Thursday 26 May 2011

Disabling/enabling services in Ubuntu (UPDATED)

Recent versions of Ubuntu have changed the way that system services start up.  Presumably this reflects a policy change in Linux systems.
There are now THREE different ways for Linux services to start automatically at boot...
  1. New way: /etc/init/example.conf
    • If you find such a file, open it up in an editor and examine its startup conditions (beginning with "start on"). 
    • To prevent the service from starting, comment out the "start on" line (change "start on" to '#start on")
    Alternatively, I'm told that you can say:
    echo "manual" >/etc/init/example.conf.override
    but I haven't tried this yet. 

  2. Legacy way: /etc/init.d/example and /etc/rc5.d/S20example.
    To start a service using this traditional technique...
    • Place a shell script in /etc/init.d/example.
    • Create a symbolic link to /etc/init.d/example for each run level you want the service to auto-start in. For example:  ln -s /etc/init.d/example /etc/rc5.d/S20example would start the example service in Run Level 5.  
    • Symbolic links named something like /etc/rcN.d/K20example provide a way to stop a service cleanly when the machine changes run level (e.g. shuts down).
    • You may recall that run level 2 is single-user text-mode; 3 is multi-user text mode; 5 is multi-user GUI mode.
    • The numbers after 'S' or 'K' provide a crude way of tweaking service start-up order, so that for example you can make sure that a database service starts up before an SQL-based application server.
    • To stop a service starting in this way, you can just delete the symlinks i.e. rm /etc/rc*.d/S*example.

  3. Bastardized legacy way: /etc/init.d/example by itself.
    • Some services still use /etc/init.d/example but rather than relying on symlinks such as /etc/rc*.d/S*example, they use a new syntax for startup conditions, placed in comments near the top of
      /etc/init.d/example.

    • For example, the Mathopd web server is controlled solely from
      /etc/init.d/mathopd, which contains the text:

      ### BEGIN INIT INFO
      # Provides:          mathopd
      # Required-Start:    $local_fs $remote_fs $network $syslog
      # Required-Stop:     $local_fs $remote_fs $network $syslog
      # Default-Start:     2 3 4 5
      # Default-Stop:      0 1 6
      # Short-Description: Mathopd web server
      ### END INIT INFO

    • Just delete all of the lines (from BEGIN INIT INFO to END INIT INFO) and replace them with a single line containing the word exit and it will not restart after you reboot the box.
    After rebooting, run "netstat -tan | grep LISTEN" to make sure you know what's bound to your external network interfaces (i.e. anything other than 127.0.0.1 for IPv4, or ::1 for IPv6).

    If you see an IPv6 service listed like this:
         tcp6   0   0 :::51413     :::*        LISTEN 
    it simply means that the service is listening on all IPv6 interfaces, on port 51413.  It's the IPv6 equivalent of showing 0.0.0.0:51413.

    Further reading at http://overtag.dk/wordpress/2011/02/headaches-over-disablingenabling-services-init-d-scripts-in-ubuntu-10-10/ .   See also http://ubuntuforums.org/showthread.php?t=1519273 .

    No comments:

    Post a Comment

    Spammers: please stop wasting my time. All comments are moderated before publication.