Friday, April 26, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 3153  / 3 Years ago, sat, june 12, 2021, 11:48:53

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.


More From » services

 Answers
2

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/


[#30235] Sunday, June 13, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ovierman

Total Points: 445
Total Questions: 108
Total Answers: 111

Location: Libya
Member since Fri, Oct 30, 2020
4 Years ago
;