× NETGEAR will be terminating ReadyCLOUD service by July 1st, 2023. For more details click here.
Orbi WiFi 7 RBE973
Reply

How to startup custom services at boottime automatically

Plukkie
Aspirant

How to startup custom services at boottime automatically

Hi,

I just installed my first piece of code on the NV+, a streaming daemon "kissd". I wonder how I can get this service startup automatic at bootime on the Infrant?

I discovered there's only one startup script named "/etc/rc3.d/S99rc3" in runlevel 3.
What's the way to automatically startup custom daemons / services?

Regards,

Peter
Message 1 of 28
yoh-dah
Guide

Re: How to startup custom services at boottime automatically

Just create a /etc/rc3.d/Sxxkissd file and call it from there.
Message 2 of 28
Plukkie
Aspirant

Script /etc/rc3.d/Sxxkissd

Yoh-dah,

Can I duplicate some script from /etc/init.d/ and just change the variables for my daemon "kissd"?

gr Peter
Message 3 of 28
yoh-dah
Guide

Re: Script /etc/rc3.d/Sxxkissd

Plukkie wrote:
Yoh-dah,

Can I duplicate some script from /etc/init.d/ and just change the variables for my daemon "kissd"?

gr Peter

It wouldn't be just variables you'd be changing. You'd need to change the daemon name as well. You can test by running something like "./Sxxkissd start" and "./Sxxkissd stop".
Message 4 of 28
Plukkie
Aspirant

It works!

Hi Joh-Dah,

Created my custom script, it works.
Thank you. For the info of other Infrant users, hereby the scriptcontent:

nas01:~# ls -l /etc/rc3.d/
total 0
lrwxrwxrwx 1 root root 15 dec 1 23:18 S100kissd -> ../init.d/kissd
lrwxrwxrwx 1 root root 13 nov 26 15:25 S99rc3 -> ../init.d/rc3
nas01:~#
nas01:~# ls -l /etc/init.d/kissd
-rwxr-xr-x 1 root root 975 dec 3 10:58 /etc/init.d/kissd
nas01:~#
nas01:~# cat /etc/init.d/kissd
#! /bin/sh
#
# This file is created by Peter, the owner of this NAS.
#
# It starts the streaming daemon Kissd, which is used by Mediaplayers of Vendor KISS.
#
# Created 01 december 2007.

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
DAEMON=/usr/local/bin/kissd
CONFIG=/usr/local/etc/kissd.conf
PIDFILE=/var/run/kissd.pid

# Arguments to kissd
#
ARGS="-c $CONFIG -d"

test -x $DAEMON || exit 0
test -f $CONFIG || exit 0

case "$1" in
start)
echo -n "Starting Streaming Media Server: kissd"
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $ARGS
echo "."
;;
stop)
echo -n "Stopping Streaming Media Server: kissd"
start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON
echo "."
;;
reload)
echo "Not implemented."
;;
force-reload|restart)
sh $0 stop
sh $0 start
;;
*)
echo "Usage: /etc/init.d/kissd {start|stop|restart|force-reload|reload}"
exit 1
;;
esac

exit 0
nas01:~#
Message 5 of 28
Plukkie
Aspirant

Startscript not starting anymore automatically at boot

Hi Joh-Dah,

I upgraded my streaming daemon to a new version, modified the startscript as necessary, but auto startup at boottime does nog work.
When the machine finished booting and I start the script manually, it works. Stopping and restarting also works??

Do you know what can be wrong here?

Below the info:
=================================================
nas01:/# ls -l /etc/init.d/kissdx
-rwxr-xr-x 1 root root 1278 dec 6 18:18 /etc/init.d/kissdx
nas01:/#
nas01:/# ls -l /etc/rc3.d/
total 0
lrwxrwxrwx 1 root root 16 dec 6 18:15 S100kissdx -> ../init.d/kissdx
lrwxrwxrwx 1 root root 13 nov 26 15:25 S99rc3 -> ../init.d/rc3
nas01:/#
nas01:/# ls -l /usr/local/bin/kissdx
-rwxr-xr-x 1 root root 387881 dec 5 16:57 /usr/local/bin/kissdx
nas01:/#
nas01:/# ls -l /usr/local/etc/kissdx.conf
-rw-r--r-- 1 root 50 6686 dec 6 10:51 /usr/local/etc/kissdx.conf
nas01:/#
nas01:/# cat /etc/init.d/kissdx
#! /bin/sh
#
# This file is created by Peter, the owner of this NAS.
#
# It starts the streaming daemon Kissdx, which is used by Mediaplayers of Vendor KISS.
#
# Created 06 december 2007.

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
DAEMON=/usr/local/bin/kissdx
CONFIG=/usr/local/etc/kissdx.conf

# Arguments to kissdx
#
STARTARGS="-c $CONFIG -d"
STOPARGS="-s FORCESTOP"
GRACESTOP="-s STOP"
RELOAD="-s RELOAD_CONFIG"

test -x $DAEMON || exit 0
test -f $CONFIG || exit 0

case "$1" in
start)
echo -n "Starting Streaming Media Server: kissdx"
start-stop-daemon --start --quiet --exec $DAEMON -- $STARTARGS
echo "."
;;
stop)
echo -n "Stopping Streaming Media Server: kissdx"
start-stop-daemon --stop --quiet --exec $DAEMON -- $STOPARGS
echo "."
;;
gracestop)
echo -n "Stopping Streaming Media Server Gracefully: kissdx"
start-stop-daemon --stop --quiet --exec $DAEMON -- $GRACESTOP
echo "."
;;
reload)
echo -n "Reloading Configfile: kissdx"
start-stop-daemon --start --quiet --exec $DAEMON -- $RELOAD
echo "."
;;
force-reload|restart)
sh $0 stop
sh $0 start
;;
*)
echo "Usage: /etc/init.d/kissdx {start|stop|gracestop|restart|force-reload|reload}"
exit 1
;;
esac

exit 0
nas01:/#
================================================

thank you in advance.
Message 6 of 28
gknippels
Aspirant

Re: How to startup custom services at boottime automatically

Plukkie,

What I did to add (your) program to start up automatically at boot is:

create a small script called kissdx :

#!/bin/sh
/usr/sbin/kissdx -d -c /etc/kissdx.conf

store it in the directory /etc/init.d/

then call from that same directory

update-rc.d kissd defaults 20

This command will add it to the scripts for startup.
In case you would like to remove it simply type:

update-rc.d -f kissd remove

P.S. You also need to disable kissd (the old version you made available) because it uses the same port.

Let me know if you need further help. Thanks again for the nice programs.

Guido
Message 7 of 28
gknippels
Aspirant

sorry, made two typos

Plukkie,

Sorry I made two typos in the update-rc lines. I typed 'kissd' instead of 'kissdx'. So the correct lines should read

update-rc.d kissdx defaults 20

update-rc.d -f kissdx remove

Guido
Message 8 of 28
Plukkie
Aspirant

Re: How to startup custom services at boottime automatically

Guido,

It doesn't work for me. For the test I just created the simplest testscript you can imagine:

#! /bin/sh
/usr/local/bin/kissdx -c /ust/local/etc/kissdx.conf -d

I pushed it in /etc/init.d/ and created the startscripts with:

nas01:/etc/init.d# update-rc.d test defaults 60
Adding system startup for /etc/init.d/test ...
/etc/rc0.d/K60test -> ../init.d/test
/etc/rc1.d/K60test -> ../init.d/test
/etc/rc6.d/K60test -> ../init.d/test
/etc/rc2.d/S60test -> ../init.d/test
/etc/rc3.d/S60test -> ../init.d/test
/etc/rc4.d/S60test -> ../init.d/test
/etc/rc5.d/S60test -> ../init.d/test
nas01:/etc/init.d#


After the reboot, it isn't started.

I am thinking about the sequencing. There's only 1 startscript from Infrant in rc3.d, which is S99. This starts everything including networking probaby. Can it be, that kissdx refuses to start when networking isn't started yet?

But then again, I do not understand why it works at your Infrant?!
Message 9 of 28
gknippels
Aspirant

startup problems

Plukkie,

I don't know if it is important but I registered the scripts with:

update-rc.d kissdx defaults 20

I saw that you used 60. To be honest I don't know if it makes a difference.

Also, I would briefly verify that your script line
/usr/local/bin/kissdx -c /ust/local/etc/kissdx.conf -d
does indeed execute without any problems if you just type it at the prompt. Also, you are sure that the older kissd deamon isn't running anymore? If it is, it blocks the port that kissdx also want's to use.

That's all I can think of right now.

Good luck
Message 10 of 28
Plukkie
Aspirant

Netgear Moderators, please kick in.

Netgear,

Can you please explain, the way I want to start my daemon is correct?
Message 11 of 28
Skywalker
NETGEAR Expert

Re: How to startup custom services at boottime automatically

The best way is probably to treat it as an addon. You can simply add a line in /etc/frontview/addons/addons.conf for your program. Follow the syntax of the SlimServer and DAAP addons, which is:
SERVICE_NAME!!Friendly_Name!!Version!!Startup_command!!Stop_command

After that, add a line in /etc/default/services with
SERVICE_NAME=1
.

So, for example, your a kissd service, it might be something like this:
In /etc/frontview/addons/addons.conf
KISSD!!KISS Streaming Service!!0.1!!start-stop-daemon -S -q -b -x /usr/local/bin/kissdx -- -c /ust/local/etc/kissdx.conf -d!!start-stop-daemon -K -n kissdx

and in /etc/default/services
KISSD=1
Message 12 of 28
Plukkie
Aspirant

Re: How to startup custom services at boottime automatically

Skywalker,

Thank you very much. Finally it works via the frontview addon way.
Message 13 of 28
Plukkie
Aspirant

Python-based program won't start at boottime??

Hi,

I added a new custom application to the frontview addons, but this one will not start at boottime. It's a python-based program.

Any idea why it refuse to start at boottime?

nas01:~# more /etc/default/services | grep HELLA
HELLANZB=1
nas01:~#
nas01:~# more /etc/frontview/addons/addons.conf
HELLANZB!!Usenet Newsleecher!!0.13!!start-stop-daemon -S -b -q -x /usr/bin/hellanzb.py!!start-stop-daemon -K -n hellanzb.py

KISSDX!!Kiss Streaming Media Service!!0.14.0.b1!!start-stop-daemon -S -q -x /usr/local/bin/kissdx -- -d -c /usr/local/etc/kissdx.conf!!start
-stop-daemon -S -q -x /usr/local/bin/kissdx -- -s FORCESTOP
SLIMSERVER!!SlimServer!!6.5.4.1!!pidof -x slimserver.pl || start-stop-daemon -S -q -b -x /usr/share/slimserver/slimserver.pl -- --daemon --p
refsfile=/etc/slimserver.conf --cachedir=/var/cache/slimserver --logfile=/var/log/slimserver.log!!start-stop-daemon -K -n slimserver.pl
DAAPD!!FireFly!!1.0.0!!start-stop-daemon -S -q -x /usr/sbin/mt-daapd!!start-stop-daemon -K -n mt-daapd
nas01:~#
Message 14 of 28
chirpa
Luminary

Re: Python-based program won't start at boottime??

Plukkie wrote:
Any idea why it refuse to start at boottime?


What is the first line of /usr/bin/hellanzb.py ? (head -n1 /usr/bin/hellanzb.py)
Message 15 of 28
Plukkie
Aspirant

Re: Python-based program won't start at boottime??

chirpa wrote:
What is the first line of /usr/bin/hellanzb.py ? (head -n1 /usr/bin/hellanzb.py)

nas01:~# head -n1 /usr/bin/hellanzb.py
#!/usr/bin/python
nas01:~#
Message 16 of 28
Skywalker
NETGEAR Expert

Re: How to startup custom services at boottime automatically

Can you run the program manually? If so, you could try
start-stop-daemon -S -q -b -x /usr/bin/hellanzb.py -a /usr/bin/python -- /usr/bin/hellanzb.py
Message 17 of 28
Plukkie
Aspirant

Re: How to startup custom services at boottime automatically

Skywalker,

Your solution didn't work out. The program is working when I start it manually.
Message 18 of 28
Plukkie
Aspirant

Re: How to startup custom services at boottime automatically

Skywalker or Shirpa,

You guys have some tricks left out of the hat??
I'm still not able to get it started automatically.

gr Peter
Message 19 of 28
Skywalker
NETGEAR Expert

Re: How to startup custom services at boottime automatically

Does running "start-stop-daemon -S -q -b -x /usr/bin/hellanzb.py -a /usr/bin/python -- /usr/bin/hellanzb.py" manually start the service?
Message 20 of 28
chirpa
Luminary

Re: How to startup custom services at boottime automatically

Does hellanzb load any special python module files? Could be the environment variables for a path. They exist when you are logged in on the shell, but not on bootup to the init scripts.
Message 21 of 28
Plukkie
Aspirant

Re: How to startup custom services at boottime automatically

Skywalker wrote:
Does running "start-stop-daemon -S -q -b -x /usr/bin/hellanzb.py -a /usr/bin/python -- /usr/bin/hellanzb.py" manually start the service?

Yes indeed.

nas01:~# ps -ef | grep hellanzb | grep -v grep
nas01:~# start-stop-daemon -S -q -b -x /usr/bin/hellanzb.py -a /usr/bin/python -- /usr/bin/hellanzb.py
nas01:~# ps -ef | grep hellanzb | grep -v grep
root 7161 1 97 19:44 ? 00:00:04 /usr/bin/python /usr/bin/hellanzb.py
nas01:~#


NOTE:
When I immediately logon to the box during bootup, I noticed during a "ps -ef" the box definately is trying to run it, but for some reason it exists.
Message 22 of 28
Plukkie
Aspirant

Re: How to startup custom services at boottime automatically

derek wrote:
Does hellanzb load any special python module files? Could be the environment variables for a path. They exist when you are logged in on the shell, but not on bootup to the init scripts.


Hi Derek,
I'm not aware of it loads special modules (I'm not familiar with python), but here's the content of the hellanzb.py script:

nas01:~# cat /usr/bin/hellanzb.py
#!/usr/bin/python
"""

hellanzb - hella nzb

Command line interface to the Hellanzb library.

@see Hellanzb.Core.main()
@see Hellanzb.Core.parseArgs()

(c) Copyright 2005 Philip Jenvey, Ben Bangert
[See end of file]
"""
from Hellanzb.Core import main

__id__ = '$Id: hellanzb.py 665 2006-02-16 23:27:52Z pjenvey $'

if __name__ == '__main__':

main()

"""
Copyright (c) 2005 Philip Jenvey <pjenvey>
Ben Bangert <bbangert>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author or contributors may not be used to endorse or
promote products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

$Id: hellanzb.py 665 2006-02-16 23:27:52Z pjenvey $
"""
nas01:~#
Message 23 of 28
Plukkie
Aspirant

Re: How to startup custom services at boottime automatically

Plukkie wrote:
Skywalker wrote:
Does running "start-stop-daemon -S -q -b -x /usr/bin/hellanzb.py -a /usr/bin/python -- /usr/bin/hellanzb.py" manually start the service?

Yes indeed.

nas01:~# ps -ef | grep hellanzb | grep -v grep
nas01:~# start-stop-daemon -S -q -b -x /usr/bin/hellanzb.py -a /usr/bin/python -- /usr/bin/hellanzb.py
nas01:~# ps -ef | grep hellanzb | grep -v grep
root 7161 1 97 19:44 ? 00:00:04 /usr/bin/python /usr/bin/hellanzb.py
nas01:~#


NOTE:
When I immediately logon to the box during bootup, I noticed during a "ps -ef" the box definately is trying to run it, but for some reason it exists.

Skywalker,
You have a clue now why it fails at boottime?
Message 24 of 28
Skywalker
NETGEAR Expert

Re: How to startup custom services at boottime automatically

Plukkie wrote:
Skywalker,
You have a clue now why it fails at boottime?

No. It must need some environment variable or something that isn't yet available during boot time. You could try making a startup script for it, in /etc/rc3.d/S99zhellanzb. That would make it the last thing to attempt to start on the system.
Message 25 of 28
Top Contributors
Discussion stats
  • 27 replies
  • 7221 views
  • 0 kudos
  • 6 in conversation
Announcements