-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathpostremove.sh
executable file
·83 lines (71 loc) · 1.81 KB
/
postremove.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
set -e
# Note: >/dev/null 2>&1 is used in multiple if statements in this file.
# This is to hide expected error messages from being outputted.
# Determine OS platform
. /etc/os-release
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
}
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
}
cleanup() {
echo "Removing nginx-agent group"
if command -V groupdel >/dev/null 2>&1; then
if [ "$(getent group nginx-agent)" ]; then
groupdel nginx-agent
fi
fi
if [ "$ID" = "freebsd" ]; then
pw groupdel nginx-agent
fi
echo "Removing /var/run/nginx-agent directory"
rm -rf "/var/run/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