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>
Marco Ceppi
  • 48,101
  • 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 '15 at 02:38

5 Answers5

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

Zanna
  • 70,465
  • 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 '10 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: http://manpages.ubuntu.com/manpages/hardy/man8/update-rc.d.8.html

    – maco Aug 14 '10 at 20:12
  • 5
    I'm accepting this answer because the updated man pages have removed that warning. http://manpages.ubuntu.com/manpages/lucid/man8/update-rc.d.8.html – Marco Ceppi Aug 15 '10 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 '10 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 '15 at 02:40
  • Current man page of update-rc.d: " Older versions of update-rc.d also supported start and stop options. These options are no longer supported, and are now equivalent to the defaults option." – EoghanM Sep 15 '15 at 15:46
  • The link is dead :( – Ann Kilzer Apr 17 '18 at 05:19
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
Marco Ceppi
  • 48,101
jokerulez
  • 551
10

Try this:

apt-get install chkconfig

This works, at least of as Ubuntu 12.04 release.

Eliah Kagan
  • 117,780
  • 7
    Doesn't work on 12.10 – expert Feb 22 '13 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? – John Little Mar 17 '14 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 '15 at 03:03
  • 2
    No package on Ubuntu 14.04. Do we need to add another source? – Hashid Hameed Sep 02 '15 at 06:02
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.

maco
  • 15,892
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.