dotfiles/termux/services/autosvc

60 lines
989 B
Plaintext
Raw Permalink Normal View History

2017-09-17 16:34:37 +02:00
#!/data/data/com.termux/files/usr/bin/bash
#
# Charge services based on phone state
#
PIDFILE="$HOME/.local/run/autosvc.pid"
LOGFILE="$HOME/.local/log/autosvc.log"
start() {
printf "Starting autosvc: "
start-stop-daemon -p "$PIDFILE" -x /data/data/com.termux/files/usr/bin/bash -S -b -m -- "$HOME/.termux/scripts/autosvc" -d -l "$LOGFILE"
echo "OK"
}
stop() {
printf "Stopping autosvc: "
start-stop-daemon -p "$PIDFILE" -x /data/data/com.termux/files/usr/bin/bash -K
echo "OK"
}
status() {
printf "autosvc: "
PID="$(cat "$PIDFILE" 2> /dev/null)"
if [[ -n "$PID" && -d "/proc/$PID" ]]
then
echo "running"
else
echo "stopped"
fi
}
log() {
tail "$@" "$LOGFILE"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
status)
status
;;
log)
shift
log "$@"
;;
*)
echo "Usage: $0 {start|stop|restart|status|log}"
exit 1
esac
exit $?