-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add greenboot-service-monitor.service for service health checking
This change adds a service to monitor whether or not specified services have started correctly. If enabled, the service runs after `multi-user.target` is reached, and is required to reach `boot-complete.target`. The monitored services can be configured in `greenboot.conf`. By default `sshd` and `NetworkManager` are monitored.
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# SPDX-License-Identifier: LGPL-2.1+ | ||
# | ||
# This file is part of greenboot. | ||
# | ||
# greenboot is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Lesser General Public License as published by | ||
# the Free Software Foundation; either version 2.1 of the License, or | ||
# (at your option) any later version. | ||
|
||
[Unit] | ||
Description=Monitor user services | ||
Before=boot-complete.target | ||
OnFailure=redboot.target | ||
After=default.target graphical.target multi-user.target | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/libexec/greenboot/greenboot-service-monitor | ||
|
||
[Install] | ||
RequiredBy=boot-complete.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
GREENBOOT_CONFIGURATION_FILE=/etc/greenboot/greenboot.conf | ||
service_started=true | ||
if test -f "$GREENBOOT_CONFIGURATION_FILE"; then | ||
source $GREENBOOT_CONFIGURATION_FILE | ||
fi | ||
|
||
if [ -n "$GREENBOOT_MONITOR_SERVICES" ]; then | ||
services=($GREENBOOT_MONITOR_SERVICES) | ||
else | ||
echo "GREENBOOT_MONITOR_SERVICE not found, using default value" | ||
services=( sshd NetworkManager ) | ||
fi | ||
|
||
# check all the services listed | ||
for service in "${services[@]}"; do | ||
rc="$(systemctl show -p ActiveState --value $service)" | ||
if [[ $rc != "active" ]]; then | ||
echo "<0>${service} is ${rc}" | ||
service_started=false | ||
fi | ||
done | ||
|
||
# fail if any of the monitored services failed. This will make boot-complete.target fail. | ||
if ! $service_started ; then | ||
exit 1 | ||
fi |