nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

shell script to start a service

This is a discussion on shell script to start a service within the Shell scripting forums, part of the Development/Scripting category; Hi. I need a script which could start squid automatically if it stops. I've added squid into rc.local but sometimes ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 06-10-2008, 01:01 PM
Member
User
 
Join Date: Jul 2006
Posts: 48
Rep Power: 0
asim.mcp
Angry shell script to start a service

Hi.

I need a script which could start squid automatically if it stops.
I've added squid into rc.local but sometimes when i start my machine it does not start automatically, can anyone help to write a script which could check if squid has started then it would not start again and if squid has not been started then it would start automatically..

Regards
Asim
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-10-2008, 03:48 PM
Junior Member
User
 
Join Date: Feb 2008
My distro: .
Posts: 9
Rep Power: 0
unSpawn is on a distinguished road
Default

If you want to script this yourself you could check the PID file Squid uses when it runs, check if it exists and if it does cat it and save the PID to a variable. Then notice the full commandline Squid runs as, use that in pgrep -f 'commandline' and save the PID( to an array. Check if the array is empty ("${#array[@]}"), else compare PIDs. If empty or PIDs not matching up, stop Squid gracefully, remove the PID file then start Squid.
OTOH running a dedicated process watcher like Monit is easy to configure and expand, faster in checking and more versatile as it can start, restart about any service and alert you all in one go and all of the time.
Reply With Quote
  #3 (permalink)  
Old 06-11-2008, 11:11 AM
Member
User
 
Join Date: Jul 2006
Posts: 48
Rep Power: 0
asim.mcp
Default

Dear Thanks for your reply.
I'm not expert in shell scripting, can you please guide me how can i define all this in a script?

Regards
ASim
Reply With Quote
  #4 (permalink)  
Old 06-11-2008, 07:59 PM
Junior Member
User
 
Join Date: Feb 2008
My distro: .
Posts: 9
Rep Power: 0
unSpawn is on a distinguished road
Default

Sure. Just make a start, post it here and I'll try and correct it.
Reply With Quote
  #5 (permalink)  
Old 06-12-2008, 12:09 PM
Member
User
 
Join Date: Jul 2006
Posts: 48
Rep Power: 0
asim.mcp
Default

Dear would you please write a simple script in the form of that you've above described so that it would be easy for me to proceed next and then i could be able to provide all the things those are required to make this script. Kindly help me.

Regards
Asim
Reply With Quote
  #6 (permalink)  
Old 06-12-2008, 06:55 PM
Junior Member
User
 
Join Date: Feb 2008
My distro: .
Posts: 9
Rep Power: 0
unSpawn is on a distinguished road
Default

echo '*/1 * * * * /somePath/pgrep -f '/somePath/squid' >/dev/null 2>&1 || /somePath/squid' >> /etc/crontab
Reply With Quote
  #7 (permalink)  
Old 07-28-2008, 12:18 PM
Junior Member
User
 
Join Date: Jul 2008
My distro: CentOS, RedHat
Posts: 2
Rep Power: 0
badsector is on a distinguished road
Thumbs up

Just my suggestion, I think you dont need a script to run the service on startup.you can use this instead "chkconfig --level 35 squid on"

It depends on your runlevel you used.
Reply With Quote
Reply

Bookmarks

Tags
chkconfig , linux , redhat , runlevel


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
start service permanently in debian myfoot Ubuntu / Debian 2 06-13-2008 01:16 PM
writing a shell script to find out my shell name jaymob123 Shell scripting 1 10-08-2007 12:36 AM
start and stop service in crontab. gthian Shell scripting 7 05-31-2007 11:04 AM
Redhat Enterprise Linux RHEL - Start service on boot chimu Getting started tutorials 0 01-26-2007 07:29 PM
start up and stop the running script mala_un Shell scripting 9 07-26-2006 07:10 AM


All times are GMT +5.5. The time now is 12:10 PM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36