Back to main page

The QND Guide to Starting Programs at Boot

Many programs, such as CUPS, samba, Canna and the like are programs that you wish to start running when the machine boots. Most operating systems have their own way of doing this. This QND guide covers how to do it in various Linux distributions, as well as FreeBSD and NetBSD.

In a pinch, one can always add a line to their /etc/rc.d/rc.local file (sometimes /usr/local/etc/rc.d, and sometimes /etc/rc.local) giving the full path to the program. For instance, if you install cannaserver from the vanilla version we provide, (see the QND Guide to Using Japanese in *nix) you could simply add the following line to ArchLinux's /etc/rc.local

/usr/sbin/cannaserver

However, as most distributions provide a way to more gracefully do this, it is worth learning.

RedHat

RedHat (and we are including Fedora in this) has a simple ncurses program called ntsysv. If you type
ntsysv

at a command prompt, a dialog comes up with various services. Hitting the space bar while a particular service is hightlighted will add or remove an asterisk from it, determining whether or not it should be started at boot.

They also have a little program called chkconfig. The syntax is as follows, using sendmail as an example

chkconfig --level 35 sendmail on

To stop it from running at startup simply change the on to off. The level part of the command refers to run levels--in RH level 3 is multiuser non-graphic and level 5 is graphic.

Slackware

Slackware has an /etc/rc.d/rc.M file. A sample from it goes
if [ -x /etc/rc.d/rc.sendmail]; then
. /etc/rc.d/rc.sendmail start
fi

So, one can add a program to this. Again, going back to our cannaserver program, one can simply add the lines

if [ -x /usr/sbin/cannaserver]; then
. /usr/sbin/cannaserver
fi

If one looks at the file, they can see other examples. There are other ways to do it, including echoing "Starting the cannaserver" before starting it, etc.

Gentoo

When a package is emerged in Gentoo, one can usually simply add it with the rc-update command. Canna is one of those that can be added. In this case
rc-update add canna default

ArchLinux

ArchLinux has an /etc/rc.conf file. In there is the line

DAEMONS=(!pcmcia network crond inetd)

One simply adds the daemons they want run at boot to that line. For example, if you want the sshd daemon to run at boot, change that line to read

DAEMONS=(!pcmcia network crond inetd sshd)

(Note that putting ! in front a daemon's name disables it--for example, in the default the pcmcia daemon is prefixed with a !, meaning it will not start at boot).

FreeBSD

FreeBSD puts most programs that don't come with the base system into either /usr/local/bin or /usr/X11R6/bin. In almost all cases, a FreeBSD port also installs a script in /usr/local/etc/rc.d. One will usually, after installing canna for example, find that a little shell script starting the daemon is in /usr/local/etc/rc.d. Continuing with our canna example, one finds that as long as it was installed from ports, there is a script in there called canna.sh.sample. If you wish canna to run at boot, simply remove the "sample" from it.
cd /usr/local/etc/rc.d
mv canna.sh.sample canna.sh

Recently, many of the /usr/local/etc/rc.d script will have commented instructions that one should add a line to /etc/rc.conf. For example, with samba, one adds

samba_enable="YES"

so one should take a quick look at the .sh script to see if this is necessary.

If you wish to make a custom startup script, /usr/local/etc/rc.d/ is the best place to put it. It must have the .sh ending. For example, if the program is called foo, the script would be called foo.sh The man rc(8) page gives some examples. In its simplest form it would read something like
#!/bin/sh

case $1 in

start)
        /usr/local/sbin/foo 
        ;;

stop)
        killall foo
        ;;

esac

NetBSD

NetBSD is quite similar to FreeBSD in this respect, however the startup script is usually found in
/usr/pkg/local/rc.d

It is hoped the above will enable you to get a program to run at boot without problems.

Back to main page