150

I've become very accustomed to managing service startups on Redhat/RHEL platforms using chkconfig though that doesn't appear to be the Debian/Ubuntu way - How do I update runlevel information for system services on Ubuntu?

Ultimately looking for the equivalents of:

chkconfig --add <service>
chkconfig --level 345 <service> on
chkconfig --del <service>
1
  • 1
    BTW: you can apt-get install chkconfig the package on ubuntu as well. However it is broken since years, the following symlink will make it (somewhat) work: ln -s /usr/lib/insserv/insserv /sbin/insserv
    – eckes
    Feb 10, 2015 at 2:38

5 Answers 5

129

The equivalent to chkconfig is update-rc.d

The equivalents you seek are

update-rc.d <service> defaults
update-rc.d <service> start 20 3 4 5
update-rc.d -f <service>  remove

See this useful page for more information or check out man update-rc.d

7
  • 6
    update-rc.d is only meant to be used in packaging scripts, not by humans. It also is for init scripts, which Ubuntu doesn't use. Ubuntu uses Upstart.
    – maco
    Aug 14, 2010 at 17:22
  • 11
    "Please note that this program was designed for use in package maintainer scripts and, accordingly, has only the very limited functionality required by such scripts. System administrators are not encouraged to use update-rc.d to manage runlevels. They should edit the links directly or use runlevel editors such as sysv-rc-conf and bum instead." From the manpage: manpages.ubuntu.com/manpages/hardy/man8/update-rc.d.8.html
    – maco
    Aug 14, 2010 at 20:12
  • 5
    I'm accepting this answer because the updated man pages have removed that warning. manpages.ubuntu.com/manpages/lucid/man8/update-rc.d.8.html Aug 15, 2010 at 19:16
  • 4
    Which still doesn't change the fact that Ubuntu doesn't even use SysV init scripts nowadays and update-rc.d is only for them.
    – maco
    Aug 15, 2010 at 23:49
  • 1
    There are still some sysv scripts used and especially they do work with upstart as well. So if you did not had the time to convert a script you might still use it this way.
    – eckes
    Feb 10, 2015 at 2:40
55

Best alternative IMHO is sysv-rc-conf To install just need to run the command:

sudo apt-get install sysv-rc-conf

Once installed run the command:

sudo sysv-rc-conf

You can check or uncheck the options to start a service on any level of execution and may even stop or start the services from this console. It is an indispensable tool to enable or disable applications on an permanently way to boot your ubuntu If you need a quick change, then you can use the CLI interface:

For example to stop ssh at levels 3 and 5 of execution:

sysv-rc-conf-off level 35 ssh

Atd to start in runlevels 2,3,4 and 5:

sysv-rc-conf on atd

If you want to know more:

man sysv-rc-conf
6
  • This is exactly what I needed, except I did sysv-rc-conf apache2 on / sysv-rc-conf apache2 off etc. Jan 15, 2014 at 14:47
  • This works for me compared update-rc.d which was looking for program scripts in /etc/init.d/ directory where some programs like vsftpd are not installed. Oct 29, 2014 at 7:58
  • Worked for me on Ubuntu 14.04 Sep 2, 2015 at 6:02
  • You have typo: sysv-rc-conf-off level 35 ssh should be sysv-rc-conf --level 35 ssh off Jan 14, 2016 at 14:26
  • 1
    E: Unable to locate package sysv-rc-conf on Ubuntu 18.04 for sudo apt-get install sysv-rc-conf
    – lreeder
    Sep 1, 2020 at 2:42
10

Right now, there is no equivalent on a stable release for doing things with Upstart scripts. Jacob Peddicord wrote jobservice (backend daemon) and jobs-admin (GTK+ GUI that talks to it) for his Google Summer of Code project. Lucid packages are in his PPA. They also exist in Universe in Maverick. There is no command line front-end for jobservice yet, just jobs-admin.

10

Try this:

apt-get install chkconfig

This works, at least of as Ubuntu 12.04 release.

4
  • 7
    Doesn't work on 12.10
    – expert
    Feb 22, 2013 at 20:56
  • 1
    have 12.04, and apt-get install chkconfig gives: "E: Package 'chkconfig' has no installation candidate". Whats in your /etc/apt/sources.list file? Mar 17, 2014 at 10:22
  • Looks like the latest was published for precise: 12.04: 1.0-79.1-2 0 in http://us.archive.ubuntu.com/ubuntu/ precise/universe i386 Packages. Some fixes never made it into a package.
    – eckes
    Feb 10, 2015 at 3:03
  • 2
    No package on Ubuntu 14.04. Do we need to add another source? Sep 2, 2015 at 6:02
6

Lets walk from ZERO to Goal - how to do it with step by step.

Step 1: lets write a hello world

cat >> /var/tmp/python/server.py <<\EOF
#/usr/bin/python
import time
while True:
  print "hello> YES Bello"
  time.sleep(30)

EOF

Step 2: lets make our hello world application server.py automated

cat >> /var/tmp/myserver.sh <<\EOF
#!/bin/sh
script='/var/tmp/python/server.py'
export DISPLAY=:0.0 && /usr/bin/python $script &

EOF
chmod +x /var/tmp/myserver.sh

cat >> /etc/init.d/myserver <<\EOF

#! /bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/var/tmp/myserver.sh
PIDFILE=/var/run/myserver.pid

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

case "$1" in
  start)
     log_daemon_msg "Starting feedparser"
     start_daemon -p $PIDFILE $DAEMON
     log_end_msg $?
   ;;
  stop)
     log_daemon_msg "Stopping feedparser"
     killproc -p $PIDFILE $DAEMON
     PID=`ps x |grep server.py | head -1 | awk '{print $1}'`
     kill -9 $PID       
     log_end_msg $?
   ;;
  force-reload|restart)
     $0 stop
     $0 start
   ;;
  status)
     status_of_proc -p $PIDFILE $DAEMON atd && exit 0 || exit $?
   ;;
 *)
   echo "Usage: /etc/init.d/atd {start|stop|restart|force-reload|status}"
   exit 1
  ;;
esac

exit 0


EOF
chmod +x /etc/init.d/myserver
chmod -R 777 /etc/init.d/myserver

Step 3:

$ update-rc.d myserver defaults
update-rc.d: warning: /etc/init.d/myserver missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Adding system startup for /etc/init.d/myserver ...
   /etc/rc0.d/K20myserver -> ../init.d/myserver
   /etc/rc1.d/K20myserver -> ../init.d/myserver
   /etc/rc6.d/K20myserver -> ../init.d/myserver
   /etc/rc2.d/S20myserver -> ../init.d/myserver
   /etc/rc3.d/S20myserver -> ../init.d/myserver
   /etc/rc4.d/S20myserver -> ../init.d/myserver
   /etc/rc5.d/S20myserver -> ../init.d/myserver
  • So in step 3, the system on boot, will automatically execute the server.py as daemon and make it easy to automate

Hope it helped.

1
  • 3
    +1: Very useful answer but I think it has the wrong question attached to it.
    – Clarus
    Feb 27, 2014 at 17:53

You must log in to answer this question.

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