The /etc/init.d/ directory contains files that are used to start or stop a service at boot, such as the firewall, the HTTP deamon, or networking.
[root@server1 ~]# ls -l /etc/init.d/
-rwxr-xr-x. 1 root root 2989 Sep 16 2015 firewall
-rwxr-xr-x. 1 root root 6581 Sep 16 2015 httpd
-rwxr-xr-x. 1 root root 3581 Sep 16 2015 network
The contents of these files are a script that will do something at boot, such as running the httpd start command (to start the HTTPD web servers).
~]$ cat /etc/init.d/httpd
#! /bin/bash
/etc/bin/httpd start
For systems using init or sysvinit, when a system is initialized, such as during boot, the INIT deamon will first read the /etc/inittab file. In this example, the system is configured to use runlevel 5. This tells the system to start all deamons that are configured as on at runlevel 5. The /etc/inittab file can be edited to permanently change the default runlevel of the system.
id:5:default
The chkconfig command without any options or with the --list option can be used to view the runlevel of init or sysvinit services. For example, if the system is using runlevel 1, both netconsole and network will be off. However, if the system is using runlevel 5, netconsole will be off and network will be on.
[root@server1 ~]# chkconfig --list
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
The chkconfig service_name on or chkconfig service_name off commands can be used to turn a service on or off. This will turn the service on or off at every runlevel. For example, to turn the HTTPD service on or off.
[root@server1 ~]# chkconfig httpd on
[root@server1 ~]# chkconfig httpd off
To only change the runlevel status for certain runlevels, use the --level option.
[root@server1 ~]# chkconfig httpd on --level 345
When using the chkconfig command to change the runlevel of a service, a file in the /etc/init.d/ directory will be updated to contain the new runlevel. For example, the prior commands turns on the HTTPD deamon for runlevels 3, 4, and 5. This command updates the /etc/init.d/httpd file to contain the following. Even though this line is commented out, this still turns on the HTTPD deamon for runlevels 3, 4, and 5.
#!/bin/sh
. . .
# chkconfig: 345 95 05
For systems using systemd or upstart, the systemctl command can be used. If you created or updated a file in the /etc/init.d/ directory, let's first reload the system daemons.
systemctl daemon-reload
And then you probaby are going to want to enable or disable a service at boot.
[root@server1 ~]# systemctl enable service_name
[root@server1 ~]# systemctl disable service_name
The systemctl list-unit-files command can be used to view the status of services when using systemd.
[root@server1 ~]# systemctl list-unit-files
abrt-ccpp.service enabled
abrt-oops.service disabled
abrt-pstoreoops.service enabled
. . .
You can list a specific service.
~]# systemctl list-unit-files crond.service
UNIT FILE STATE PRESET
crond.service enabled enabled
1 unit files listed.
Did you find this article helpful?
If so, consider buying me a coffee over at