LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-22-2015, 09:56 AM   #1
itreyger
LQ Newbie
 
Registered: May 2015
Posts: 2

Rep: Reputation: Disabled
Need to start application service only when other services are up and running


I am new to Linux but need a help with script that will restart the naming service when it's down only if other app services are up and running and do nothing if other service are down. That's in case when there is a app maintenance or Linux servers patching going on. here is what I came up so far:
#!/bin/bash

###edit the following
service=orbadmin ns
email=test@company.com
###stop editing

host=`host -f`
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running"
else
/etc/init.d/$service start
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
subject="$service at $host has been started"
echo "$service at $host wasn't running and has been started" | mail -s "$subject" $email
else
subject="$service at $host is not running"
echo "$service at $host is stopped and cannot be started!!!" | mail -s "$subject" $email
fi
fi
 
Old 05-22-2015, 02:48 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
This variable declaration won't work as is:
service=orbadmin ns
You'd have to put quotes around it:
service="orbadmin ns"

The next question is are you looking for "orbadmin ns" to be on the same command line in your ps output or are you talking about two different services called "orbadmin" and "ns". If the latter then the rest of your script wouldn't work unless you put in a for loop to check each service e.g.
for svc in $service
do (whatever)
done

Your (whatever) wouldn't be the same for both services though.

You don't have to do the for loop if in fact you're looking for a single "orbadmin ns" line in ps output.

Also I believe you meant to use "hostname -f" rather than "host -f" when setting host variable. You can also use the $() instead of backticks:
host=$(hostanme -f)
 
1 members found this post helpful.
Old 05-26-2015, 10:24 AM   #3
itreyger
LQ Newbie
 
Registered: May 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks MensaWater!
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Server Services start after login and remain running Catalyph Linux - Security 3 08-06-2012 03:11 PM
[SOLVED] Logging in and running an application on start up macanucaire Linux - Newbie 3 07-01-2012 11:30 AM
[SOLVED] Auto running an application on start up u03pje Linux - Newbie 4 11-02-2009 11:08 AM
How to start an application/service in startup? lawrence_lee_lee Linux - Software 4 09-21-2007 02:57 AM
services wont start, nor service-config birras Fedora 3 10-24-2004 08:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:26 PM.

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