restarting radius:(

Silver-0-surfer

Well-Known Member
Joined
Jan 5, 2008
Messages
317
Hi

we have a server that runs freeradius, and every couple of days it just stops, the radius services, we are in the proccess of building a new server, the only problem is it dies at the most awkward times and then we get calls from people and have to restart it and it fine again..

I wanted to setup a cronjob to check if the radius.pid file exists like every 5 minutes or so and this is what I have

*/5 * * * * bash /home/cronjobs/restart_radius.sh

#!/bin/bash

file=`find /var/run/freeradius/ -name 'freeradius.pid'`
if [ -n "$file" ] ; then
echo "Radius Still up"
else
/etc/init.d/freeradius restart
fi


I am not a programmer/scripter or anything but whats the problem here? I see in the logs it says

Date: Sat, 27 Feb 2010 16:35:02 +0200 (SAST)

* Stopping FreeRADIUS daemon freeradius
* /var/run/freeradius/freeradius.pid not found...
...done.
* Starting FreeRADIUS daemon freeradius
/etc/init.d/freeradius: 63: start-stop-daemon: not found
...done.

So it didn't work and I had to manually type in /etc/init.d/freeradius start and then it comes up:confused:

any1 have some ideas as to why this isn;t working
 

Nephew_

Senior Member
Joined
Sep 2, 2009
Messages
754
I suggest not to use this to check for the file existence:
Code:
file=`find /var/run/freeradius/ -name 'freeradius.pid'`
if [ -n "$file" ] ; then .....

Rather use this:
Code:
if [ -f /var/run/freeradius/freeradius.pid ] ; then ...
This IF condition check for the existence of a file and do not depend on find.
See if it improves the script.
 
Last edited:

Silver-0-surfer

Well-Known Member
Joined
Jan 5, 2008
Messages
317
I could be wrong but I think the problem lies after the "else" because I am going through the log and I see Radius Still up, Radius Still up, Radius Still up like every 5 minutes. But thanks for that, my way looks a bit sloppy:/
 

Nephew_

Senior Member
Joined
Sep 2, 2009
Messages
754
I am also spotting this now:
Code:
/etc/init.d/freeradius: 63: start-stop-daemon: not found

Make sure the "/etc/init.d/freeradius" script is calling a deamon that is existing and has the right path.

The other question is, if the deamon dies by itself, it could mean that the file freeradius.pid still exists even though it does not run anymore.

If that is the case, rather check if the process is still running with ps, something like:
Code:
isrunning=`ps -eo cmd|grep -c radius`
if [ $isruning -gt 0 ]
then
     echo "Radius is still running"
     .....
 

graviti

Senior Member
Joined
May 8, 2006
Messages
665
Hi
#!/bin/bash

file=`find /var/run/freeradius/ -name 'freeradius.pid'`
if [ -n "$file" ] ; then
echo "Radius Still up"
else
/etc/init.d/freeradius restart
fi

I have an idea. It's possible that the freeradius init.d script doesn't have the restart function. I don't run it, so I have no idea. Instead of /etc/init.d/freeradius restart, change the restart to just start, seeing as we don't need to stop it anyway.
Cheers
 

Silver-0-surfer

Well-Known Member
Joined
Jan 5, 2008
Messages
317
lol, guys I don;t know whats going on:D

so I killed radius and then ran my script

bash /home/cronjobs/restart_radius.sh

and just like that it starts up again...


@ graviti, I did try that as well before I posted here but had no success

Make sure the "/etc/init.d/freeradius" script is calling a deamon that is existing and has the right path.

I may not quite understand what you are saying by this but as I run this outside of the script and it works, I can only assume its calling it correctly.

This cronjob is running under root, i can only assume it uses root privileges.

I really don't know..:wtf:


edit: grammar/spelling:)
 
Last edited:

sjm

Expert Member
Joined
Apr 17, 2009
Messages
1,127
Your environment when logged on is WAY different from what cron gets, had to learn this the hard way (several times).

Rules with cron
- Always give full paths to executables
- be careful of relying on shell built in functions
- always check your cron task before assuming it'll run (maybe initially set it for 2 minutes after current time & see whether it runs ok or not).
- always make sure that the cron email goes to a real address & check that as well
 
Top