Keep Server Alive with Cron Job


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Keep Server Alive with Cron Job
# 1  
Old 08-12-2010
Keep Server Alive with Cron Job

Despite my best efforts, my media streaming server still dies sometimes and I am in a random place trying to ssh into the server to restart it on my cell phone after customers start calling.... I tried using google to track down a script that would do the following

Every 5 min execute:
sudo /etc/init.d/WowzaMediaServer status

Then it would grep the returned text for "started" and if it isn't found would execute:
sudo /etc/init.d/WowzaMediaServer start

I am not sure how to setup the script + it is going to ask for a password to use the sudo command.

Anybody able to give me a hand? Seems like a nice script that many people should have on hand anyway.
# 2  
Old 08-12-2010
You probably don't need sudo just to do /etc/init.d/service status. Which is fortunate since running sudo every five minutes could fill your logfiles with pointless junk.

sudo can be configured to let a certain user run a certain program without a password.

I'd just have cron run a script file. If checking every hour is fine, you could just put the script in /etc/cron.hourly/check-mediaserver.sh and it'd run it hourly under the cron user.

In the script file:

Code:
#!/bin/sh

source /etc/profile

/etc/init.d/WowzaMediaServer status || sudo /etc/init.d/WowzaMediaServer start

Depending on your init system this may generate output that'd get mailed by your cron daemon if it can, or end up in dead.letter if it can't.

You can edit your sudo permissions as root with visudo. You could add a line like:

Code:
cron ALL=NOPASSWD: /etc/init.d/WowzaMediaServer

...which would let the cron user run /etc/init.d/WozxaMediaServer as root without a password.

Last edited by Corona688; 08-12-2010 at 02:28 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

3. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

4. UNIX for Advanced & Expert Users

cron job to extact lines from files to another file and ftp to new server

i have a text file in this format: which creates a new one everyday in the form of filename _zing__r200_2012_8_10_log.txt Fri Aug 10 07:29:17 EDT 2012, usera(192.168.0.245) to anotheruser: hey top, this is a private test Fri Aug 10 07:29:28 EDT 2012, anotheruser(192.168.0.245) to usera: got... (2 Replies)
Discussion started by: bkkid
2 Replies

5. Shell Programming and Scripting

Script that will be a cron job to export rrd files for cacti server

I wrote a quick little script that will eventually end up as a cron job to export rrd files for my cacti server. Here is the script: #!/bin/bash rm -rf /backup/cacti_xml/* cd /var/www/html/rra ls -1 *.rrd | awk '{print "rrdtool dump "$1" > /backup/cacti_xml/"$1".xml"}' | sh -x Is there... (5 Replies)
Discussion started by: TheBigAmbulance
5 Replies

6. UNIX for Dummies Questions & Answers

How to find the server ip is alive ?

How to write a shell script to find ports are open for the server. Thanks in advance. regards krackjack (4 Replies)
Discussion started by: krackjack
4 Replies

7. UNIX for Dummies Questions & Answers

Server moved, new IP, broken CRON job

Due to downsizing and attrition, I have inherited SysAdmin tasks, but unfortunately not all the required knowledge and skills came to me along with the assignment -> so I appreciate any advice and help ( be patient with my newbie terms and questions). We moved a central server and changed it's... (1 Reply)
Discussion started by: HikerLT
1 Replies

8. UNIX for Dummies Questions & Answers

Keeping cron jobs alive...?

Hi, I'm very new to Unix so please bear with me... :) Here is my requirement: I need to create a cron job to run two different scripts at 1 a.m. every day. Here's what I did: I used the "crontab -e" command and created a crontab file using the vi editor. When I exit the editor using... (3 Replies)
Discussion started by: yogiB
3 Replies

9. Shell Programming and Scripting

check if job still alive and killing it after a certain walltime

Hi! I'm using a script to start a process that might run forever if some parameters are given wrong (it's part of an optimization). I would now like to have the process killed after a certain walltime in that case. So far I get it done with the following lines ./My_process.e & pid=`ps -ef |... (3 Replies)
Discussion started by: ciwstevie
3 Replies

10. UNIX for Dummies Questions & Answers

CRON Job - saving to a different server?

Thanks for the all the help last evening on CRON jobs. It's now working. Is it possible with cron to save a backup of a file to a different server or location? The idea being that if one host goes arse over tit, I'll have a backup of the DB on another server? Many thanks, Ed Ludlow (3 Replies)
Discussion started by: eludlow
3 Replies
Login or Register to Ask a Question