This commit is contained in:
Geoffrey Frogeye 2017-09-17 14:34:37 +00:00
parent 96751acaab
commit eeb061a032
4 changed files with 167 additions and 1 deletions

39
termux/scripts/autosvc Executable file
View file

@ -0,0 +1,39 @@
#!/data/data/com.termux/files/usr/bin/bash
#
# Start services based on phone state
#
function act() {
# Services that should be always on
service sshd start
service autosvc start
# Services that should be on depending on battery
bat="$(termux-battery-status | jq -r '.status')"
if [[ "$bat" == "FULL" || "$bat" == "CHARGING" ]]
then
service syncthing start
else
service syncthing stop
fi
}
if [ "$1" == "-d" ]
then
# Daemon mode
while true
do
echo 29
act &>> $HOME/.local/log/autosvc.log
echo 31
sleep 60
done
else
# One shot mode
# TODO Soft-code the log destination & the program arguments
act
fi

View file

@ -3,4 +3,9 @@
# Substitution for sudo
#
echo "$@" | tsu
if [ "$(whoami)" != 'root' ]
then
echo "$@" | tsu
else
"$@"
fi

61
termux/services/autosvc Executable file
View file

@ -0,0 +1,61 @@
#!/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"
termux-toast "Started autosvc"
echo "OK"
}
stop() {
printf "Stopping autosvc: "
start-stop-daemon -p "$PIDFILE" -x /data/data/com.termux/files/usr/bin/bash -K
termux-toast "Stopped autosvc"
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 $?

61
termux/services/crond Executable file
View file

@ -0,0 +1,61 @@
#!/data/data/com.termux/files/usr/bin/bash
#
# Start crond
#
PIDFILE="$HOME/.local/run/crond.pid"
LOGFILE="$HOME/.local/log/crond.log"
start() {
printf "Starting crond: "
start-stop-daemon -p "$PIDFILE" -x crond -S -b -m -- -f -L "$LOGFILE"
termux-toast "Started crond"
echo "OK"
}
stop() {
printf "Stopping crond: "
start-stop-daemon -p "$PIDFILE" -x crond -K
termux-toast "Stopped crond"
echo "OK"
}
status() {
printf "crond: "
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 $?