I need help with Script running as a daemon !!!
Cwalinski, Zygmunt
zcwalinski at metroland.com
Tue Feb 6 00:20:13 UTC 2007
Dave,
Thanks for your email. I have set execute bit and change the script to:
name="runtest"
pidfile="/var/run/${name}.pid"
rcvar=`set_rcvar`
start_cmd=runtest_start
command="/etc/runtest"
command_interpreter=while
load_rc_config $name
runtest_enable=${runtest_enable-:NO}
runtest_start() {
$command &
echo $! > ${pidfile}
}
I get no error when I start this script but still when I am trying to
stop the daemon I am getting the following error:
runtest not running? (check /var/run/runtest.pid).
(pidfile contains a correct process ID)
Zyggi
-----Original Message-----
From: Brooks Davis [mailto:brooks at freebsd.org]
Sent: 05-02-2007 5:56 PM
To: Cwalinski, Zygmunt
Cc: freebsd-rc at freebsd.org
Subject: Re: I need help with Script running as a daemon !!!
On Mon, Feb 05, 2007 at 05:02:26PM -0500, Cwalinski, Zygmunt wrote:
> Hi,
> I am a new user to FreeBSD. All is new for me but I try to learn more
> and more everyday.
> I have to run a script as a daemon. Nice job for first time user :)
> Unfortunately I have to run more sophisticated daemon then this below
> but I can't even mange this simple daemon.
> Fortunately I have just found this mailing list and I hope I will get
> some help from you.
>
> I am trying to run the following script "runtest" as a daemon
> --------------------------------------------------------------
> while true
> do
> sleep 1
> done
>
> My daemon script:
> -----------------
> #!/bin/sh
> . /etc/rc.subr
> # PROVIDE: Test
> # REQUIRE: DAEMON
> # BEFORE: LOGIN
> # KEYWORD: My test
> name="runtest"
> pidfile="/var/run/${name}.pid"
> rcvar=`set_rcvar`
> start_postcmd=runtest_poststart
> command="sh /etc/runtest"
> command_args="&"
> command_interpreter=yes
> load_rc_config $name
> runtest_enable=${runtest_enable-:NO}
>
> runtest_poststart() {
> echo $! > ${pidfile}
> }
> run_rc_command "$1"
>
> When I start above daemon I get:
> ------------------------------------
> test# sh /usr/local/etc/rc.d/runtestd start
> eval: cannot open sh: No such file or directory
> [: !=: argument expected
> [: sh: unexpected operator
> Starting runtest.
>
> and runtest script is running.
>
> Then I try to stop it and I get the following information:
> ----------------------------------------------------------
> test# sh /usr/local/etc/rc.d/runtestd stop
> eval: cannot open sh: No such file or directory
> [: !=: argument expected
> runtest not running? (check /var/run/runtest.pid).
>
> runtest.pid does exists and there is correct process ID for my script
>
> What am I doing wrong?
> Please help me with it as I have spent few days already.
You need to write a runtest_start() that runs the command and immediatly
create the PID file. Note that for ${command} to work at all it must be
an absolute path to something with the execute bit set.
-- Brooks
More information about the freebsd-rc
mailing list