Sunday, April 17, 2005

Redhat/ Fedora linux set services automatically start

e.g. to set nfs to start automatically:

[root@www2 rc3.d]# chkconfig --list nfs
nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@www2 rc3.d]# chkconfig nfs on
[root@www2 rc3.d]# chkconfig --list nfs
nfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off


alternatively, e.g. for mysql:

# To make the script be run on machine start up we need to create a symbolic link to it.

cd /etc/rc.d/rc3.d
ln -s ../init.d/mysql S85mysql
cd /etc/rc.d/rc5.d
ln -s ../init.d/mysql S85mysql

# Now the links to make MySQL shut down:

cd /etc/rc.d/rc0.d
ln -s ../init.d/mysql K85mysql
cd /etc/rc.d/rc6.d
ln -s ../init.d/mysql K85mysql


Runlevel Links

Some services depend on other services. The 'httpd' service (Apache web server) for example won't start correctly if the 'network' script hasn't already set up the network interfaces. How is the order in which services are started on boot determined?

Have a look at the '/etc/rc.d' directory:

$ ls /etc/rc.d

init.d/ rc0.d/ rc2.d/ rc4.d/ rc6.d/ rc.local* rc.sysinit*
rc* rc1.d/ rc3.d/ rc5.d/ rc.firewall rc.modules*

You see the 'init.d' from '/etc' here again (in fact it's the same) and then several directories and files starting with 'rc' ('rc' is short for 'runcom[mand]').
In Mandrake Linux releases 8.0 and later, these files and directories are also accessible directly from the '/etc' directory.

If you now look into one of those 'rcnumber' subdirectories, you will find a bunch of files, some of them starting with 'S' and some of them with 'K' followed by a two-digit number. 'S' is short for 'start' and 'K' stands for 'kill'. The numbers imply the order in which starting and killing services takes place. In fact all those files are just links to their appropriate counterparts in '/etc/init.d'.
'S12syslog' for example is a link to '/etc/init.d/syslog' and gets started after 'S10network' which links to '/etc/init.d/internet' but before 'S20random'.



Also for mysql:


shell> cp mysql.server /etc/init.d/mysql
shell> chmod +x /etc/init.d/mysql

Older Red Hat systems use the `/etc/rc.d/init.d' directory rather than `/etc/init.d'. Adjust the preceding commands accordingly. Alternatively, first create `/etc/init.d' as a symbolic link that points to `/etc/rc.d/init.d':

shell> cd /etc
shell> ln -s rc.d/init.d .

After installing the script, the commands needed to activate it to run at system startup depend on your operating system. On Linux, you can use chkconfig:

shell> chkconfig --add mysql

On some Linux systems, the following command also seems to be necessary to fully enable the mysql script:

shell> chkconfig --level 345 mysql on

On FreeBSD, startup scripts generally should go in `/usr/local/etc/rc.d/'. The rc(8) manual page states that scripts in this directory are executed only if their basename matches the *.sh shell filename pattern. Any other files or directories present within the directory are silently ignored. In other words, on FreeBSD, you should install the `mysql.server' script as `/usr/local/etc/rc.d/mysql.server.sh' to enable automatic startup.

As an alternative to the preceding setup, some operating systems also use `/etc/rc.local' or `/etc/init.d/boot.local' to start additional services on startup. To start up MySQL using this method, you could append a command like the one following to the appropriate startup file:

/bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'
Post a Comment