1

I find the concept of runlevels very confusing. Currently, I'm trying to run a script only at start up. But configuring as shown below leads to it working also at halt time.

I'm programming a daemon this way:

update.rc-d script.sh defaults 100

Also I have tried

update-rc-d script.sh start 100

But that does not work either.

1

2 Answers 2

3

Runlevels are logical groups of tasks. Traditionally you have five run levels.

0 boot
1 single user 
2 not used
3 multiuser
4 not used 
5 gui
6 reboot 

Each runlevel defines a more or less static set of tasks to run. Runlevel 1, may not have networking while runlevel 3 may not have the GUI login screen. A system goes through all lower runlevels before it reaches the default runlevel. For a typical Ubuntu box, the traditional runlevel is 5: GUI, while other distros such as Debian or Gentoo may come configured to run 3: multiuser as the default runlevel.

In recent versions of ubuntu, this model has changed somewhat because the previous way of starting the system did not allow for multiple services (programs) to run in parallel. Without doubt, there were other reasons as well.


If I understand your objective correctly, you need to run a single command. You can do that by putting it along with any other commands you might have in the /etc/rc.local file:

$ chmod 755 /etc/rc.local 

The Init system will not run this file without execution bits

$ cat /etc/rc.local
#!/bin/sh -e
# This script is executed at the end of each multiuser runlevel.

loadkeys  /root/jolemak.iso15.kmap
exit 0

Any multiuser runlevel means any runlevel above 3. In this example, a single command is run to load an alternative keyboard layout for the virtual consoles. It serves as a quick way to fix the layout before I figure out how to properly install and configure additional layouts.


If you need to do more advanced stuff, either write a traditional /etc/init.d/foo script or a new upstart (Ubuntu-specific) /etc/init/moo.conf. Study the examples in that folder and read the wiki for more info.

https://help.ubuntu.com/community/UbuntuBootupHowto
http://upstart.ubuntu.com/getting-started.html
http://upstart.ubuntu.com/cookbook/

Your question is also answered here: http://upstart.ubuntu.com/cookbook/#single-job and here http://www.debuntu.org/how-to-managing-services-with-update-rc-d/

0

http://www.netbsd.org/docs/guide/en/chap-rc.html#chap-rc-scripts documents how your script should work. Your script is going to be run at startup AND at shutdown AND any time a user runs "service yourscriptname". You need to tell your script to check its first and only parameter. If that parameter is "start" then start your service or do whatever else your script does. If that parameter is "stop" then stop your service or do nothing. How you handle "restart" and "status" is up to you. Right now your script is ignoring that parameter, so when "script.sh start" gets called on startup all is well, but when "script.sh stop" gets called on halt the whole thing runs again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .