Re: bash script as daemon from startup
From: Reiner Griess (mynewnews_at_gmx.net)
Date: 02/24/05
- Next message: Reiner Griess: "Re: bash script as daemon from startup"
- Previous message: CV: "Case-insensitive matching in bash - Again"
- In reply to: Alan Connor: "Re: bash script as daemon from startup"
- Next in thread: Alan Connor: "Re: bash script as daemon from startup"
- Reply: Alan Connor: "Re: bash script as daemon from startup"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 24 Feb 2005 15:48:25 +0100
Alan Connor wrote:
> On Thu, 24 Feb 2005 12:10:32 +0100, Reiner Griess <mynewnews@gmx.net> wrote:
>>Alan Connor wrote:
>>>On Wed, 23 Feb 2005 23:35:58 +0100, Reiner Griess
>>><mynewnews@gmx.net> wrote:
>>>
>>>>I know this question was asked often before. But I was not able
>>>>to find a suitable solution. [...]
>>>>
>>>>Now, as I said, I want to start a bash script as a daemon. [...]
>>>
>>>
>>>Interesting. I run Debian too, and had a look at that skeleton
>>>script in /etc/init.d.
>>
>>the skeleton: /etc/init.d/skeleton
>>
>>
>>>Why wouldn't it work for a bash script? They are programs too...
>>
>>My test-shell-script /root/SCRIPTS/while:
>>#!/bin/bash
>>while true
>>do
>> echo "jop" >> /root/SCRIPTS/output
>> sleep 1
>>done
>>
>>And the initscript, based on the skeleton:
>><--- while.initscript --->
>>#! /bin/sh
>>PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
>>DAEMON=/root/SCRIPTS/while
>>NAME=whiledaemon
>>DESC="while daemon"
>>
>>test -x $DAEMON || exit 0
>>
>>set -e
>>
>>case "$1" in
>> start)
>> echo -n "Starting $DESC: $NAME"
>> start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
>> --exec $DAEMON
>> echo "."
>> ;;
>> stop) # and so on and on
>><--- while.initscript --->
>>
>>
>>Now, when I am executing the initscript:
>>/etc/init.d/while.init start
>>the output of the script is "Starting while daemon: whiledaemon" and
>>nothing else happens. The script runs in the background but will not get
>>detached from the shell!
>>
>>Any hints?
>>reiner
>
>
> Errrr.....RTFM?
>
> :-)
YEAH! This seems to be a good idea ;-)
> From man start-stop-daemon:
>
>
> <quote>
>
> -b|--background
> Typically used with programs that don't detach on
> their own. This option will force start-stop-daemon
> to fork before starting the process, and force it
> into the background. WARNING: start-stop-daemon
> cannot check the exit status if the process fails
> to execute for any reason. This is a last resort,
> and is only meant for programs that either make no
> sense forking on their own, or where it's not fea
> sible to add the code for it to do this itself.
>
>
> </quote>
>
> Another option would be to run the script in screen, and then
> detach the screen session. But it wouldn't be anywhere near
> as efficient.
Uh, no!
But "-b" works! I read the man page. But, I was *blind* maybe :)
> There's probably a utility somewhere that one can use to detach
> processes from the shell, but I don't know what it is.
The most important thing is: it runs!
Nice. Hopefully this works with my original bash script and not only
with this sensless do...while loop.
Thank you, alan!
reiner
- Next message: Reiner Griess: "Re: bash script as daemon from startup"
- Previous message: CV: "Case-insensitive matching in bash - Again"
- In reply to: Alan Connor: "Re: bash script as daemon from startup"
- Next in thread: Alan Connor: "Re: bash script as daemon from startup"
- Reply: Alan Connor: "Re: bash script as daemon from startup"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|