LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Howto stop squid before executing crontab file? (https://www.linuxquestions.org/questions/linux-server-73/howto-stop-squid-before-executing-crontab-file-868427/)

gardenair 03-14-2011 03:14 AM

Howto stop squid before executing crontab file?
 
Hi,
I am using squid 2.6 on my cent os 5 .I want to shutdown the system at 7:00 pm for that purpose I write in
# crontab -e

0 19 * * * /sbin/shutdown -h now

The thing which I want to clear that when the system will going to turn off it will also stop squid service? If not then how can I automatically stop squid service and then crontab file execute ?
kindly guide me
garden

repo 03-14-2011 03:16 AM

Quote:

The thing which I want to clear that when the system will going to turn off it will also stop squid service?
Since you shutdown the system, all running processes will be turned off.

Kind regards

EricTRA 03-14-2011 03:18 AM

Hello,

Normally your system should take care of that. You can have a look in the /etc/rc.d/rc0.d folder to check when (in what order) your services are shutting down. The higher the number, the later the service will stop. This is done so that dependent services get stopped before the service they depend on.

Kind regards,

Eric

gardenair 03-14-2011 03:35 AM

Thnks for the reply. I can check it by
# vi /etc/rc.d/rc0.d

what you say If I a script may work


Code:

vi /root/auto_shutdown_script

#!/bin/bash

/etc/init.d/squid stop > /dev/null 2> /dev/null

if [ $? -eq 0 ]
then
shutdown -h now > /dev/null 2> /dev/null
fi



Step..2

crontab -e

* 19 * * * sh /root/auto_shutdown_script > /dev/null


kaushalpatel1982 03-14-2011 04:03 AM

While you shutting your system, All services running on the server will going to shutdown.

Just shutdown the system and forget everything.

gardenair 03-14-2011 11:38 PM

EricTRA as you mentioned in your post You can have a look in the /etc/rc.d/rc0.d folder to check when (in what order) your services are shutting down. How can I check it ?
kindly just explain it
thanks
garden

EricTRA 03-15-2011 02:42 AM

Hello,

Just do:
Code:

ls /etc/rc.d/rc0.d
You'll get a list of links to scripts in init.d beginning with either K (Kill) or S (Start). The initial letter is followed by a number which indicates the sequence in which the scripts will start. If beginning with K then the stop command will be passed to the script in init.d to which the link references. If beginning with an S then the start command will be passed.
Code:

K01dnsmasq -> ../init.d/dnsmasq
K01smartd -> ../init.d/smartd
K02avahi-daemon -> ../init.d/avahi-daemon
K02avahi-dnsconfd -> ../init.d/avahi-dnsconfd
K02NetworkManager -> ../init.d/NetworkManager
K02oddjobd -> ../init.d/oddjobd
K03yum-updatesd -> ../init.d/yum-updatesd
S00killall -> ../init.d/killall
S01halt -> ../init.d/halt

Above is a list of some of the links in a CentOS server. You'll see that dnsmasq and smartd get stopped (Kill) before avahi-daemon and so on. The scripts starting with S are there to kill remaining processes, remove lock files and some other actions before the system is halted. You can check the contents of either of the init.d script to see what they do exactly.

At this link you can find some more basic information about runlevels and init scripts.

Kind regards,

Eric


All times are GMT -5. The time now is 01:19 AM.