| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		keopp Senior Member
 
  Joined: 08 Nov 2008 Posts: 166 Location: Romania
  | 
		
			
				 Posted: Sun Aug 19, 2012 1:55 pm    Post subject: pid files in /var/run | 
				     | 
			 
			
				
  | 
			 
			
				Hello,
 
 
Looking for a server.pid file in /var/run(working to configure an openvpn servr), I strangely found only 3 files(except subdiredtories) inside this directory as follows:
 
 
  	  | Quote: | 	 		  
 
2
 
=acpid.socket
 
server.pid
 
 | 	  
 
 
The weirdest thing, was the content of the file "2" created today:
 
 
 	  | Quote: | 	 		  
 
ls: cannot access 1: No such file or directory
 
/dev/null
 
acpid.pid
 
atd.pid
 
dhcpd.pid
 
inetd.pid
 
klogd.pid
 
server.pid
 
sshd.pid
 
syslogd.pid
 
 | 	  
 
 
And it was right: excepting server.pid recently created, all the other was missing.
 
 
Reboot solved the problem but have someone a clue of what is the origin of that? | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		keopp Senior Member
 
  Joined: 08 Nov 2008 Posts: 166 Location: Romania
  | 
		
			
				 Posted: Sun Aug 19, 2012 2:15 pm    Post subject:  | 
				     | 
			 
			
				
  | 
			 
			
				SOLVED
 
 
It is the "rm -rf" inside the rc.openvpn file:
 
 
 	  | Code: | 	 		  
 
...
 
openvpn_stop() {
 
    echo "Stoping Openvpn Tunnels"
 
    killall openvpn 2&>1 /dev/null
 
    rm -rf $piddir/*.pid
 
    return 0
 
}
 
...
 
 | 	  
 
 
I belive it is enough to replace:
 
 	  | Code: | 	 		  piddir=/var/run
 
...
 
$openvpn --writepid /var/run/`echo $conf | cut -d. -f1`.pid --daemon --config $conf
 
 | 	  
 
 
with 
 
 
 	  | Code: | 	 		  piddir=/var/run/openvpn
 
...
 
$openvpn --writepid $piddir/`echo $conf | cut -d. -f1`.pid --daemon --config $conf
 
 | 	  
 
 
I also belive that the following statements are not sintactically correct as the usage of /dev/null, 2 and 1.
 
 
 	  | Code: | 	 		  
 
ls *.pid 1&>2 /dev/null
 
...
 
killall openvpn 2&>1 /dev/null | 	  
 
because these are the generators of the files 2 and 1 containing error messages
 
 
Searcing for other script examples I found interesting and useful the inclusion of
 
 
 	  | Code: | 	 		  | /sbin/modprobe tun >/dev/null 2>&1 | 	  
 
 
at the beginning of the rc script. | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		gerasimos_h Site Admin
 
  Joined: 09 Aug 2007 Posts: 1757 Location: Greece
  | 
		
			
				 Posted: Sun Aug 19, 2012 3:40 pm    Post subject:  | 
				     | 
			 
			
				
  | 
			 
			
				You are correct, rc.openvpn it's a little messed up, it's my bad to not check it, how it works...
 
I'll fix it...
 
An updated package will upload soon along with other upgrades.
 
 
Thanks for the bug report...
 
 
gerasimos_h _________________ Superb! Mini Server Project Manager
 
http://sms.it-ccs.com | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		keopp Senior Member
 
  Joined: 08 Nov 2008 Posts: 166 Location: Romania
  | 
		
			
				 Posted: Sun Aug 19, 2012 4:46 pm    Post subject:  | 
				     | 
			 
			
				
  | 
			 
			
				Ok, I'm glad to help. I use for now the followng working rc.openvpn:
 
 
 	  | Code: | 	 		  
 
#!/bin/sh
 
# Start/stop/restart all the openvpn processes
 
#by Giancarlo Razzolini
 
 
#openvpn binary
 
openvpn=/usr/sbin/openvpn
 
#piddir
 
piddir=/var/run/openvpn
 
#conf dir
 
confdir=/etc/openvpn
 
 
openvpn_start() {
 
    echo -n "Starting openvpn: "
 
    /sbin/modprobe tun >/dev/null 2>&1
 
    #for all the conf files in the openvpn dir, start a new process
 
    cd $confdir
 
    echo "Starting Openvpn Tunnels:"
 
    for conf in `ls *.conf` ; do
 
   echo -e "\t$openvpn $confdir/$conf"
 
   $openvpn --writepid $piddir/`echo $conf | cut -d. -f1`.pid --daemon --config $conf 
 
    done
 
    return 0
 
}
 
 
openvpn_status() {
 
    cd $piddir
 
    ls *.pid > /dev/null 2>&1
 
    if [ "$?" != "0" ] ; then
 
   echo "No openvpn process is running."
 
    else
 
   for process in `ls *.pid` ; do
 
       echo Process `cat $process` is running...
 
   done
 
    fi
 
    return 0
 
}
 
 
openvpn_stop() {
 
    echo "Stoping Openvpn Tunnels"
 
    killall openvpn > /dev/null 2>&1
 
    rm -rf $piddir/*.pid
 
    return 0
 
}
 
 
openvpn_restart() {
 
    openvpn_stop
 
    sleep 1
 
    openvpn_start
 
}
 
    
 
case "$1" in
 
'start')
 
   openvpn_start
 
   ;;
 
'status')
 
   openvpn_status
 
   ;;
 
'stop')
 
   openvpn_stop
 
  ;;
 
'restart')
 
   openvpn_restart
 
   ;;
 
    *)
 
   echo "usage $0 start|stop|status|restart"
 
esac
 
 | 	 
  | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		 |