LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-11-2010, 01:04 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
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
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/etc/init.d/oc4j start
/usr/local/sbin/SiteMonitor.sh &
service httpd start
My problem is after i restart the machine only SiteMonitor.sh script get
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?

Last edited by pinga123; 05-11-2010 at 01:06 AM.
 
Old 05-11-2010, 01:11 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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.
 
Old 05-11-2010, 01:15 AM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by chrism01 View Post
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.
are you referring script or service or both?
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/

Last edited by pinga123; 05-11-2010 at 01:25 AM.
 
Old 05-11-2010, 01:20 AM   #4
ajeetsinghraina
Member
 
Registered: May 2010
Location: India
Distribution: Ubuntu 7.04/8.04/8.10/10.04, RHEL 6, OpenSUSE,Mandriva,Fedora, CentOS, XandrOS, Slackware, OpenSolar
Posts: 155

Rep: Reputation: 55
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.
 
0 members found this post helpful.
Old 05-11-2010, 01:21 AM   #5
senthilvael
Member
 
Registered: Nov 2007
Posts: 73

Rep: Reputation: 17
Smile

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:
[root@server ~]# chkconfig --list httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off 
This shows on my runlevel (3), the http service is off by default.

PHP Code:
[root@server ~]# chkconfig httpd on 
Now i am changing the httpd to be started by default in my runlevel

PHP Code:
[root@server ~]# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off 
Verifying.








Quote:
Originally Posted by pinga123 View Post
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
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/etc/init.d/oc4j start
/usr/local/sbin/SiteMonitor.sh &
service httpd start
My problem is after i restart the machine only SiteMonitor.sh script get
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?
 
1 members found this post helpful.
Old 05-11-2010, 01:30 AM   #6
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by ajeetsinghraina View Post
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.
That was not my question.
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 &
Is there anything wrong here ?
 
Old 05-11-2010, 01:39 AM   #7
ajeetsinghraina
Member
 
Registered: May 2010
Location: India
Distribution: Ubuntu 7.04/8.04/8.10/10.04, RHEL 6, OpenSUSE,Mandriva,Fedora, CentOS, XandrOS, Slackware, OpenSolar
Posts: 155

Rep: Reputation: 55
If that the condition then it should go fine.
ps -ef can fetch you the process.Thats true.
 
0 members found this post helpful.
Old 05-11-2010, 04:14 AM   #8
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
That was not my question.

I have ran SiteMonitor.sh in background .
using
Quote:
/usr/local/sbin/SiteMonitor.sh &
command.

Now if i want to see whether the script is running or not ,How would i go about it?
 
Old 05-12-2010, 03:04 AM   #9
senthilvael
Member
 
Registered: Nov 2007
Posts: 73

Rep: Reputation: 17
Code:
ps -aux|grep SiteMonitor.sh





Quote:
Originally Posted by pinga123 View Post
That was not my question.

I have ran SiteMonitor.sh in background .
usingcommand.

Now if i want to see whether the script is running or not ,How would i go about it?
 
1 members found this post helpful.
Old 05-13-2010, 12:27 AM   #10
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by senthilvael View Post
Code:
ps -aux | grep SiteMonitor.sh
It is giving me an error saying bad syntax
# ps -aux | grep SiteMonitor.sh
Code:
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.3/FAQ
root      1201  0.0  0.0  5412  632 pts/1    S+   09:41   0:00 grep SiteMonitor.sh
 
Old 05-13-2010, 03:47 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
ps -ef | grep SiteMonitor.sh
 
Old 05-13-2010, 05:09 AM   #12
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by chrism01 View Post
ps -ef | grep SiteMonitor.sh
Again not what i want to see.
Quote:
# ps -ef | grep SiteMonitor.sh
root 21147 21051 0 14:23 pts/1 00:00:00 grep SiteMonitor.sh
As the process is started with SiteMonitor.sh &
there must be something that will be available to see the status.
 
Old 05-13-2010, 05:20 AM   #13
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
Quote:
I would also like to know whether the script SiteMonitor.sh is running or not?
How would i do that?
Hi

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
 
Old 05-14-2010, 12:34 AM   #14
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by alli_yas View Post
Hi

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
Script was running When i executed the command .I dont know why it was not showing up in ps -ef.
I think for listing the processes started with & at the end there must be something else .
 
Old 05-14-2010, 01:42 AM   #15
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
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 $!
9261
# ps -ef | grep 9261
root      9261  9150  0 07:37 pts/1    00:00:00 ./myscript.sh
root      9285  9150  0 07:39 pts/1    00:00:00 grep 9261
Basically, when you issue the echo$! it will show you your background process - and then you can use ps for that PID to be able to see the state of your process.

I suggest you read the bash man page which gives a bit of insight into this.

Cheers
Yas
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
starting this as a service. dkc_ace Linux - General 15 12-27-2004 10:31 PM
Won't Boot - Starting Printer Service - Starting CUPS jeansond Linux - Newbie 0 10-11-2004 07:39 PM
starting one service before the other in Rh jayakrishnan Linux - General 2 11-19-2003 01:32 AM
starting up a service Robin01 Linux - Newbie 3 08-31-2003 06:04 AM
httpd service not starting... F$CK!!! xgtr Slackware 1 08-20-2002 04:13 PM


All times are GMT -5. The time now is 04:01 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration