LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-04-2009, 10:00 AM   #1
pitbull7270
LQ Newbie
 
Registered: Feb 2009
Posts: 11

Rep: Reputation: 0
Need help with a start-up script


I have been tasked with creating a chkconfig startup script for an application. I have most of it done, it just doesn't work and keeps throwing errors at me. The application needs to check two log files to see if that application is up and running, once it is then it is safe to start this application.

Or if there is a better way please help. I am fairly new to this and we are replacing windows boxes weekly with linux ones. I hand typed this in so if there are any obvious errors, sorry.

Here is the script:
#!/bin/bash
#
# Startup script for time tracker
# chkconfig: 23 99 15
# description: time tracker
# processname: timetrack
# pidfile: /var/run/timetrack.pid

# Source function library. This creates the operating environment for the process to be start
. /etc/rc.d/init.d/functions

NIK1=`tail /var/log/nik1/nik.log | grep "application up"`
NSA1=`tail /var/log/nsa1/nsa.log | grep "application up"`

start() {
if [ "$NIK1" = "!" ] && exit 1
if [ "$NSA1" = "!" ] && exit 1
then
echo -n "Starting timetrack"
su - ttrack -c /time/bin/timetrackstart
echo
touch /var/lock/subsys/timetrack
}
stop() {
echo -n "Stopping timetrack"
su - ttrack -c /time/bin/timetrackstop
echo
rm -f /var/lock/subsys/timetrack
rm -f /var/run/timetrack.pid
}
status() {
status timetrack
}
restart() {
$0 stop
$0 start
}
reload() {
echo -n "Reloading timetrack"
killproc timetrack -HUP
echo
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac

exit 0
 
Old 03-04-2009, 10:07 AM   #2
pitbull7270
LQ Newbie
 
Registered: Feb 2009
Posts: 11

Original Poster
Rep: Reputation: 0
Actually I forgot to add if both log files do not have the "application up" then the software needs to either retry, or sit and wait for the "application up" and then start. I do not know how to put a pause into a script, maybe that would work if they are not at "application up".
 
Old 03-04-2009, 09:00 PM   #3
T74marcell
Member
 
Registered: Mar 2009
Posts: 102

Rep: Reputation: 18
chkconfig scripts are merely meant to launch server applications (daemon processes). So it's rather the launched server software that should do the "application up" testing and looping with this test until the server is stopped. Somehow I have the feeling that you are using the chkconfig concept for something that it wasn't meant for.

You could just as well add your (modified) script as a cronjob, so it would retry it's task in a defined time interval.

Arch Linux

Last edited by T74marcell; 03-14-2009 at 12:49 AM.
 
Old 03-05-2009, 08:22 AM   #4
pitbull7270
LQ Newbie
 
Registered: Feb 2009
Posts: 11

Original Poster
Rep: Reputation: 0
Why wouldn't chkconfig be the proper thing? I figured out part of the problem, the errors anyway. This works as far as starting the program but both log files were in their ready state. Now I need to figure out how to put in a retry command. Here is the code that was wrong and the corrected statement.
bad:
start() {
if [ "$NIK1" = "!" ] && exit 1
if [ "$NSA1" = "!" ] && exit 1
then
echo -n "Starting timetrack"
su - ttrack -c /time/bin/timetrackstart
echo
touch /var/lock/subsys/timetrack
}

good:
start() {
if [ "$NIKU1" > 0 ] && [ "$NSA1" > 0 ]; then
echo -n "Starting timetrack "
su - ttrack -c /time/bin/timetrackstart
echo
touch /var/lock/subsys/timetrack
else
exit 1
fi
}

As for the retry I want the system to check these logs, and if they aren't both containing the "application up" to retry every say 10 seconds until the logs are meeting the criteria. Not sure if a while command would work.
 
Old 03-05-2009, 08:38 AM   #5
healyma
Member
 
Registered: Feb 2009
Location: Mayo, Ireland
Distribution: LFS 6.4; Debian 5.4; Mythbuntu & Kubuntu 10.04
Posts: 49

Rep: Reputation: 19
Hi,
A while loop would be an inefficient way of doing it and a bit of a resource hog.

a cron job might work better - where you can call your original script repeatedly. I think this is limited to a minimum interval of a minute though.

e.g.
Run script,
if either process is not running
- set up cron job to call this script every minute
else if both processes running
- delete cron job
- run the application


Mark
 
  


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
ssh - using variables in call to start remote script from local script babag Linux - Networking 2 06-03-2008 04:50 PM
bash - start remote script from local script? babag Programming 7 04-06-2008 05:46 PM
Get script to start again at a certain point in the script (bash) helptonewbie Programming 11 01-11-2008 05:49 AM
Start a script after GDM autologin, don't quit when script finishes Plastech Linux - Newbie 2 05-29-2007 10:15 AM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 11:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:06 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