2022-09-14 08:21:28 +02:00
|
|
|
#!/bin/sh
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
. /etc/default/earlyoom
|
|
|
|
|
|
|
|
do_start() {
|
2022-10-20 21:02:45 +02:00
|
|
|
if [ -f /var/run/earlyoom.pid ];
|
2022-09-14 08:21:28 +02:00
|
|
|
then
|
2022-10-20 21:02:45 +02:00
|
|
|
if ps -p "$(cat /var/run/earlyoom.pid)" > /dev/null 2>&1
|
|
|
|
then
|
|
|
|
echo "earlyoom is already running."
|
|
|
|
exit 0
|
|
|
|
fi
|
2022-09-14 08:21:28 +02:00
|
|
|
fi
|
2022-10-20 21:02:45 +02:00
|
|
|
echo "Starting earlyoom..."
|
|
|
|
# shellcheck disable=2086
|
|
|
|
nohup /usr/bin/earlyoom $EARLYOOM_ARGS > /var/log/earlyoom.log 2>&1 &
|
|
|
|
echo "$!" > /var/run/earlyoom.pid
|
|
|
|
exit 0
|
2022-09-14 08:21:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
do_stop() {
|
2022-10-20 21:02:45 +02:00
|
|
|
if [ -f /var/run/earlyoom.pid ];
|
2022-09-14 08:21:28 +02:00
|
|
|
then
|
2022-10-20 21:02:45 +02:00
|
|
|
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
|
|
|
|
exit 0
|
|
|
|
fi
|
2022-09-14 08:21:28 +02:00
|
|
|
fi
|
2022-10-20 21:02:45 +02:00
|
|
|
echo "earlyoom is not running..."
|
2022-09-14 08:21:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
do_force_stop() {
|
2022-10-20 21:02:45 +02:00
|
|
|
if [ -f /var/run/earlyoom.pid ];
|
2022-09-14 08:21:28 +02:00
|
|
|
then
|
2022-10-20 21:02:45 +02:00
|
|
|
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
|
|
|
|
exit 0
|
|
|
|
fi
|
2022-09-14 08:21:28 +02:00
|
|
|
fi
|
2022-10-20 21:02:45 +02:00
|
|
|
echo "earlyoom appears to not be running."
|
|
|
|
exit 0
|
2022-09-14 08:21:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
do_restart() {
|
|
|
|
do_stop
|
|
|
|
do_start
|
|
|
|
}
|
|
|
|
|
|
|
|
do_status() {
|
2022-10-20 21:02:45 +02:00
|
|
|
if [ -f /var/run/earlyoom.pid ];
|
2022-09-14 08:21:28 +02:00
|
|
|
then
|
2022-10-20 21:02:45 +02:00
|
|
|
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
|
2022-09-14 08:21:28 +02:00
|
|
|
fi
|
2022-10-20 21:02:45 +02:00
|
|
|
echo "earlyoom is not running."
|
2022-09-14 08:21:28 +02:00
|
|
|
}
|
|
|
|
|
2022-10-20 21:02:45 +02:00
|
|
|
do_help() {
|
|
|
|
echo "USAGE: rc.earlyoom (start|stop|force-stop|restart|status)"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z "${1-}" ];
|
|
|
|
then
|
|
|
|
do_help
|
|
|
|
fi
|
|
|
|
|
2022-09-14 08:21:28 +02:00
|
|
|
case $1 in
|
|
|
|
start)
|
|
|
|
do_start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
do_stop
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
do_restart
|
|
|
|
;;
|
|
|
|
force-stop)
|
|
|
|
do_force_stop
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
do_status
|
|
|
|
;;
|
|
|
|
*)
|
2022-10-20 21:02:45 +02:00
|
|
|
do_help
|
2022-09-14 08:21:28 +02:00
|
|
|
;;
|
|
|
|
esac
|