Browse Source

Add service monitor (#961)

catch-docker-failure
Luke Childs 4 years ago
committed by GitHub
parent
commit
cda4ecd766
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      scripts/umbrel-os/external-storage/mount
  2. 62
      scripts/umbrel-os/service-monitor
  3. 21
      scripts/umbrel-os/services/umbrel-service-monitor.service
  4. 6
      scripts/umbrel-os/status-server/static/index.html
  5. 2
      scripts/umbrel-os/status-server/static/styles.css

1
scripts/umbrel-os/external-storage/mount

@ -146,7 +146,6 @@ copy_docker_to_external_storage () {
main () {
$set_status mount started
trap '[[ "$?" != "0" ]] && $set_status mount errored mount-script-exit' EXIT
echo "Running external storage mount script..."
check_root
check_dependencies sed wipefs parted mount sync umount

62
scripts/umbrel-os/service-monitor

@ -0,0 +1,62 @@
#!/usr/bin/env bash
UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)"
STATUS_FILE_PATH="/umbrel-status"
set_status="/status-server/set-status"
check_root () {
if [[ $UID != 0 ]]; then
echo "This script must be run as root"
exit 1
fi
}
check_umbrel_os () {
[[ -f "/etc/default/umbrel" ]] && source "/etc/default/umbrel"
if [[ -z "${UMBREL_OS:-}" ]]; then
echo "This script must only be run on Umbrel OS"
exit 1
fi
}
has_service_failed () {
systemctl is-failed --quiet '*'
}
has_umbrel_started () {
cat "${STATUS_FILE_PATH}" | grep --silent '^umbrel:completed$'
}
has_error_been_caught () {
cat "${STATUS_FILE_PATH}" | grep --silent ':errored:'
}
check_root
check_umbrel_os
$set_status service-monitor started
echo "Starting service monitor..."
while true
do
if has_umbrel_started
then
echo "Umbrel successfully started, exiting service monitor!"
exit 0
fi
if has_service_failed
then
echo "Service failed!"
if has_error_been_caught
then
echo "Error already caught, doing nothing."
else
echo "Error not caught, writing an error."
$set_status service-monitor errored service-failed
fi
echo "Exiting service monitor"
exit 0
fi
sleep 1
done

21
scripts/umbrel-os/services/umbrel-service-monitor.service

@ -0,0 +1,21 @@
# Umbrel Service Monitor
# Installed at /etc/systemd/system/umbrel-service-monitor.service
[Unit]
Description=Service Monitor
After=umbrel-status-server.service
[Service]
Type=oneshot
Restart=no
ExecStart=/home/umbrel/umbrel/scripts/umbrel-os/service-monitor
TimeoutStartSec=45min
User=root
Group=root
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=service monitor
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

6
scripts/umbrel-os/status-server/static/index.html

@ -76,9 +76,9 @@
<p>The version of UmbrelOS on your microSD card is not compatible with the version of Umbrel on your external drive.</p>
</div>
<div class="error-text mount-script-exit">
<p><b class="text-dark">Error: Mounting external drive failed</b></p>
<p>Something went wrong when trying to connect to the external drive.</p>
<div class="error-text service-failed">
<p><b class="text-dark">Error: System service failed</b></p>
<p>Something went wrong when starting Umbrel. Need help? Feel free to jump on our <a href="https://community.getumbrel.comhttps://t.me/getumbrel" target="_blank">community forum</a> or <a href="https://t.me/getumbrel" target="_blank">Telegram chat</a>.</p>
</div>
<div class="error-text no-block-device">

2
scripts/umbrel-os/status-server/static/styles.css

@ -49,7 +49,7 @@ p {
}
[data-error="monitor-check"] .error-text.monitor-check,
[data-error="semver-mismatch"] .error-text.semver-mismatch,
[data-error="mount-script-exit"] .error-text.mount-script-exit,
[data-error="service-failed"] .error-text.service-failed,
[data-error="no-block-device"] .error-text.no-block-device,
[data-error="multiple-block-devices"] .error-text.multiple-block-devices,
[data-error="rebinding-failed"] .error-text.rebinding-failed {

Loading…
Cancel
Save