Using daemon from /etc/init.d/functions

Steve smorrey at gmail.com
Fri Mar 30 14:37:12 MDT 2007


I dunno about redhat, but anything I've ever wanted to run as a
daemon, I'ld just do the double fork thing in code.  This way even if
you don't have access to the init system (shared hosting for
instance), you can run your service daemon.

As an interesting aside, I once decided to cheap out on a server, and
went with one of those shared hosting for noobs deals.  I created a
simple c++ program that that basically just piped a TCP connection
straight to bash, did the double fork trick, then wrote a PHP script
to allow me to launch it remotely.
Poof instant shell access :D

On 3/30/07, Dave Smith <dave at thesmithfam.org> wrote:
> I've written a C++ server application for Linux, and it just runs in the
> foreground for now. It's come time to ship it to users, and I want to
> provide a Red Hat init script with it. I've written such an init script,
> and I use this in my script to start the server:
>
> start() {
>     echo -n $"Starting Dave's Server: "
>     daemon /usr/bin/daves-server
>     RETVAL=$?
>     touch /var/lock/subsys/daves-server
>     echo
>     return $RETVAL
> }
>
> case "$1" in
>   start)
>     start
>     ;;
> ...
>
>
> The daemon function doesn't appear to background my executable. Do I
> need to fork() in my executable's code, or should daemon be
> backgrounding it for me somehow? I've read over the daemon function in
> /etc/init.d/functions, and it looks like it ends by running this command:
>
>     initlog -q -c /usr/bin/daves-server
>
> Anyway, just curious if I need to do my own forkin()'ing, or if Red
> Hat's daemon() is supposed to background it for me.
>
> When I call daemon(int,int) (from unitstd.h) in my executable's code,
> the init script works fine, but I was just wondering if I could get away
> without doing that...
>
> Thanks!
>
>
> --Dave
>
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
>



More information about the PLUG mailing list