LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-01-2013, 12:27 PM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Rep: Reputation: 55
What is the best way/tool to monitor several services, and issue a restart command?


What is the best way/tool to monitor several services, and issue a restart command if one is down?

IE. Connect to port 80 and if that connection ever fails, restart apache and then try to reconnect.

TIA
 
Old 08-01-2013, 03:07 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Well I beat on this for an hour, so here goes...

It needs work, but it's a start?
Code:
#!/bin/bash
if [[ $(curl -Is http://ipa.ddr.ess:80 | \grep -E '^Server' | cut -c9-14)  = Apache ]] ; then 
	exit 
else $(ssh -i /path/to/keyless/key root@host "service httpd restart") 
fi
#EOF
Assumes Apache as the server.
Assumes you have key-based ssh setup.
Code:
service httpd restart
This "may" be another command, so substitute whatever command restarts the service(s) on the target.

That ought to get you going.

Have fun.

For several services, you could replicate the script or use a Monitoring program such as Zabbix.

Last edited by Habitual; 08-01-2013 at 03:19 PM. Reason: added :80 to curl parameter
 
1 members found this post helpful.
Old 08-01-2013, 04:09 PM   #3
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Original Poster
Rep: Reputation: 55
Thanks!
 
Old 08-01-2013, 04:11 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
You are very welcome.
 
Old 08-01-2013, 04:38 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by Habitual View Post
For several services, you could replicate the script or use a Monitoring program such as Zabbix.
...or use something lighter on resources like Monit?..
 
Old 08-01-2013, 04:39 PM   #6
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by unSpawn View Post
...or use something lighter on resources like Monit?..
I just came across Monit earlier today, I'll check that out.

Thx
 
Old 08-01-2013, 05:19 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
What is the best way/tool to monitor several services, and issue a restart command?

httpcheck from nagios
 
Old 08-02-2013, 03:12 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
On the other hand, you could just create a cronjob on the sever itself, no networking reqd.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Restart services - 'service' command not found davee Linux - Newbie 9 03-16-2013 12:34 AM
How can I monitor services such as apache and mysql, and restart them automatically? abefroman Linux - Software 3 05-21-2008 10:06 PM
What is the best tool to monitor services on linux? abefroman Linux - Software 6 04-11-2008 09:45 AM
LXer: Linux automatically monitor and restart services when daemon is killed LXer Syndicated Linux News 0 11-25-2006 10:21 PM
command to restart services djc Linux - Newbie 3 03-31-2004 02:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration