0

I have to setup port forwarding on system start and have this configured in my rc.local

runuser -l phpAdmin -c 'ssh -f -N -L 9904:localhost:3306 phpAdmin@<server>'

When rc.local is executed, is it executed as root?

foobarmoo
  • 15
  • 1
  • 3

1 Answers1

0

rc.local is executed as root user, but this is not probably the place to start such tunnel because if you get any problem (even a temporary network problem), your tunnel will be stopped forever. A better solution is to put it in /etc/inittab file, so that your init process may run it in your correct runlevel, and respawn it if it crashes. If you run it from inittab remove the "-f" flag from ssh invokation, otherwise init will not be able to detect ssh failing.

eppesuig
  • 313
  • 1
  • 10
  • Do you mean add an entry in inittab itself or create an entry like /etc/init.d/foo with foo having the port forwarding script? – foobarmoo Dec 07 '12 at 10:14
  • in inittab, like "TT:23:respawn:/bin/su phpAdmin -c 'ssh ...'" – eppesuig Dec 07 '12 at 10:57
  • Now that we are on it, a question, what is the difference between doing it in init tab versus adding another entry under init.d? If you can point me to a link also, I would be very happy. Thanks for the help. – foobarmoo Dec 07 '12 at 12:10
  • in inittab you just put a command line and it will be executed when init switch run level. In init.d you store scripts and you may invoke them with an argument (usually start/stop/restart/status) and you may have many scripts in the same runlevel (just link them from /etc/rcN.d where N is the runlevel) and you may sort them. More info to /etc/init.d startup sequence depends on what startup procedure you are using: check all "upstart" "systemd" "sysv-rc" – eppesuig Dec 07 '12 at 13:04