Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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".
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.