Automating Services
Make services run automatically on boot (FreeBSD 5.2)
Posted 12.06.2003 | Updated 23.05.2006 | Contributed by Andy Mallett


Sometimes it is required that certain services start from boot.

For instance if the WWW service is running and the server gets rebooted, the box will restart the web service automatically.

One common method is to put an entry into /etc/rc.conf. Entries in this file will make the required services (daemons) run on demand at bootup.

For instance, adding the line inetd_enable="YES" will initialise inetd - the Unix 'internet Super Server'.

As a result, certain services can be run from inet.d such as Apache.

Here's an example rc.conf file..

hostname="GOTH1.IT.NET"
ifconfig_fxp0="DHCP"
saver="daemon"
sshd_enable="YES"
usbd_enable="YES"
inetd_enable="YES"


Here's an example from an inetd.conf file (ftpd enabled)..

# To disable a service, comment it out by prefixing the line with '#'.
# To enable a service, remove the '#' at the beginning of the line.
#
ftp stream tcp nowait root /usr/libexec/ftpd ftpd -l
#ftp stream tcp6 nowait root /usr/libexec/ftpd ftpd -l
#ssh stream tcp nowait root /usr/sbin/sshd sshd -i -4
#ssh stream tcp6 nowait root /usr/sbin/sshd sshd -i -6
#telnet stream tcp nowait root /usr/libexec/telnetd telnetd
#telnet stream tcp6 nowait root /usr/libexec/telnetd telnetd
#shell stream tcp nowait root /usr/libexec/rshd rshd
#shell stream tcp6 nowait root /usr/libexec/rshd rshd


Note that if a service is started from inet.d then it won't show up is a ps command; as inet.d is running things, only inet.d shows up.

There are exceptions to this method. The problem with starting, for instance, Apache from rc.conf is that the service will not run continuously. The file rc.conf only activates Apache when a page request is received. After that the Apache service stops until the next page request. This can make accessing the web server somewhat sluggish, waiting for the service to start before delivering content.

An alternative is to use the olde methode known as rc.local..

Create the file, vi  /etc/rc.local - here's an example..

/usr/local/apache2/bin/apachectl  start
/usr/local/sbin/smbd  start
/usr/local/sbin/nmbd  start


Good old rc.local works like autoexec.bat in DOS, if you like. If it exists in /etc the system will run it. Make sure to include the full path to any executables. Anything initiated from this file will run continuously - check with ps  -aux.