Skip to content

Commit 799d9e6

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 799d9e6

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

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 [ -x /bin/systemctl ] && systemctl is-system-running; 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 [ -x /bin/systemctl ] && systemctl is-system-running; 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 [ -x /bin/systemctl ] && 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 [ -x /bin/systemctl ] && 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)