Cleaner way to get systemd unit state

See : https://unix.stackexchange.com/a/396633
This commit is contained in:
Jeremy Gardais 2023-01-25 10:35:07 +01:00
parent 48aeef052c
commit 34e47ee0e0
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 2 additions and 2 deletions

View File

@ -213,7 +213,7 @@ main() { # {{{
if [ "${request_status}" = "start" ]; then
debug_message "-- Connect VPN BEGIN"
### If forticlient.service unit is not started {{{
systemd_forticlient_status=$(systemctl show forticlient.service | grep "^ActiveStat" | sed 's/.*=\(.*\)/\1/' || error_message "Error while requesting forticlient.service unit status." 21)
systemd_forticlient_status=$(systemctl show --property ActiveState --value forticlient.service || error_message "Error while requesting forticlient.service unit status." 21)
if [ "${systemd_forticlient_status}" = "failed" ]; then
debug_message "| Try to start forticlient.service unit."
sudo systemctl restart forticlient.service \
@ -221,7 +221,7 @@ main() { # {{{
fi
### }}}
### If forticlient.service unit is started {{{
systemd_forticlient_status=$(systemctl show forticlient.service | grep "^ActiveStat" | sed 's/.*=\(.*\)/\1/' || error_message "Error while requesting forticlient.service unit status." 21)
systemd_forticlient_status=$(systemctl show --property ActiveState --value forticlient.service || error_message "Error while requesting forticlient.service unit status." 21)
if [ "${systemd_forticlient_status}" = "active" ]; then
debug_message "| forticlient.service unit is ${RED}started${COLOR_DEBUG}."
fi