Adding services to auto start after reboot in linux

In this blog, you will come to know the process of Adding services to auto start after reboot in Linux.

The chkconfig utility is a command-line tool that allows you to specify in which runlevel to start a selected service, as well as to list all available services along with their current setting. Note that with the exception of listing, you must have superuser privileges to use this cAdding services to auto start after reboot in linuxommand.

chkconfig – Updates and queries runlevel information for system services.

SYNOPSIS

       chkconfig [–list] [–type type][name]
       chkconfig –add name
       chkconfig –del name
       chkconfig –override name
       chkconfig [–level levels] [–type type] name <on|off|reset|resetpriorities>
       chkconfig [–level levels] [–type type] name
To display the current settings for a selected service only, use chkconfig –list followed by the name of the service:
# chkconfig --list service_name

The chkconfig command can also be used to activate and deactivate services. The chkconfig –list command displays a list of system services and whether they are started (on) or stopped (off) in runlevels 0-6. At the end of the list is a section for the services managed by xinetd.

To list all startup services in alphabetic order.
$ chkconfig --list | sort | less
auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
...

Check the mysqld,zabbix-agent and httpd service is auto-started in below mention runlevel: 

[root@node1 sshinde]# chkconfig --list 
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
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
mysqld          0:off   1:off   2:on    3:on    4:off   5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
zabbix-agent    0:off   1:off   2:off   3:off   4:off   5:off   6:off
...
Adding mysqld, zabbix-agent, httpd to chkconfig.
[root@node1 sshinde]# chkconfig --level 235 zabbix-agent on
[root@node1 sshinde]# chkconfig --level 235 httpd on
[root@node1 sshinde]# chkconfig --level 235 mysqld on 

[root@node1 sshinde]# chkconfig --list
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
httpd           0:off   1:off   2:on    3:on    4:off   5:on    6:off
mysqld          0:off   1:off   2:on    3:on    4:off   5:on    6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
zabbix-agent    0:off   1:off   2:on    3:on    4:off   5:on    6:off
...
[root@node1 sshinde]#

To Disable any run-level use the off parameter.

[root@node1 sshinde]# chkconfig --level 2 mysqld off   
//In run-level 2 (init 2) mysqld service will not auto start
To remove service from the startup list, use the –del option as shown below.
# chkconfig --del httpd
# chkconfig --list | grep httpd //verify the settings
Script Files under rc.d Subdirectories:
  • Whenever you add or remove a service from chkconfig control, it does the following under the /etc/rc.d sub-directories.
  • When chkconfig –add command is executed, it creates a symbolic link file to start and stop the service under corresponding rc directory.
  • When chkconfig –del command is executed, it removes the symbolic link file from the corresponding rc directory.

End of the tutorial, Adding services to auto start after reboot in Linux.

Thanks for reading this article, you’ll also like:

Checklist for Pre and Post Linux Reboot

How to install Nginx in RHEL and CentOS

How to Setup Alerting System for Graphite Metrics

How to execute script or command on reboot or startup in Linux