Skip to content

Commit bf2bcd9

Browse files
Merge pull request #1989 from craigcomstock/ENT-13277/master
ENT-13277: Adjusted detection of systemd in package scriptlets to handle more valid states
2 parents 8e4fdb9 + 19ccbed commit bf2bcd9

10 files changed

Lines changed: 32 additions & 11 deletions

File tree

packaging/common/cfengine-hub/postinstall.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ systemctl restart cfengine3"
2929
fi
3030
fi
3131

32-
if command -v systemctl 2>/dev/null && systemctl is-system-running; then
32+
if use_systemd; then
3333
# This is important in case any of the units have been replaced by the package
3434
# and we call them in the postinstall script.
3535
if ! /bin/systemctl daemon-reload; then
@@ -1073,7 +1073,7 @@ chmod g+rX "$PREFIX/httpd/php"
10731073
# Register CFEngine initscript, if not yet.
10741074
#
10751075
if ! is_upgrade; then
1076-
if command -v systemctl 2>/dev/null && systemctl is-system-running; then
1076+
if use_systemd; then
10771077
# Reload systemd config to pick up newly installed units
10781078
/bin/systemctl daemon-reload > /dev/null 2>&1
10791079
# Enable cfengine3 service (starts all the other services)

packaging/common/cfengine-hub/preinstall.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fi
136136
if is_upgrade; then
137137
cf_console platform_service cfengine3 stop
138138
# CFE-2278: Migrate to split units
139-
if [ -x /bin/systemctl ] && [ -e /usr/lib/systemd/system/cfengine3-web.service ]; then
139+
if use_systemd && [ -e /usr/lib/systemd/system/cfengine3-web.service ]; then
140140
# When using systemd, the services are split in two, and although both will
141141
# stop due to the command above, the web part may only do so after some
142142
# delay, which may cause problems in an upgrade situation, since this script

packaging/common/cfengine-hub/preremove.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cf_console platform_service cfengine3 stop
2-
if [ -x /bin/systemctl ] && [ -e /usr/lib/systemd/system/cfengine3-web.service ]; then
2+
if use_systemd && [ -e /usr/lib/systemd/system/cfengine3-web.service ]; then
33
# When using systemd, the services are split in two, and although both will
44
# stop due to the command above, the web part may only do so after some
55
# delay, which may cause problems later if the binaries are gone by the time

packaging/common/cfengine-non-hub/postinstall.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if command -v systemctl 2>/dev/null && systemctl is-system-running; then
1+
if use_systemd; then
22
# This is important in case any of the units have been replaced by the package
33
# and we call them in the postinstall script.
44
if ! /bin/systemctl daemon-reload; then
@@ -69,7 +69,7 @@ case `os_type` in
6969
#
7070
# Register CFEngine initscript, if not yet.
7171
#
72-
if command -v systemctl 2>/dev/null && systemctl is-system-running; then
72+
if use_systemd; then
7373
# Reload systemd config to pick up newly installed units
7474
/bin/systemctl daemon-reload > /dev/null 2>&1
7575
# Enable cfengine3 service (starts all the other services)

packaging/common/cfengine-non-hub/preremove.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ case `os_type` in
1010
#
1111
# systemd support
1212
#
13-
test -x /bin/systemctl && systemctl disable cfengine3.service > /dev/null 2>&1
13+
use_systemd && systemctl disable cfengine3.service > /dev/null 2>&1
1414

1515
#
1616
# Clean lock files created by initscript, if any

packaging/common/produce-script

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# type = <deb|rpm|depot|bff|pkg>
77
# action = <install|remove>
88
#
9+
# script-header.sh
910
# <type>-script-common.sh
1011
# <type>-script-common-<action>.sh
1112
# script-common.sh
@@ -33,6 +34,7 @@ include_script()
3334
fi
3435
}
3536

37+
include_script "$TEMPLATEDIR/script-header.sh"
3638
include_script "$TEMPLATEDIR/$PKG_TYPE-script-common.sh"
3739

3840
case "$PKG_TYPE" in

packaging/common/script-templates/deb-script-common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rc_d_path()
1919

2020
platform_service()
2121
{
22-
if [ -x /bin/systemctl ]; then
22+
if use_systemd; then
2323
/bin/systemctl "$2" "$1".service
2424
else
2525
/etc/init.d/"$1" "$2"

packaging/common/script-templates/rpm-script-common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ rc_d_path()
2727

2828
platform_service()
2929
{
30-
if [ -x /bin/systemctl ]; then
30+
if use_systemd; then
3131
/bin/systemctl "$2" "$1".service
3232
else
3333
`rc_d_path`/init.d/"$1" "$2"

packaging/common/script-templates/script-common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ case "$PKG_TYPE" in
2929
esac
3030

3131
get_cfengine_state() {
32-
if type systemctl >/dev/null 2>&1; then
32+
if use_systemd; then
3333
systemctl list-units -l | sed -r -e '/^\s*(cf-[-a-z]+|cfengine3)\.service/!d' -e 's/\s*(cf-[-a-z]+|cfengine3)\.service.*/\1/'
3434
else
3535
platform_service cfengine3 status | awk '/is running/ { print $1 }'
@@ -39,7 +39,7 @@ get_cfengine_state() {
3939
restore_cfengine_state() {
4040
# $1 -- file where the state to restore is saved (see get_cfengine_state())
4141

42-
if type systemctl >/dev/null 2>&1; then
42+
if use_systemd; then
4343
for service in `cat "$1"`; do
4444
definition=`systemctl cat "$service"` || continue
4545
# only try to start service that are defined/exist (some may be gone
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
USE_SYSTEMD=0
2+
_use_systemd=$(command -v systemctl 2>&1 >/dev/null && systemctl is-system-running)
3+
case "$_use_systemd" in
4+
offline|unknown)
5+
USE_SYSTEMD=0
6+
;;
7+
"")
8+
USE_SYSTEMD=0
9+
;;
10+
*)
11+
USE_SYSTEMD=1
12+
;;
13+
esac
14+
15+
use_systemd()
16+
{
17+
test $USE_SYSTEMD = 1
18+
}
19+

0 commit comments

Comments
 (0)