LinHES Forums
http://forum.linhes.org/

runit sv issues
http://forum.linhes.org/viewtopic.php?f=22&t=26041
Page 1 of 1

Author:  caymann [ Fri Apr 03, 2020 3:29 pm ]
Post subject:  runit sv issues

The command works perfectly when i run this on a command line interface:
sudo openvpn --config /etc/openvpn/client/myvpn.conf

I get a VPN IP address

I want to automate this during bootup....

$sudo mkdir /etc/sv/myvpn/
$sudo nano /etc/sv/myvpn/run

Actual script...
#!/bin/sh
exec 2>&1
export TERM=linux
. /etc/rc.conf
. /etc/rc.d/functions
stat_runit "Starting MyVPN"
exec sudo openvpn --config /etc/openvpn/client/myvpn.conf


I make this executible: sudo chmod +x /etc/sv/myvpn/run

$ sudo add_service.sh myvpn
$ sudo sv start myvpn
$ sudo sv status myvpn

Response i get is
run: myvpn: (pid 27344) 4774s; down: log: 1s, normally up, want up

Even after i bootup, it doesn't run


Any thoughts?

jim

Author:  brfransen [ Sat Apr 04, 2020 9:03 am ]
Post subject:  Re: runit sv issues

sv already is running as root so you don't need to sudo openvpn in the run script. The other thing is that for runit to manage the process using exec the process must remain in the foreground. So if when you run it from the cmd line it returns you to a prompt you will need to find an option that keeps openvpn in the foreground or you will need to write a finish file.

To test stop the service then if running from a non root accout "
Code:
sudo /etc/sv/myvpn/run
and you can see what it might be getting hung up on. Ctrl+c to quit and if everything is good start the service.

Author:  caymann [ Sat Apr 04, 2020 2:10 pm ]
Post subject:  Re: runit sv issues

If i do
$sudo /usr/bin/openvpn --config /etc/openvpn/myvpn.conf
It connects to the myvpn server and gets me VPN IP address but doesn't give me command prompt back.
So i guess, that is what i need to mimic using sv
I am thinking of adding a return at the end should do it

What changes to the /etc/sv/myvpn/run script do i need to accomplish that?
Here is the script called run.

#!/bin/sh
exec 2>&1
export TERM=linux
. /etc/rc.conf
. /etc/rc.d/functions
stat_runit "Starting MyVPN"
exec ls -l /dev/net/tun
exec modprobe tun
exec /usr/bin/openvpn --config /etc/openvpn/myvpn.conf
return

Author:  caymann [ Sat Apr 04, 2020 2:30 pm ]
Post subject:  Re: runit sv issues

Sorry still doesn't work

Author:  caymann [ Mon Apr 06, 2020 5:43 am ]
Post subject:  Re: runit sv issues

solved it:

I changed the script to:-
(notice there is no exec in front of modprobe)

modprobe tun
stat_runit "Starting MyVPN"
exec /usr/bin/openvpn --config /etc/openvpn/myvpn.conf

Author:  brfransen [ Mon Apr 06, 2020 12:53 pm ]
Post subject:  Re: runit sv issues

Guess I never hit Submit but you found the issue. runit only manages one process so only use the exec on the process you want it to manage.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/