-
Notifications
You must be signed in to change notification settings - Fork 684
Keeping Linuxdeploy responsive by constant pings from the inside
I wanted to keep my Linuxdeploy instance's wifi on all the time, so that it is responsive to network requests. Based on the discussion here, I created an init script to place in my Linux installation that will ping the local gateway every half a second.
Thank you Gazihan Alankus for the initial write up. On my HTC One Mini 2 the whole system froze after a while. I figured out it's the deep-sleep engergy save mode of Android. It can be disabled by doing unchroot echo "Debian" > /sys/power/wake_lock . Probably a overkill to do this every 500ms, from docu I think only once would be sufficient. But hey it works... so I'll leave it here hoping it helps someone. B
Create /etc/init.d/pingwoke
and place the following in it:
#!/bin/sh
# Start/stop the cron daemon.
#
### BEGIN INIT INFO
# Provides: pingwoke
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Keeps linuxdeploy awake
# Description: Keeps linuxdeploy awake
### END INIT INFO
PIDFILE=/var/run/pingwoke.pid
test -f $DAEMON || exit 0
. /lib/lsb/init-functions
start() {
# code to start app comes here
# example: daemon program_name &
#/sbin/runuser android -s /bin/bash -c "/home/android/pinger" &
log_daemon_msg "Starting pingwoke"
#start-stop-daemon --start --chuid android --background \
# --make-pidfile --pidfile $PIDFILE --exec $DAEMON
start-stop-daemon --start --chuid android --background --make-pidfile \
--pidfile $PIDFILE --startas /bin/bash -- -c "exec ping -i 0.5 192.168.1.1 > /home/android/pinger.log 2>&1"
echo "hello"
# Prevent Android Device from going into deep sleep mode, making the whole system unresponsive. Background here https://elinux.org/Android_Power_Management
unchroot echo "Debian" > /sys/power/wake_lock
log_end_msg $?
}
stop() {
# code to stop app comes here
# example: killproc program_name
log_daemon_msg "Stopping pingwoke"
#killall pinger
#killproc -p $PIDFILE $DAEMON
start-stop-daemon --stop --pidfile $PIDFILE
RETVAL=$?
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE
log_end_msg $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
# code to check status of app comes here
# example: status program_name
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0
Replace 192.168.1.1
with your own gateway. I guess we could get it from the system as an improvement but I was too lazy to do that.
Give it execute permission:
chmod ugo+x /etc/init.d/pingwoke
Then, we need to register this service to be executed when Linux starts:
sudo update-rc.d pingwoke defaults
Now check whether /etc/rc2.d/
has a S01pingwoke
kind of entry. If so, reboot and see if ping is running with:
root@localhost:/etc/init.d# ps -aux | grep ping
android 2687 0.0 0.1 4152 628 ? S 15:07 0:03 ping -i 0.5 192.168.1.1
root 3345 0.0 0.1 2108 620 pts/0 S+ 16:28 0:00 grep ping
root@localhost:/etc/init.d#
Together with Using ext4 in sd and unmounting it from Android at boot, I'm making an old Android phone be the center of my home automation system.