mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Packaging: Stop and disable service on DEB package removal (#59580)
* Stop and disable service on DEB package removal The condition for this code to run applies on package removal only, not on upgrade or reinstall which generally invoke the prerm script as well. Currently the service keeps running after package removal, failing at some point due to missing files. And if enabled, the attempted service start on every boot is doomed to fail. If the invoke-rc.d command exists, it can be assumed that update-rc.d exists as well, as both are part of the same init-system-helpers package in dpkg distro repositories. If neither systemd, nor the init system helper package is installed, the service is not tried to be disabled, since we cannot know a safe method to do so. Compared to the postinst script, "set -e" is skipped here, since we do not run any command which is allowed to fail the whole package removal. Signed-off-by: MichaIng <micha@dietpi.com> * Add postrm script to package build Signed-off-by: MichaIng <micha@dietpi.com> * Remove redundant check Co-authored-by: Dan Cech <dan@aussiedan.com> --------- Signed-off-by: MichaIng <micha@dietpi.com> Co-authored-by: Dan Cech <dan@aussiedan.com>
This commit is contained in:
parent
ff78103a24
commit
71e5024d7a
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -e
|
||||
|
||||
|
17
packaging/deb/control/prerm
Normal file
17
packaging/deb/control/prerm
Normal file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
if [ "$1" = 'remove' ]
|
||||
then
|
||||
echo 'Stopping and disabling grafana-server service...'
|
||||
if command -v systemctl >/dev/null; then
|
||||
systemctl stop grafana-server || true
|
||||
systemctl disable grafana-server || true
|
||||
elif [ -x '/etc/init.d/grafana-server' ]; then
|
||||
if command -v invoke-rc.d >/dev/null; then
|
||||
invoke-rc.d grafana-server stop || true
|
||||
update-rc.d -f grafana-server remove || true
|
||||
else
|
||||
/etc/init.d/grafana-server stop || true
|
||||
fi
|
||||
fi
|
||||
fi
|
@ -379,6 +379,9 @@ func executeFPM(options linuxPackageOptions, packageRoot, srcDir string) error {
|
||||
"--vendor", vendor,
|
||||
"-a", string(options.packageArch),
|
||||
}
|
||||
if options.prermSrc != "" {
|
||||
args = append(args, "--before-remove", options.prermSrc)
|
||||
}
|
||||
if options.edition == config.EditionEnterprise || options.edition == config.EditionEnterprise2 || options.goArch == config.ArchARMv6 {
|
||||
args = append(args, "--conflicts", "grafana")
|
||||
}
|
||||
@ -727,6 +730,7 @@ func realPackageVariant(ctx context.Context, v config.Variant, edition config.Ed
|
||||
initdScriptFilePath: "/etc/init.d/grafana-server",
|
||||
systemdServiceFilePath: "/usr/lib/systemd/system/grafana-server.service",
|
||||
postinstSrc: filepath.Join(grafanaDir, "packaging", "deb", "control", "postinst"),
|
||||
prermSrc: filepath.Join(grafanaDir, "packaging", "deb", "control", "prerm"),
|
||||
initdScriptSrc: filepath.Join(grafanaDir, "packaging", "deb", "init.d", "grafana-server"),
|
||||
defaultFileSrc: filepath.Join(grafanaDir, "packaging", "deb", "default", "grafana-server"),
|
||||
systemdFileSrc: filepath.Join(grafanaDir, "packaging", "deb", "systemd", "grafana-server.service"),
|
||||
@ -843,6 +847,7 @@ type linuxPackageOptions struct {
|
||||
initdScriptFilePath string
|
||||
systemdServiceFilePath string
|
||||
postinstSrc string
|
||||
prermSrc string
|
||||
initdScriptSrc string
|
||||
defaultFileSrc string
|
||||
systemdFileSrc string
|
||||
|
Loading…
Reference in New Issue
Block a user