The debuggerd method worked well for my use case, which was simply to mount my home movie (samba) server at /sdcard/Movies/cifs. I am using a Nexus 4 running Faux kernel, but with stock Android 4.2.1 ROM (JOP40D). Here is my flow :
- Replace debuggerd with your own script that performs the mount then runs the renamed original debuggerd (debuggerd.bin below). Android starts the debuggerd service at boot, and at that point the mount will fail as wireless is not connected. However, Android will automatically restart debuggerd if it is killed. So we create another script that kills debuggerd and use a ScriptManager widget to call that script at the click of a button. Assuming wireless is connected, the mount will succeed when debuggerd is rerun by Android.
1. /system/bin/debuggerd
Code:
#!/system/bin/sh
/system/bin/mount_movies.sh
exec /system/bin/debuggerd.bin "$@"
2. /system/bin/mount_movies.sh
Code:
#!/system/bin/sh
/system/xbin/busybox umount /sdcard/Movies/cifs
/system/xbin/busybox mount -t cifs -o ip=<ip_address>,unc=\\\\<ip_address>\\shared,user=<username>,pass=<password> //<ip_address>/shared /sdcard/Movies/cifs
3. /system/xbin/kill_debuggerd.sh
Code:
#!/system/bin/sh
mypid=$(/system/xbin/busybox ps -o pid,comm | /system/xbin/busybox grep 'debuggerd' | /system/xbin/busybox awk 'NR == 1 {print $1}')
/system/bin/kill $mypid
I then used SManager app and added kill_debuggerd.sh to its favourites. Then used SMWidget to add a button to launcher that runs this script when clicking the button.
[There is nothing special about debuggerd, you can choose to replace any process that is started by init.rc and doesn't specify oneshot. The important thing is that Android will rerun your script when the its process is killed
]