View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 6 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
 Post subject: runit sv issues
PostPosted: Fri Apr 03, 2020 3:29 pm 
Offline
Joined: Tue Mar 27, 2018 12:02 pm
Posts: 40
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


Last edited by caymann on Sat Apr 04, 2020 1:52 pm, edited 2 times in total.


Top
 Profile  
 
 Post subject: Re: runit sv issues
PostPosted: Sat Apr 04, 2020 9:03 am 
Offline
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location: SC
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.


Top
 Profile  
 
 Post subject: Re: runit sv issues
PostPosted: Sat Apr 04, 2020 2:10 pm 
Offline
Joined: Tue Mar 27, 2018 12:02 pm
Posts: 40
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


Top
 Profile  
 
 Post subject: Re: runit sv issues
PostPosted: Sat Apr 04, 2020 2:30 pm 
Offline
Joined: Tue Mar 27, 2018 12:02 pm
Posts: 40
Sorry still doesn't work


Top
 Profile  
 
 Post subject: Re: runit sv issues
PostPosted: Mon Apr 06, 2020 5:43 am 
Offline
Joined: Tue Mar 27, 2018 12:02 pm
Posts: 40
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


Top
 Profile  
 
 Post subject: Re: runit sv issues
PostPosted: Mon Apr 06, 2020 12:53 pm 
Offline
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1194
Location: SC
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.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 24 guests


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 post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu