Short note on how to manage system services using CentOS.

Startup configuration

To list all services and their status at boot on each runlevel execute command:

# chkconfig --list
abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrt-oops       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrtd           0:off   1:off   2:off   3:on    4:off   5:on    6:off
acpid           0:off   1:off   2:on    3:on    4:on    5:on    6:off
atd             0:off   1:off   2:off   3:on    4:on    5:on    6:off
auditd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[...]
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
sssd            0:off   1:off   2:off   3:off   4:off   5:off   6:off
sysstat         0:off   1:on    2:on    3:on    4:on    5:on    6:off
udev-post       0:off   1:on    2:on    3:on    4:on    5:on    6:off
ypbind          0:off   1:off   2:off   3:off   4:off   5:off   6:off

To list all services enabled at boot on specified runlevel (runlevel 3 in this example) execute command:

# chkconfig --list | grep 3:on
abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrt-oops       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrtd           0:off   1:off   2:off   3:on    4:off   5:on    6:off
acpid           0:off   1:off   2:on    3:on    4:on    5:on    6:off
atd             0:off   1:off   2:off   3:on    4:on    5:on    6:off
auditd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[...]
rpcidmapd       0:off   1:off   2:off   3:on    4:on    5:on    6:off
rsyslog         0:off   1:off   2:on    3:on    4:on    5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
sysstat         0:off   1:on    2:on    3:on    4:on    5:on    6:off
udev-post       0:off   1:on    2:on    3:on    4:on    5:on    6:off

To disable service at boot (ntpd in this example) execute command:

# chkconfig ntpd off

To disable service at boot (cups at runlevel 3 in this example) execute command:

# chkconfig --level 3 cups off

To enable service at boot (sshd in this example) execute command:

# chkconfig sshd on

To enable service at boot (sshd at runlevel 3 in this example):

# chkconfig --level 3 sshd on

Current service status

To list all services and their current status execute command:

# service --status-all
abrtd (pid  1488) is running...
abrt-dump-oops (pid 1496) is running...
acpid (pid  1300) is running...
atd (pid  1551) is running...
auditd (pid  1594) is running...
[...]
slapd is stopped
smartd is stopped
openssh-daemon (pid  1388) is running...
sssd is stopped
ypbind is stopped

To check current status of specified service (sshd in this example):

# service sshd status
openssh-daemon (pid  1415) is running...

To stop service (cups in this example) execute command:

# service cups stop
Stopping cups:                                             [  OK  ]

To restart service (postfix in this example) execute command:

# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]

To perform full restart – execute stop command then start command (cups in this example) run:

# service cups --full-restart
Stopping cups:                                             [  OK  ]
Starting cups:                                             [  OK  ]

Creating a custom service

Look at scripts located in /etc/init.d/ directory and read couple of them to learn how it works.

For more detailed information, see Writing System V init scripts for Red Hat Linux.

Copy existing ntpd script (it is used only as example) to newservice:

# cp /etc/init.d/ntpd /etc/init.d/newservice

Change newservice script according to your needs:

# vi /etc/init.d/newservice

Add execute permission to the script:

# chmod +x /etc/init.d/newservice

Add new service:

# chkconfig --add newservice

Check service status at boot:

# chkconfig --list newservice
newservice      0:off   1:off   2:off   3:on    4:on    5:on    6:off

Remove example service newservice:

# chkconfig --del newservice