I want to automatically start email tunnels and socks proxy at boot time. I have an /etc/init.d/email-tunnels
script that invokes another script under my home directory. It won't work at boot time, it won't work if I execute sudo service email-tunnels start
, but it does work if I just run it, sudo /etc/init.d/email-tunnels start
. BTW, I have an identical setup on another machine (Debian 8), and it works like a charm on that one.
These are the details (of the Ubuntu 18 setup, the one that is not working):
[···]$ ls -lh /etc/init.d/email-tunnels
-rwxr-xr-x 1 root root 602 Aug 28 10:21 /etc/init.d/email-tunnels
[···]$
The contents is (including some debugging echo
s):
[···]$ cat /etc/init.d/email-tunnels
#! /bin/sh
### BEGIN INIT INFO
# Provides: email_tunnels
# Required-Start: $all
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3
# Default-Stop: 0 1 6
# Short-Description: E-mail and HTTP tunnels over SSH
### END INIT INFO
echo "email-tunnels invoked at `date`" >> /tmp/email-tunnels.log
touch /var/lock/email-tunnels
case "$1" in
start)
echo "email-tunnels executing 'start' at `date`" >> /tmp/email-tunnels.log
su -c "/home/cal/bin/email.sh &" cal
;;
stop)
;;
*)
echo "Usage: /etc/init/email-tunnels {start|stop}"
exit 1
;;
esac
exit 0
And then, my script on my home directory:
[···]$ ls -lh /home/cal/bin/email.sh
-rwxr-xr-x 1 cal cal 410 Aug 28 10:09 /home/cal/bin/email.sh
[···]$
And its contents:
[···]$ cat /home/cal/bin/email.sh
#!/bin/bash
echo "email.sh executed at `date`" >> /tmp/email.log
sleep 30
while [ "1" == "1" ]
do
echo "email.sh about to execute ssh at `date`" >> /tmp/email.log
ssh -N -D5080 -Llocalhost:10110:xx.xx.xx.xx:110 -Llocalhost:10025:xx.xx.xx.xx:25 [email protected]
sleep 120
done
The tunnels user on my target (server) machine does have the PK authentication properly configured, so that I can ssh-connect without any user interaction (without having to supply a password).
Any ideas why it's not working? From the debugging output, I see that the init.d script (email-tunnels) is executed (I see the output at /tmp/email-tunnels.log), but not the /home/cal/bin/email.sh --- when I manually run /etc/init.d/email-tunnels start
, then I do see the /tmp/email.log debugging output, and for that matter the tunnels work after I ran it.
/etc/init.d/
scripts rather than just having a cron job for that user scheduled to run@reboot
?@reboot
feature seems a bit unreliable (e.g., unix.stackexchange.com/questions/109804/…). Plus, familiarity would also be a reason (I feel --- or maybe I should say felt --- more comfortable with handling the init.d scripts to do what needs to be done after a reboot)