summaryrefslogtreecommitdiffstats
path: root/system/earlyoom/rc.earlyoom
diff options
context:
space:
mode:
Diffstat (limited to 'system/earlyoom/rc.earlyoom')
-rw-r--r--system/earlyoom/rc.earlyoom69
1 files changed, 48 insertions, 21 deletions
diff --git a/system/earlyoom/rc.earlyoom b/system/earlyoom/rc.earlyoom
index 277050fefd..0e1cbb303d 100644
--- a/system/earlyoom/rc.earlyoom
+++ b/system/earlyoom/rc.earlyoom
@@ -4,34 +4,48 @@ set -eu
. /etc/default/earlyoom
do_start() {
- if ps -p "$(cat /var/run/earlyoom.pid)" > /dev/null
+ if [ -f /var/run/earlyoom.pid ];
then
- echo "earlyoom is already running."
- else
- echo "Starting earlyoom..."
- nohup /usr/bin/earlyoom $EARLYOOM_ARGS > /var/log/earlyoom.log 2>&1 &
- echo "$!" > /var/run/earlyoom.pid
+ 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 ps -p "$(cat /var/run/earlyoom.pid)" > /dev/null
+ if [ -f /var/run/earlyoom.pid ];
then
- echo "Stopping earlyoom..."
- kill -15 "$(cat /var/run/earlyoom.pid)"
- else
- echo "earlyoom is not running."
+ 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 ps -p "$(cat /var/run/earlyoom.pid)" > /dev/null
+ if [ -f /var/run/earlyoom.pid ];
then
- echo "Killing earlyoom..."
- kill -9 "$(cat /var/run/earlyoom.pid)"
- else
- echo "earlyoom appears to not be running."
+ 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() {
@@ -40,14 +54,27 @@ do_restart() {
}
do_status() {
- if ps -p "$(cat /var/run/earlyoom.pid)" > /dev/null
+ if [ -f /var/run/earlyoom.pid ];
then
- echo "earlyoom is running with pid $(cat /var/run/earlyoom.pid)."
- else
- echo "earlyoom is not running."
+ 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
@@ -65,6 +92,6 @@ case $1 in
do_status
;;
*)
- echo "USAGE: rc.earlyoom (start|stop|force-stop|restart|status)"
+ do_help
;;
esac