build: Do not use --deb-systemd with fpm (fixes #7548) (#7564)

This commit is contained in:
Simon Frei 2021-04-11 20:04:15 +02:00 committed by GitHub
parent 1a00ea7c6e
commit c2bb11a794
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 22 deletions

View File

@ -30,6 +30,7 @@ import (
"runtime"
"strconv"
"strings"
"text/template"
"time"
)
@ -59,12 +60,11 @@ type target struct {
debname string
debdeps []string
debpre string
debpost string
description string
buildPkgs []string
binaryName string
archiveFiles []archiveFile
systemdServices []string
systemdService string
installationFiles []archiveFile
tags []string
}
@ -86,7 +86,6 @@ var targets = map[string]target{
name: "syncthing",
debname: "syncthing",
debdeps: []string{"libc6", "procps"},
debpost: "script/post-upgrade",
description: "Open Source Continuous File Synchronization",
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/syncthing"},
binaryName: "syncthing", // .exe will be added automatically for Windows builds
@ -97,6 +96,7 @@ var targets = map[string]target{
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
// All files from etc/ and extra/ added automatically in init().
},
systemdService: "syncthing@*.service",
installationFiles: []archiveFile{
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
{src: "README.md", dst: "deb/usr/share/doc/syncthing/README.txt", perm: 0644},
@ -141,9 +141,7 @@ var targets = map[string]target{
{src: "LICENSE", dst: "LICENSE.txt", perm: 0644},
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
},
systemdServices: []string{
"cmd/stdiscosrv/etc/linux-systemd/stdiscosrv.service",
},
systemdService: "cmd/stdiscosrv/etc/linux-systemd/stdiscosrv.service",
installationFiles: []archiveFile{
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
{src: "cmd/stdiscosrv/README.md", dst: "deb/usr/share/doc/syncthing-discosrv/README.txt", perm: 0644},
@ -170,9 +168,7 @@ var targets = map[string]target{
{src: "LICENSE", dst: "LICENSE.txt", perm: 0644},
{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
},
systemdServices: []string{
"cmd/strelaysrv/etc/linux-systemd/strelaysrv.service",
},
systemdService: "cmd/strelaysrv/etc/linux-systemd/strelaysrv.service",
installationFiles: []archiveFile{
{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
{src: "cmd/strelaysrv/README.md", dst: "deb/usr/share/doc/syncthing-relaysrv/README.txt", perm: 0644},
@ -654,11 +650,13 @@ func buildDeb(target target) {
for _, dep := range target.debdeps {
args = append(args, "-d", dep)
}
for _, service := range target.systemdServices {
args = append(args, "--deb-systemd", service)
}
if target.debpost != "" {
args = append(args, "--after-upgrade", target.debpost)
if target.systemdService != "" {
debpost, err := createPostInstScript(target)
defer os.Remove(debpost)
if err != nil {
log.Fatal(err)
}
args = append(args, "--after-upgrade", debpost)
}
if target.debpre != "" {
args = append(args, "--before-install", target.debpre)
@ -666,6 +664,28 @@ func buildDeb(target target) {
runPrint("fpm", args...)
}
func createPostInstScript(target target) (string, error) {
scriptname := filepath.Join("script", "deb-post-inst.template")
t, err := template.ParseFiles(scriptname)
if err != nil {
return "", err
}
scriptname = strings.TrimSuffix(scriptname, ".template")
w, err := os.Create(scriptname)
if err != nil {
return "", err
}
defer w.Close()
if err = t.Execute(w, struct {
Service, Command string
}{
target.systemdService, target.binaryName,
}); err != nil {
return "", err
}
return scriptname, nil
}
func shouldBuildSyso(dir string) (string, error) {
type M map[string]interface{}
version := getVersion()

View File

@ -0,0 +1,14 @@
#!/bin/sh
command -v deb-systemd-invoke > /dev/null
has_systemd=$?
if [ $has_systemd -eq 0 ]; then
systemctl daemon-reload
fi
if [ $has_systemd -eq 0 ] && [ -n "$(systemctl list-units --plain --no-legend {{.Service}})" ]; then
deb-systemd-invoke try-restart "{{.Service}}"
else
pkill -HUP -x {{.Command}}
fi

View File

@ -1,8 +0,0 @@
#!/bin/sh
if command -v deb-systemd-invoke > /dev/null; then
deb-systemd-invoke restart procps.service
else
sysctl -q --system
fi
pkill -HUP -x syncthing || true