ssh tunnel as a daemon

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



FC2 Uptodate

I'm trying to figure out how to daemon'ize a script that I have to start
an ssh port forwading tunnel.  Here is how I'm doing it:

the script (name is sshtun):
---snip---
while [ true ]; do
 ssh -nN2g -c $Crypt $LPort:$LHost $RUser@$RHost -L $RPort:$LHost:$LPort
done
---snip---

the init script (sshtund):
---snip---
daemon $ProgramFull
....
killproc $ProgramFull
---snip---

The problem:
When I call service sshtund start, the ssh process does go to the
background and sshtund never exits.

So I tried this with the init:
---snip---
$ProgramFull &
....
killproc $ProgramFull
---snip---

but then service sshtund stop doest work.  So I changed the stop section
of the init to:

---snip---
$ProgramFull &
....
killall -qgs 9 $ProgramName
---snip---

where ProgramName is sshtun.  And this works but all further processing
of the init script (everything that follows the killall) doesn't get
done and the init script returns.

So, it appears that the ssh is holding the init script and tie'ing it to
the ssh command but I can not seem to separate the init script from the
program it calls (not sure if it is  possible).  OK thats cool, So I can
give the ssh command (in the script sshtun) the -f option to put ssh in
the background.  But I have to get rid of the while-do-done which
creates my real problem.  So, my question is:

Is there a best practice on scripting a process to make sure a
background process is running?  Or when a background process drops off
it triggers an event that would attempt to start it up again?  Any ideas
would help.



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux