diff options
Diffstat (limited to 'system/earlyoom/rc.earlyoom')
-rw-r--r-- | system/earlyoom/rc.earlyoom | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/system/earlyoom/rc.earlyoom b/system/earlyoom/rc.earlyoom new file mode 100644 index 0000000000..0e1cbb303d --- /dev/null +++ b/system/earlyoom/rc.earlyoom @@ -0,0 +1,97 @@ +#!/bin/sh +set -eu + +. /etc/default/earlyoom + +do_start() { + if [ -f /var/run/earlyoom.pid ]; + then + if ps -p "$(cat /var/run/earlyoom.pid)" > /dev/null 2>&1 + then + echo "earlyoom is already running." + exit 0 + fi + fi + echo "Starting earlyoom..." + # shellcheck disable=2086 + nohup /usr/sbin/earlyoom $EARLYOOM_ARGS > /var/log/earlyoom.log 2>&1 & + echo "$!" > /var/run/earlyoom.pid + exit 0 +} + +do_stop() { + if [ -f /var/run/earlyoom.pid ]; + then + if ps -p "$(cat /var/run/earlyoom.pid)" > /dev/null 2>&1 + then + echo "Stopping earlyoom..." + kill -15 "$(cat /var/run/earlyoom.pid)" > /dev/null 2>&1 + rm -f /var/run/earlyoom.pid + exit 0 + fi + fi + echo "earlyoom is not running..." +} + +do_force_stop() { + if [ -f /var/run/earlyoom.pid ]; + then + if ps -p "$(cat /var/run/earlyoom.pid)" > /dev/null 2>&1 + then + echo "Killing earlyoom..." + kill -9 "$(cat /var/run/earlyoom.pid)" > /dev/null 2>&1 + rm -f /var/run/earlyoom.pid + exit 0 + fi + fi + echo "earlyoom appears to not be running." + exit 0 +} + +do_restart() { + do_stop + do_start +} + +do_status() { + if [ -f /var/run/earlyoom.pid ]; + then + if ps -p "$(cat /var/run/earlyoom.pid)" > /dev/null 2>&1 + then + echo "earlyoom is running with pid $(cat /var/run/earlyoom.pid)." + exit 0 + fi + fi + echo "earlyoom is not running." +} + +do_help() { + echo "USAGE: rc.earlyoom (start|stop|force-stop|restart|status)" + exit 0 +} + +if [ -z "${1-}" ]; +then + do_help +fi + +case $1 in + start) + do_start + ;; + stop) + do_stop + ;; + restart) + do_restart + ;; + force-stop) + do_force_stop + ;; + status) + do_status + ;; + *) + do_help + ;; +esac |