-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid stopping nginx-agent service on package upgrade (#352)
* fix: restart service on package upgrade on Debian/Ubuntu Previously it was stopped during the executing of package scripts due to incorrect behavior in prerm: https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html#summary-of-ways-maintainer-scripts-are-called * fix: do not stop service on upgrade (RHEL-based distros) * Avoid restarting nginx-agent service from pkg on FreeBSD during upgrades This will end up with a new process being killed immediately by pkg: https://github.com/freebsd/pkg/blob/1.19.1/libpkg/scripts.c#L100-L103 https://github.com/freebsd/pkg/blob/1.19.1/libpkg/scripts.c#L244-L261 See also: freebsd/pkg#2128 * feat: OpenRC package scripts for Alpine Linux * chore: add Alpine Linux instructions to README While here, removed extra trailing spaces across the doc. * chore: adjust service description, remove modelines * chore: remove leading underscore from shell func names
- Loading branch information
Showing
8 changed files
with
160 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/sbin/openrc-run | ||
|
||
description="NGINX Agent" | ||
command_background=true | ||
|
||
cfgfile=${cfgfile:-/etc/nginx-agent/nginx-agent.conf} | ||
pidfile=/var/run/nginx-agent.pid | ||
command=/usr/bin/nginx-agent | ||
command_args="" | ||
required_files="$cfgfile" | ||
|
||
depend() { | ||
need net | ||
use dns logger netmount | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,68 @@ | ||
#!/bin/sh | ||
|
||
# Determine OS platform | ||
# shellcheck source=/dev/null | ||
. /etc/os-release | ||
|
||
if [ "$ID" = "freebsd" ]; then | ||
echo "Stop and remove nginx-agent service" | ||
stop_agent_freebsd() { | ||
echo "Stopping nginx-agent service" | ||
service nginx-agent onestop >/dev/null 2>&1 || true | ||
} | ||
|
||
disable_agent_freebsd() { | ||
echo "Disabling nginx-agent service" | ||
sysrc -x nginx_agent_enable >/dev/null 2>&1 || true | ||
elif command -V systemctl >/dev/null 2>&1; then | ||
echo "Stop and disable nginx-agent service" | ||
} | ||
|
||
stop_agent_systemd() { | ||
echo "Stopping nginx-agent service" | ||
systemctl stop nginx-agent >/dev/null 2>&1 || true | ||
} | ||
|
||
disable_agent_systemd() { | ||
echo "Disabling nginx-agent service" | ||
systemctl disable nginx-agent >/dev/null 2>&1 || true | ||
} | ||
|
||
systemd_daemon_reload() { | ||
echo "Running daemon-reload" | ||
systemctl daemon-reload || true | ||
fi | ||
} | ||
|
||
cleanup() { | ||
echo "Removing /var/run/nginx-agent directory" | ||
rm -rf "/var/run/nginx-agent" | ||
} | ||
|
||
echo "Removing /var/run/nginx-agent directory" | ||
rm -rf "/var/run/nginx-agent" | ||
echo "Removing /var/log/nginx-agent directory" | ||
rm -rf "/var/log/nginx-agent" | ||
case "$ID" in | ||
freebsd) | ||
stop_agent_freebsd | ||
disable_agent_freebsd | ||
cleanup | ||
;; | ||
debian|ubuntu) | ||
if [ "$1" = "remove" ]; then | ||
stop_agent_systemd | ||
disable_agent_systemd | ||
systemd_daemon_reload | ||
cleanup | ||
fi | ||
;; | ||
rhel|fedora|centos|amzn|almalinux|rocky) | ||
if [ "$1" = "0" ]; then | ||
stop_agent_systemd | ||
disable_agent_systemd | ||
systemd_daemon_reload | ||
cleanup | ||
fi | ||
;; | ||
alpine) | ||
cleanup | ||
;; | ||
*) | ||
stop_agent_systemd | ||
disable_agent_systemd | ||
systemd_daemon_reload | ||
cleanup | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
|
||
NEWVER="$1" | ||
OLDVER="$2" | ||
|
||
restart_agent_if_required() { | ||
if service nginx-agent status >/dev/null 2>&1; then | ||
printf "PostUpgrade: Restarting nginx agent (upgraded to %s from %s)\n" "$NEWVER" "$OLDVER" | ||
service nginx-agent restart || true | ||
fi | ||
} | ||
|
||
# Determine OS platform | ||
# shellcheck source=/dev/null | ||
. /etc/os-release | ||
|
||
case "$ID" in | ||
alpine) | ||
restart_agent_if_required | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,4 +164,4 @@ update_config_file() { | |
ensure_sudo | ||
load_config_values | ||
update_config_file | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,17 @@ | ||
#!/bin/sh | ||
# Pre Remove Steps | ||
|
||
# Determine OS platform | ||
# shellcheck source=/dev/null | ||
. /etc/os-release | ||
|
||
stop_agent_openrc() { | ||
echo "Stopping nginx-agent service" | ||
service nginx-agent stop 2>&1 || true | ||
} | ||
|
||
case "$ID" in | ||
alpine) | ||
stop_agent_openrc | ||
;; | ||
esac |