Managing Linux Services

Linux services or daemons are used to automatically start software that provide services such as web servers, database servers, FTP, SSH, Samba. This article is about how to manage linux services and to set them to start automatically. Note that Linux distributions are based on System V which have run levels for system services (as opposed to BSD).

Note that the information provided here does vary between linux distributions. I’m using specific examples from CentOS (and therefore RedHat) linux distributions.

Manging Services

Services that will run can be found in /etc/init.d/.

For any one of these services, you can use the service to manage a service. For example, Samba is managed by the service smb. Use the command:

$ service smb status

This will tell you the status of the daemon programs associated with Samba (e.g. smbd and nmbd). To start or stop them you can issue commands like:

$ service smb start
$ service smb stop
$ service smb restart

Making Services Start Automatically

You can use chkconfig to add a service to a specified run level to make it start automatically.

Linux distributions have 6 run levels and these vary slightly between distributions. In CentOS and RedHat they are:

  • 1 – Single user mode
  • 2 – Multiuser, without NFS (The same as 3, if you do not have networking)
  • 3 – Full multiuser mode
  • 4 – unused
  • 5 – X11
  • 6 – reboot (Do NOT set initdefault to this)

A run level basically tells you what the mode the system is in. To find out what runlevel you are in:

$ runlevel

You can look at /etc/inittab to see how the system is configured to run processes at different run levels. This file maps the association between a run level (e.g. 3) and the services started in that run level which are typically stored in /etc/rc.d under the appropriate run level directory (e.g. /etc/rc.d/rc3.d/).

To make a service such as Samba smb start automatically, you need to add it to appropriate run levels (e.g. 3,4,5) using chkconfig:

$ chkconfig —level 345 smb on

You can then use chkconfig to see what run levels your service will be started at:

$ chkconfig —list smb

Which gives a result like this:

smb 0:off 1:off 2:off 3:on 4:on 5:on 6:off

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress with modified GimpStyle Theme originally designed by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.