Skip to content

Commit 8187564

Browse files
committed
Adjusted packaging scripts to check systemctl is-system-running
In the case of containers running debian 11 and such, systemctl command is available but the system may not be running. systemctl is-system-running is a better check as to whether we should execute systemd related commands. Ticket: CFE-4544 Changelog: title
1 parent 1cbd3df commit 8187564

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ rc_d_path()
1919

2020
platform_service()
2121
{
22-
if [ -x /bin/systemctl ]; then
23-
/bin/systemctl "$2" "$1".service
22+
if command -v systemctl 2>/dev/null && systemctl is-system-running; then
23+
systemctl "$2" "$1".service
2424
else
2525
/etc/init.d/"$1" "$2"
2626
fi

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ rc_d_path()
2727

2828
platform_service()
2929
{
30-
if [ -x /bin/systemctl ]; then
31-
/bin/systemctl "$2" "$1".service
30+
if command -v systemctl 2>/dev/null && systemctl is-system-running; then
31+
systemctl "$2" "$1".service
3232
else
3333
`rc_d_path`/init.d/"$1" "$2"
3434
fi

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 command -v systemctl 2>/dev/null && systemctl is-system-running; 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 command -v systemctl 2>/dev/null && systemctl is-system-running; 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

0 commit comments

Comments
 (0)