shell script for httpd
Hi, I make this script but I'm not sure if this is correct.
Code:
#!/bin/bash I HOPE YOUR HELP. Regards I USE DEBIAN 4.* |
try replacing
/usr/sbin/$SERVICE -k restart with /etc/init.d/$SERVICE restart |
This script runs forever - doesn't it make more sense to create a simpler script that is run as a cron job? Then you will have much better control about the timing intervals. Your script won't eat a lot of system resources, but it's just bad practice to use endless loops with sleep calls.
---------- T74marcell Arch Linux |
I don't user cron jobs but is a good idea. I have cron jobs of directadmin control panel so this can be work?
|
Quote:
On top of that, your non-precise grep 80 statement could match anything that has, e.g. "80" in the PID. So you'd violently kill something you did not intend to kill, and then start only httpd. All your script really needs to do is this: Code:
# pgrep httpd >/dev/null || /etc/init.d/httpd start |
I'd also add that this is a poor approach to service management, IMO. If httpd is crashing regularly, diagnose and solve the problem. You should also deploy some form of service monitoring - e.g. Nagios.
|
Quote:
|
so my script is wrong and the correct shell script is just: # pgrep httpd >/dev/null || /etc/init.d/httpd start ???
|
Your script is causing a lot of unnecessary activity (and probably service interruptions) for the httpd daemon. A closely related question is: why is this script you're proposing necessary? Is httpd regularly crashing?
The one-liner I suggested could run as a cronjob every 5 minutes or so. |
Is httpd regularly crashing?
YES =( I'm newbie on Linux. Frequently it's necessary to kill the process of httpd and up again. |
LOOK THIS:
IN THIS MOMENT MY HTTPD SERVICE IS CRASHING SO I PROCCED TO CHECK THE ISSUE: box:~# lsof -w -n -i tcp:80 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME h 8858 apache 3u IPv6 1684609 TCP *:www (LISTEN) wtf? h command? So if I try to run my httpd service the system print an error like this: You can't use 80 port because is in use. So for solve the problem I use the follow commands: box:~# kill -9 8858 box:~# /usr/sbin/httpd -k start box:~# lsof -w -n -i tcp:80 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME httpd 21138 root 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21139 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21140 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21141 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21142 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21143 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21144 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21145 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21146 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21147 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21148 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21149 apache 3u IPv6 1761832 TCP *:www (LISTEN) httpd 21150 apache 3u IPv6 1761832 TCP *:www (LISTEN) box:~# AND ALL IS OK! =/ ... But this happeds frecuently so I need a shell script to do this. Regards SORRY IF MY ENGLISH IS BAD. |
Like Anomie already said: if your httpd is crashing regularly combatting symptoms won't make the problem go away. You need to diagnose and solve the problem instead. Do your system and http daemon access and error logs show warnings or errors?
|
error_log
[Sat Mar 07 00:10:15 2009] [notice] Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8c DAV/2 PHP/5.2.9 configured -- resuming normal operations [Sat Mar 07 00:11:02 2009] [notice] caught SIGTERM, shutting down |
Quote:
What I'd suggest is editing httpd.conf so that you have the directive: Code:
LogLevel info --- Also, are you the only sysadmin on this server? Is anyone else root or a sudoer besides you? |
Quote:
# lsof -p <pid_here> (... in addition to the other items above.) |
All times are GMT -5. The time now is 03:58 PM. |