Results 1 to 4 of 4
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 ...
- 03-04-2009 #1Just Joined!
- Join Date
- May 2005
- Posts
- 5
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.
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".
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
- 03-05-2009 #2
- 03-05-2009 #3Just Joined!
- Join Date
- May 2005
- Posts
- 5
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.
- 03-05-2009 #4
Try the following:
start() {
while [ `tail /var/log/nsa1/nsa.log | grep -c "application up" ` -lt 1 ] || [ `tail /var/log/nik1/nik.log | grep -c "application up" ` -lt 1 ]; do
echo Waiting for apps to start
sleep 5
done
echo -n "Starting timetrack "
su - ttrack -c /time/bin/timetrackstart
echo
touch /var/lock/subsys/timetrack
}
This will test each file, and sleep for 5 seconds before trying again, until both have application up.


Reply With Quote