linux distro - How to Auto-start Services on Boot in Linux?

How to Auto-start Services on Boot in Linux?

Geek Flare Blog post is sponsored by Netsparker Web Application Security Scanner.

One of the essential for a system administrator to know is how to configure service at boot, so when a server gets a reboot, they start automatically.

There could be various reasons for server reboot, including the following.

  • Scheduled for weekly, monthly
  • Unexpected due to hardware/kernel issue

By doing the right configuration, you don’t have to start them manually each time you reboot.

A little bit of automation. Isn’t it?

The following examples are two popular distros tested on DigitalOcean servers.

CentOS or RHEL 6.x

The following example I have taken as Apache HTTP server, but procedure remain same for any other services you wish to start at boot in Red Hat Enterprise Linux (RHEL) or CentOS 6 version.

You can keep any script file name, and here I’ve kept httpd

  • Become as root user on your Linux server
  • Create or copy your script under /etc/init.d/
[[email protected] init.d]# ls -ltr httpd
-rwxr-xr-x. 1 root root 3371 Jan 6 08:56 httpd
[[email protected] init.d]#

We will use chkconfig utility which is available default on Linux or CentOS.

  • Add script to start on boot using chkconfig with --add parameter
[[email protected] init.d]# chkconfig --add httpd
[[email protected] init.d]# chkconfig httpd on
  • Confirm script is added successfully with --list
[[email protected] init.d]# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[[email protected] init.d]#

That’s all! httpd script will be called to start services on Linux boot.

In case you need to disable auto-start service then you can use the following commands

chkconfig httpd off
chkconfig --del httpd

RHEL or CentOS 7.x

Procedure to configure services on boot in RHEL 7 is slightly different than RHEL 6. It uses systemd to manage the services.

Most of the software like Apache, PHP, MySQL, Nginx scripts are added in services when you install it.

Let’s take an example of PHP-FPM.

First thing first, let’s see the status of php-fpm

[[email protected] ~]# systemctl status php-fpm
php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: inactive (dead) 
[[email protected] ~]#

As you can see the status is disabled which means it’s not configured to start on boot.

Let’s enable php-fpm to start on boot by using systemctl

[[email protected] ~]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/php-fpm.service.
[[email protected] ~]#

Now, let’s see the status

[[email protected] ~]# systemctl status php-fpmphp
php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)    Active: inactive (dead) 
[[email protected] ~]#

php-fpm is all set to start on boot. Let’s test it by rebooting the server.

If you ever need to disable starting services on boot, then you can use below command

systemctl disable php-fpm

RHEL 7 has many new things, and if interested to learn more you can refer this online course by Cody Ray Miller.


Configuring auto-start services in Ubuntu is slightly different. Let’s say script name is nginx

  • Login to Ubuntu server with root
  • Copy the script in /etc/init.d/ folder
  • Execute the below command
update-rc.d nginx defaults
  • Reboot the server to ensure services are started.

This has helped me and I believe will be beneficial to you as well.

System administration is always fun and challenging, and if you are looking to supercharge your career in it, then you may refer this online course by Jason Cannon.

HostGator Hosting

9 thoughts on “How to Auto-start Services on Boot in Linux?”

  1. Instead of chkconfig –del httpd, we need to do chkconfig –-del httpd (Please check chkconfig sysntax)

Leave a Comment

Your email address will not be published. Required fields are marked *