TechTalkz.com Logo Ask the Experts!

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Linux & Opensource

auto-running a script as daemon

Linux & Opensource

 
 
Thread Tools Display Modes
Unread 05-12-2007, 05:46 PM   #1
Tony van der Hoff
Guest
 
Posts: n/a
auto-running a script as daemon

I have a perl script to monitor various bits of my server, which I run as
root: /usr/local/sbin/monitor.pl &

That works fine, but I'd really like to start it automatically on reboot.
How would I organise that?

--
Tony van der Hoff | mailto:news_0711@vanderhoff.org
Buckinghamshire, England

Sponsored Links
 
Unread 05-12-2007, 05:46 PM   #2
Geoffrey Clements
Guest
 
Posts: n/a
Re: auto-running a script as daemon

"Tony van der Hoff" <news@nospam.vanderhoff.org> wrote in message
news:gemini.jsl2w1005t6v4052s.news@nospam.vanderho ff.org...
>I have a perl script to monitor various bits of my server, which I run as
> root: /usr/local/sbin/monitor.pl &
>
> That works fine, but I'd really like to start it automatically on reboot.
> How would I organise that?
>


1. Drop the script into /etc/init.d.
2. Look at /etc/inittab and find what run level you're starting at, the line
will look something like this:
id:x:initdefault:
where x is the value you want.

3. Put a symlink to /etc/init.d/monitor.pl into /etc/rc.d/rcx.d where again
x is the number from inittab. The symlink should be somthing like
Snnmonitor.pl where nn are two digits defining the order of the services to
start relative to the other services in that run level.

Please note that the directory names and positions vary with each
distribution so you may need to change things slightly.

--
Geoff


 
Unread 05-12-2007, 05:46 PM   #3
User98
Guest
 
Posts: n/a
Re: auto-running a script as daemon

> 1. Drop the script into /etc/init.d.
> 2. Look at /etc/inittab and find what run level you're starting at, the
> line will look something like this:
> id:x:initdefault:
> where x is the value you want.
>
> 3. Put a symlink to /etc/init.d/monitor.pl into /etc/rc.d/rcx.d where
> again x is the number from inittab. The symlink should be somthing like
> Snnmonitor.pl where nn are two digits defining the order of the services
> to start relative to the other services in that run level.


You may also need to do a similar job on a script to stop the process when
your system is being shut down.


 
Unread 05-12-2007, 05:47 PM   #4
Gordon Henderson
Guest
 
Posts: n/a
Re: auto-running a script as daemon

In article <gemini.jsl2w1005t6v4052s.news@nospam.vanderhoff.o rg>,
Tony van der Hoff <news_0711@vanderhoff.org> wrote:
>I have a perl script to monitor various bits of my server, which I run as
>root: /usr/local/sbin/monitor.pl &
>
>That works fine, but I'd really like to start it automatically on reboot.
>How would I organise that?


It varies from distro to distro... Eg. Debian look in /etc/init.d for a
file called skeleton - this is a bash script, so copy this to eg
/etc/init.d/monitorMyStuff and edit to start your own thing, then run

update-rc.d monitorMyStuff defaults

and it'll create all the right symbolic links in /etc/rc?.d. See the
man page for update-rc.d to work out how to get it to start before or
after various other things (if needed) and note that it will get called
with a parameter of start or stop, depending on the machine booting or
shutting down.

Gordon
 
Unread 05-12-2007, 05:47 PM   #5
Tony van der Hoff
Guest
 
Posts: n/a
Re: auto-running a script as daemon

On 5 Dec at 16:11 "Geoffrey Clements"
<geoffrey.clementsNO@SPAMbaesystems.com> wrote in message
<4756c9d8$1_1@glkas0286.greenlnk.net>

> "Tony van der Hoff" <news@nospam.vanderhoff.org> wrote in message
> news:gemini.jsl2w1005t6v4052s.news@nospam.vanderho ff.org...
> > I have a perl script to monitor various bits of my server, which I run
> > as root: /usr/local/sbin/monitor.pl &
> >
> > That works fine, but I'd really like to start it automatically on
> > reboot. How would I organise that?
> >

>
> 1. Drop the script into /etc/init.d. 2. Look at /etc/inittab and find what
> run level you're starting at, the line will look something like this:
> id:x:initdefault: where x is the value you want.
>
> 3. Put a symlink to /etc/init.d/monitor.pl into /etc/rc.d/rcx.d where
> again x is the number from inittab. The symlink should be somthing like
> Snnmonitor.pl where nn are two digits defining the order of the services
> to start relative to the other services in that run level.
>

Thanks, Geoff; I'm sure I knew that once, but my memory must be slipping...

> Please note that the directory names and positions vary with each
> distribution so you may need to change things slightly.
>

No, it was all as you describe. Thanks again.

--
Tony van der Hoff | mailto:news_0711@vanderhoff.org
Buckinghamshire, England
 
Unread 05-12-2007, 05:47 PM   #6
Tony van der Hoff
Guest
 
Posts: n/a
Re: auto-running a script as daemon

On 5 Dec at 16:25 Gordon Henderson <gordon+usenet@drogon.net> wrote in
message <fj6jdf$20if$1@energise.enta.net>

> In article <gemini.jsl2w1005t6v4052s.news@nospam.vanderhoff.o rg>, Tony van
> der Hoff <news_0711@vanderhoff.org> wrote:
> > I have a perl script to monitor various bits of my server, which I run
> > as root: /usr/local/sbin/monitor.pl &
> >
> > That works fine, but I'd really like to start it automatically on
> > reboot. How would I organise that?

>
> It varies from distro to distro... Eg. Debian look in /etc/init.d for a
> file called skeleton - this is a bash script, so copy this to eg
> /etc/init.d/monitorMyStuff and edit to start your own thing, then run


Thanks, Gordon; my distro doesn't have that; I can only see things like
"Program Files", and "My Documents and Settings".

Um, not really , but I'm running Mandriva, which has its roots in red hat,
and what Geoff described was ideal.

Thanks for replying, anyway.

Cheers, Tony



--
Tony van der Hoff | mailto:news_0711@vanderhoff.org
Buckinghamshire, England
 
Unread 05-12-2007, 07:04 PM   #7
Tony van der Hoff
Guest
 
Posts: n/a
Re: auto-running a script as daemon

On 5 Dec at 16:11 "Geoffrey Clements"
<geoffrey.clementsNO@SPAMbaesystems.com> wrote in message
<4756c9d8$1_1@glkas0286.greenlnk.net>

> "Tony van der Hoff" <news@nospam.vanderhoff.org> wrote in message
> news:gemini.jsl2w1005t6v4052s.news@nospam.vanderho ff.org...
> > I have a perl script to monitor various bits of my server, which I run
> > as root: /usr/local/sbin/monitor.pl &
> >
> > That works fine, but I'd really like to start it automatically on
> > reboot. How would I organise that?
> >

>
> 1. Drop the script into /etc/init.d. 2. Look at /etc/inittab and find what
> run level you're starting at, the line will look something like this:
> id:x:initdefault: where x is the value you want.
>
> 3. Put a symlink to /etc/init.d/monitor.pl into /etc/rc.d/rcx.d where
> again x is the number from inittab. The symlink should be somthing like
> Snnmonitor.pl where nn are two digits defining the order of the services
> to start relative to the other services in that run level.
>

Thanks, Geoff; I'm sure I knew that once, but my memory must be slipping...

> Please note that the directory names and positions vary with each
> distribution so you may need to change things slightly.
>

No, it was all as you describe. Thanks again.

--
Tony van der Hoff | mailto:news_0711@vanderhoff.org
Buckinghamshire, England
 
Unread 05-12-2007, 07:04 PM   #8
Tony van der Hoff
Guest
 
Posts: n/a
Re: auto-running a script as daemon

On 5 Dec at 16:25 Gordon Henderson <gordon+usenet@drogon.net> wrote in
message <fj6jdf$20if$1@energise.enta.net>

> In article <gemini.jsl2w1005t6v4052s.news@nospam.vanderhoff.o rg>, Tony van
> der Hoff <news_0711@vanderhoff.org> wrote:
> > I have a perl script to monitor various bits of my server, which I run
> > as root: /usr/local/sbin/monitor.pl &
> >
> > That works fine, but I'd really like to start it automatically on
> > reboot. How would I organise that?

>
> It varies from distro to distro... Eg. Debian look in /etc/init.d for a
> file called skeleton - this is a bash script, so copy this to eg
> /etc/init.d/monitorMyStuff and edit to start your own thing, then run


Thanks, Gordon; my distro doesn't have that; I can only see things like
"Program Files", and "My Documents and Settings".

Um, not really , but I'm running Mandriva, which has its roots in red hat,
and what Geoff described was ideal.

Thanks for replying, anyway.

Cheers, Tony



--
Tony van der Hoff | mailto:news_0711@vanderhoff.org
Buckinghamshire, England
 
Unread 06-12-2007, 12:45 AM   #9
Martin Gregorie
Guest
 
Posts: n/a
Re: auto-running a script as daemon

Tony van der Hoff wrote:
> On 5 Dec at 16:25 Gordon Henderson <gordon+usenet@drogon.net> wrote in
> message <fj6jdf$20if$1@energise.enta.net>
>
>> In article <gemini.jsl2w1005t6v4052s.news@nospam.vanderhoff.o rg>, Tony van
>> der Hoff <news_0711@vanderhoff.org> wrote:
>>> I have a perl script to monitor various bits of my server, which I run
>>> as root: /usr/local/sbin/monitor.pl &
>>>
>>> That works fine, but I'd really like to start it automatically on
>>> reboot. How would I organise that?

>> It varies from distro to distro... Eg. Debian look in /etc/init.d for a
>> file called skeleton - this is a bash script, so copy this to eg
>> /etc/init.d/monitorMyStuff and edit to start your own thing, then run

>
> Thanks, Gordon; my distro doesn't have that; I can only see things like
> "Program Files", and "My Documents and Settings".
>
> Um, not really , but I'm running Mandriva, which has its roots in red hat,
> and what Geoff described was ideal.
>

If your distro is RedHat-like, there is a bit of help:
- there's no example script, but its easy enough to find something
suitable in /etc/rc.d/init.d, copy it and edit it. At a minimum
it should have sections that implement start, stop, status and restart
requests. The vs-ftp or sshd scripts are reasonable starting points.

- use the "chkconfig" command to set up the symlinks in /etc/rc.d/rc.n
(where 'n' is the run level) that are used to start or stop the
service whenever the runlevel is changed

- use the "service" command to start, stop and restart the service or
query its status.

chkconfig and service can only be run as root.


--
martin@ | Martin Gregorie
gregorie. | Es***, UK
org |
 
Unread 06-12-2007, 12:57 AM   #10
Martin Gregorie
Guest
 
Posts: n/a
Re: auto-running a script as daemon

Sponsored Links
Tony van der Hoff wrote:
> On 5 Dec at 16:25 Gordon Henderson <gordon+usenet@drogon.net> wrote in
> message <fj6jdf$20if$1@energise.enta.net>
>
>> In article <gemini.jsl2w1005t6v4052s.news@nospam.vanderhoff.o rg>, Tony van
>> der Hoff <news_0711@vanderhoff.org> wrote:
>>> I have a perl script to monitor various bits of my server, which I run
>>> as root: /usr/local/sbin/monitor.pl &
>>>
>>> That works fine, but I'd really like to start it automatically on
>>> reboot. How would I organise that?

>> It varies from distro to distro... Eg. Debian look in /etc/init.d for a
>> file called skeleton - this is a bash script, so copy this to eg
>> /etc/init.d/monitorMyStuff and edit to start your own thing, then run

>
> Thanks, Gordon; my distro doesn't have that; I can only see things like
> "Program Files", and "My Documents and Settings".
>
> Um, not really , but I'm running Mandriva, which has its roots in red hat,
> and what Geoff described was ideal.
>

If your distro is RedHat-like, there is a bit of help:
- there's no example script, but its easy enough to find something
suitable in /etc/rc.d/init.d, copy it and edit it. At a minimum
it should have sections that implement start, stop, status and restart
requests. The vs-ftp or sshd scripts are reasonable starting points.

- use the "chkconfig" command to set up the symlinks in /etc/rc.d/rc.n
(where 'n' is the run level) that are used to start or stop the
service whenever the runlevel is changed

- use the "service" command to start, stop and restart the service or
query its status.

chkconfig and service can only be run as root.


--
martin@ | Martin Gregorie
gregorie. | Es***, UK
org |

Sponsored Links
 
 

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT. The time now is 08:09 PM.


vBulletin, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © 2005-2016, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional