1
0
Эх сурвалжийг харах

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

Simon Frei 4 жил өмнө
parent
commit
c2bb11a794

+ 34 - 14
build.go

@@ -30,6 +30,7 @@ import (
 	"runtime"
 	"runtime"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
+	"text/template"
 	"time"
 	"time"
 )
 )
 
 
@@ -59,12 +60,11 @@ type target struct {
 	debname           string
 	debname           string
 	debdeps           []string
 	debdeps           []string
 	debpre            string
 	debpre            string
-	debpost           string
 	description       string
 	description       string
 	buildPkgs         []string
 	buildPkgs         []string
 	binaryName        string
 	binaryName        string
 	archiveFiles      []archiveFile
 	archiveFiles      []archiveFile
-	systemdServices   []string
+	systemdService    string
 	installationFiles []archiveFile
 	installationFiles []archiveFile
 	tags              []string
 	tags              []string
 }
 }
@@ -86,7 +86,6 @@ var targets = map[string]target{
 		name:        "syncthing",
 		name:        "syncthing",
 		debname:     "syncthing",
 		debname:     "syncthing",
 		debdeps:     []string{"libc6", "procps"},
 		debdeps:     []string{"libc6", "procps"},
-		debpost:     "script/post-upgrade",
 		description: "Open Source Continuous File Synchronization",
 		description: "Open Source Continuous File Synchronization",
 		buildPkgs:   []string{"github.com/syncthing/syncthing/cmd/syncthing"},
 		buildPkgs:   []string{"github.com/syncthing/syncthing/cmd/syncthing"},
 		binaryName:  "syncthing", // .exe will be added automatically for Windows builds
 		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},
 			{src: "AUTHORS", dst: "AUTHORS.txt", perm: 0644},
 			// All files from etc/ and extra/ added automatically in init().
 			// All files from etc/ and extra/ added automatically in init().
 		},
 		},
+		systemdService: "syncthing@*.service",
 		installationFiles: []archiveFile{
 		installationFiles: []archiveFile{
 			{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
 			{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
 			{src: "README.md", dst: "deb/usr/share/doc/syncthing/README.txt", perm: 0644},
 			{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: "LICENSE", dst: "LICENSE.txt", perm: 0644},
 			{src: "AUTHORS", dst: "AUTHORS.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{
 		installationFiles: []archiveFile{
 			{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
 			{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},
 			{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: "LICENSE", dst: "LICENSE.txt", perm: 0644},
 			{src: "AUTHORS", dst: "AUTHORS.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{
 		installationFiles: []archiveFile{
 			{src: "{{binary}}", dst: "deb/usr/bin/{{binary}}", perm: 0755},
 			{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},
 			{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 {
 	for _, dep := range target.debdeps {
 		args = append(args, "-d", dep)
 		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 != "" {
 	if target.debpre != "" {
 		args = append(args, "--before-install", target.debpre)
 		args = append(args, "--before-install", target.debpre)
@@ -666,6 +664,28 @@ func buildDeb(target target) {
 	runPrint("fpm", args...)
 	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) {
 func shouldBuildSyso(dir string) (string, error) {
 	type M map[string]interface{}
 	type M map[string]interface{}
 	version := getVersion()
 	version := getVersion()

+ 14 - 0
script/deb-post-inst.template

@@ -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

+ 0 - 8
script/post-upgrade

@@ -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