[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: daemonizing a command



On Fri, May 28, 2010 at 2:43 AM, Israel Garcia <igalvarez@gmail.com> wrote:
> On Thu, May 27, 2010 at 9:59 PM, Neal Hogan <nealhogan@gmail.com> wrote:
>> On Thu, May 27, 2010 at 2:52 PM, Israel Garcia <igalvarez@gmail.com> wrote:
>>> Hi,
>>>
>>> I need to daemonize this command on a debian lenny?
>>>
>>> ruby apd.rb
>>>
>>> It's a simple app for my network.
>>>
>>> I was thinking to use nohup ruby app.rb & at rc.local, but I want to
>>> know if there's other ways to do it.
>>
>> It's been awhile since I wrote such a script, so the details aren't at
>> the tip of my tongue, but the following helped me when I did. Perhaps
>> it will help.
>>
>> http://www.debian-administration.org/article/Making_scripts_run_at_boot_time_with_Debian
> Hi Neal,
>
> I did it this way.. look my init script :-)
>
> #! /bin/sh
> # /etc/init.d/apd
> #
>
> # Some things that run always
>
> # Carry out specific functions when asked to by the system
> case "$1" in
>  start)
>    echo "Starting postfix policy daemon...."
>    sleep 1
>    ruby /usr/local/bin/apd.rb & > /dev/null
>    echo ""   > /dev/null
>    ;;
>  stop)
>    echo "Stopping postfix policy daemon...."
>    sleep 1
>     kill -9 `ps afx|grep "ruby /usr/local/bin/apd.rb"|grep -v
> grep|awk '{print $1}'` >/dev/null
>    ;;
> restart)
>        $0 stop
>        sleep 1
>        $0 start
>        ;;
>  *)
>    echo "Usage: /etc/init.d/apd {start|stop|restart}"
>    exit 1
>    ;;
> esac
>
> exit 0


It looks fine to me. If it does what you want, great!

Thanks for showing me.

-Neal


Reply to: