Starting a service at startup.
Hi guys I want to start a service and a script SiteMonitor.sh at startup.
Here is brief working of SiteMonitor.sh (This script monitors the ip addresses of machines which are using http service of the host. This script checks this after every 5 seconds therefore i have run it at background. ) To start with i have modified /etc/rc.local file. Here is the content of my /etc/rc.local file. Code:
#!/bin/sh executed but the command service httpd start doesnt .Therefore i have to manually login to the system and fire service httpd start to start apache. I would also like to know whether the script SiteMonitor.sh is running or not? How would i do that? |
Normally you set it on using the chkconfig cmd http://linux.die.net/man/8/chkconfig or the equiv. You don't need an entry in/etc/rc.local.
|
Quote:
What should be the runlevel for apache service? What should be start and end priority? The reason i m using rc.local file is beacause one of our senior member has suggested that in following thread. http://www.linuxquestions.org/questions/linux-newbie-8/need-to-run-script-at-startup-786850/ |
Say, SiteMonitor.sh is under /opt/ directory.
Just browse to : #vi /etc/rc.local And add: sh /opt/SiteMonitor.sh at the last line Save it. Note: Make sure the script has executable permission. |
Hi,
Please check the following link. Monit will do exactly what you need. http://mmonit.com/monit/ To start the http service, at boot time, PHP Code:
PHP Code:
PHP Code:
Quote:
|
Quote:
My SiteMonitor.sh Script ran successfully at background I just wanted to know How would i determine whether the script is running or not. May be using ps -ef (or something like this). I have copied SiteMonitor.sh to /usr/local/sbin/ which is in my $PATH I just added following line to /etc/rc.local file Code:
/usr/local/sbin/SiteMonitor.sh & |
If that the condition then it should go fine.
ps -ef can fetch you the process.Thats true. |
That was not my question.
I have ran SiteMonitor.sh in background . using Quote:
Now if i want to see whether the script is running or not ,How would i go about it? |
Code:
ps -aux|grep SiteMonitor.sh Quote:
|
Quote:
# ps -aux | grep SiteMonitor.sh Code:
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ |
ps -ef | grep SiteMonitor.sh
|
Quote:
Quote:
there must be something that will be available to see the status. |
Quote:
As per above you want to see if your script is running or not. The previous command that you ran (ps -ef | grep sitemonitor.sh) basically will show you whether your script has been spawned as a process or not - thus if you don't see your script with a process ID it means that its not running. Cheers Yas |
Quote:
I think for listing the processes started with & at the end there must be something else . |
Hi
Yes - you're quite right. When you run the script with the ampersand (&) at the end the script is run in the background in a sub-shell. Here's how you see whether your script is running or not: Code:
# echo $! I suggest you read the bash man page which gives a bit of insight into this. Cheers Yas |
All times are GMT -5. The time now is 04:41 AM. |