Last active
October 30, 2019 15:33
-
-
Save b23prodtm/a0cebe97817800e10764928a93ef56ab to your computer and use it in GitHub Desktop.
Check if the system dpkg need a restart and send corresponding signal, as a service
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
#!/bin/bash | |
# auto-reboot | |
# description: Check if the system dpkg need a restart and send corresponding signal | |
start() { | |
# code to start app comes here | |
# example: bahs -c "program_name" & | |
bash -c "while [ ! -f /var/run/reboot-required ]; do sleep 30; done; cat /var/run/reboot-required.dpkgs 2> /dev/null; reboot" & | |
echo $! > /var/run/chkdpkgs.pid | |
} | |
stop() { | |
# code to stop app comes here | |
# example: kill program_name.pid | |
kill $(cat /var/run/chkdpkgs.pid) | |
rm /var/run/chkdpkgs.pid | |
} | |
status() { | |
if [ -e /var/run/chkdpkgs.pid ]; then | |
echo auto-reboot is running, pid=$(cat /var/run/chkdpkgs.pid) | |
else | |
echo auto-reboot is NOT running | |
exit 1 | |
fi | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
status) | |
# code to check status of app comes here | |
# example: status program_name | |
status | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status|restart}" | |
esac | |
exit 0 |
sudo systemctl enable auto-reboot
The system should reboot at anytime if the message **** System reboot is required **** is displayed on login shell.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/etc/systemd/system/auto-reboot.service
`[Unit]
Description=Auto-Check system reboot-required status and reboot
[Service]
Type=forking
ExecStart=/usr/local/bin/auto-reboot.sh start
ExecStop=/usr/local/bin/auto-reboot.sh stop
PIDFile=/var/run/chkdpkgs.pid
[Install]
WantedBy=multi-user.target
`