Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
vpn init script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
Letharion
Veteran
Veteran


Joined: 13 Jun 2005
Posts: 1319
Location: Sweden

PostPosted: Mon Mar 30, 2009 7:07 pm    Post subject: vpn init script Reply with quote

I made this script
Code:
name="VPN"
depend() {
   need net
}
start() {
   ebegin "Connecting to VPN"
   start-stop-daemon --start --exec /usr/sbin/pon VPN --pidfile /var/run/ppp0.pid
   /sbin/route add -net 192.168.175.0 netmask 255.255.255.0 dev ppp0
   eend $?
}

stop() {
   ebegin "Disconnecting from VPN"
   start-stop-daemon --stop --exec /usr/sbin/poff VPN
   eend $?
}

Starting pon works well, however, route doesn't seem to execute.
And on stop, I get a complant that "start-stop-daemon: no matching processes found". The pid file does appear to contain the correct PID-number
How can I improve this?

Should I really put this in net.eth?
Back to top
View user's profile Send private message
karmaking
Tux's lil' helper
Tux's lil' helper


Joined: 11 Feb 2004
Posts: 81
Location: Berlin, Germany

PostPosted: Tue Mar 31, 2009 12:32 pm    Post subject: Reply with quote

route probably isn't executed, because the pon script doesn't detach itself. Use the -b switch for start-stop-daemon.

On stop, it cannot find the pid, because it's looking for poff, while you started pon. Maybe don't use start-stop-daemon at all but run the scripts directly.
Back to top
View user's profile Send private message
Letharion
Veteran
Veteran


Joined: 13 Jun 2005
Posts: 1319
Location: Sweden

PostPosted: Tue Mar 31, 2009 12:39 pm    Post subject: Reply with quote

Sweet, thanks :)
It seems if route executes immediately, it fails. Adding the pause however, helps.
There are atleast 2 major problems with this. (a) I wastes time and (b) Once in a while it might take 5.01 seconds, and then again it doesn't work.

Is there a better way to solve this?

Code:
name="VPN"
depend() {
   need net
}
start() {
   ebegin "Connecting to VPN"
   /usr/sbin/pon VPN
   sleep 5 #Give pon a chance to get an ip
   /sbin/route add -net 192.168.175.0 netmask 255.255.255.0 dev ppp0
   eend $?
}
stop() {
   ebegin "Disconnecting from VPN"
   /usr/sbin/poff VPN
   eend $?
}
Back to top
View user's profile Send private message
karmaking
Tux's lil' helper
Tux's lil' helper


Joined: 11 Feb 2004
Posts: 81
Location: Berlin, Germany

PostPosted: Tue Mar 31, 2009 12:48 pm    Post subject: Reply with quote

Boy this starts to become a dirty hack now :)

Create a new script which calls pon, waits for 10 secs and then sets the route. Call this script from within your init script with & (detach) so it will do the waiting in the background.
Back to top
View user's profile Send private message
Letharion
Veteran
Veteran


Joined: 13 Jun 2005
Posts: 1319
Location: Sweden

PostPosted: Tue Mar 31, 2009 12:51 pm    Post subject: Reply with quote

Haha, yeah ;)

Thanks, that's a good idea.

Could you give me any hints on what I should to do reduce the "dirty hack" level of this?

Does this kind of stuff really belong in net.ethX? Or do I just need better bash haxx skills to make it better?
Back to top
View user's profile Send private message
karmaking
Tux's lil' helper
Tux's lil' helper


Joined: 11 Feb 2004
Posts: 81
Location: Berlin, Germany

PostPosted: Tue Mar 31, 2009 1:06 pm    Post subject: Reply with quote

Letharion wrote:
Could you give me any hints on what I should to do reduce the "dirty hack" level of this?


Uh well better not as I'm not that kind of a bash guru. :roll: As long as it works for you, fine!

Letharion wrote:
Does this kind of stuff really belong in net.ethX?


It doesn't matter how you name your script. The net.lo script is designed to be called via symbolic links to it which are named e.g. net.ethx or net.wlanx and which then brings up those interfaces according to the name of the symbolic link. If you name your script net.vpn or whatever, it just doesn't matter.
Back to top
View user's profile Send private message
Letharion
Veteran
Veteran


Joined: 13 Jun 2005
Posts: 1319
Location: Sweden

PostPosted: Tue Mar 31, 2009 1:11 pm    Post subject: Reply with quote

karmaking wrote:
Letharion wrote:
Could you give me any hints on what I should to do reduce the "dirty hack" level of this?


Uh well better not as I'm not that kind of a bash guru. :roll: As long as it works for you, fine!

Ok ;)

karmaking wrote:
Letharion wrote:
Does this kind of stuff really belong in net.ethX?


It doesn't matter how you name your script. The net.lo script is designed to be called via symbolic links to it which are named e.g. net.ethx or net.wlanx and which then brings up those interfaces according to the name of the symbolic link. If you name your script net.vpn or whatever, it just doesn't matter.

My question was ill-formed.
the net scripts use some special syntax. (Don't they?) While I guess the syntax isn't contained to /etc/init.d/net.* (As that sounds stupid and hard to enforce) I'm guessing they are unique to the Gentoo enviroment? And as such I figured maybe there are clever ways already written to handle things like this, and I should use those. :)
Back to top
View user's profile Send private message
karmaking
Tux's lil' helper
Tux's lil' helper


Joined: 11 Feb 2004
Posts: 81
Location: Berlin, Germany

PostPosted: Tue Mar 31, 2009 1:46 pm    Post subject: Reply with quote

The Gentoo network interface init scripts are indeed designed in a special way - they start/stop interfaces according to the name of the file they have been called as. So if you take the generic /etc/init.d/net.lo script, rename it (or link to it) as e.g. /etc/init.d/net.eth0, and then run it with the "start" parameter, it will start the eth0 interface. The same script with the name /etc/init.d/net.wlan0 will act accordingly with the interface wlan0.

Thus I'm sure there are ways to incorporate automatic VPN connects into this script (or another init script) in a more elegant way than we did here, but I don't know about it. You could also modify the generic net.* script into your own net.eth0 script and include the pon/poff commands in a clever way.

If you manage to, please post it here :)
Back to top
View user's profile Send private message
karmaking
Tux's lil' helper
Tux's lil' helper


Joined: 11 Feb 2004
Posts: 81
Location: Berlin, Germany

PostPosted: Tue Mar 31, 2009 1:56 pm    Post subject: Reply with quote

This http://wiki.joyrex.net/wiki/Gentoo,_Relakks_VPN,_NAT_and_Firewall#PPP deals with automatic vpn connections on startup and maybe helps you.

You basically can create a /etc/init.d/net.ppp0 script and tell it what to do via an ppp0 entry in /etc/conf.d/net

Good luck!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum