Ubuntu, control the init startup

3

2

Ubuntu uses upstart instead of sysvinit. However there are still runlevels and the links in them.

I have installed tor and it has added itself to the startup of the OS. Now I want to remove it and the popular options are to remove the links of starting and stopping the service from runlevels or make the /etc/init.d/ script non-executable. This is fine but this will be problematic in case I want to put tor again on the startup list. How would I know to put the proper sequences in the proper runlevel directories.

Is there any complete guide given? What are the rules for this? Any tools to manage the init?

Please tell

Xolve

Posted 2010-06-11T06:13:19.513

Reputation: 450

Why not just remove tor itself? – Bobby – 2010-06-11T11:31:32.723

Answers

8

SysVinit works like this. Initialization scripts for each package are located in /etc/init.d. Links to those scripts are located in /etc/rcS.d and /etc/rc[0-6].d. These links start with either S (start) or K (kill) and a 2-digit number.

  • When the system boots and the SysVinit process starts, it looks in /etc/rcS.d and executes scripts starting with S, ordered by the number. (I believe it passes the "start" argument to the scripts, but I'm not sure.)

  • After all /etc/rcS.d scripts are processed, the system begins moving into a certain runlevel. In Ubuntu, booting to the normal desktop, the default runlevel is 2. So SysVinit looks in /etc/rc2.d and

    1. stops all services with links starting with K, ordered by the number; and
    2. starts all services with links starting with S, ordered by the number.

    If you've booted into Ubuntu's recovery mode instead, you'll be booting into runlevel 1. After all services are started, the system runlevel is officially set.

  • Finally, the system runs the /etc/rc.local script.

If you switch runlevels later, SysVinit runs the same basic process: it doesn't check /etc/rcS.d, but goes straight to processing the links in /etc/rcN.d (where N is whatever runlevel is being entered).


You could also write an Upstart script. I've written about Upstart previously, so check there for more details. Upstart scripts are kept in /etc/init; to write them, look over existing scripts to get a feel for how it works, and read the init(5) manpage.

quack quixote

Posted 2010-06-11T06:13:19.513

Reputation: 37 382

1

I know only update-rc.d as a tool. The manual page gives a good explanation how to use it and it's not too hard to learn.


Thanks to Quack who told me about chkconfig. Check his post here.

Apache

Posted 2010-06-11T06:13:19.513

Reputation: 14 755

this is the "right tool" for manipulating the /etc/rc*.d links automatically. – quack quixote – 2010-06-11T08:35:18.833

see my answer here for a quick how-to-use-update-rc.d primer.

– quack quixote – 2010-06-11T08:46:43.087

Oh why don't you just edit my answer? Feel free to improve it if you can (or write a new one if its totally fubar.. :)) – Apache – 2010-06-11T08:58:38.133

because to expand on your how-to-use-update-rc.d answer i'd be cutting-n-pasting from the answer i linked to. which is why i posted a comment link. (i was writing up a separate tack and ran across that link.) – quack quixote – 2010-06-11T09:00:55.570

Oh okay... see your answer now. Deleting mine soon I guess. :) – Apache – 2010-06-11T09:06:42.813

0

Here is the update-rc.d man page. Basically, removing the rc.d links won't work as they will be restored on upgrade. The correct way is:

sudo update-rc.d tor disable

Which renames S (start) links in /etc/rc?.d to K (stop) links. This would also work:

sudo rename 's:/S:/K:g' /etc/rc?.d/S*tor

Tobu

Posted 2010-06-11T06:13:19.513

Reputation: 2 584