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 for two popular distros tested on DigitalOcean servers.

CentOS or RHEL 6.x

In the following example, I have taken an Apache HTTP server, but the procedure remains the 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 a root user on your Linux server Create or copy your script under /etc/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

Confirm script is added successfully with –list

That’s all! httpd script will be called to start services on Linux boot. In case you need to disable the auto-start service then you can use the following commands

RHEL or CentOS 7.x/8.x

The 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 (this assume you already have scripts in /usr/lib/systemd/system/) 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 Now, let’s see the status 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 the below command You may also prefer to check out this post explaining systemd and auto-starting services on boot.

Ubuntu

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

Login to Ubuntu server with root Copy the script in /etc/init.d/ folder Execute the below command

Reboot the server to ensure services are started.

This has helped me and I believe it 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 to this Udemy course. Next, check out how to find Linux sudden reboot reason. Head here you want to install/upgrade PHP-FPM 5.6 on CentOS 6.x.

How to Auto start Services on Boot in Linux  - 28How to Auto start Services on Boot in Linux  - 22How to Auto start Services on Boot in Linux  - 70How to Auto start Services on Boot in Linux  - 48How to Auto start Services on Boot in Linux  - 76How to Auto start Services on Boot in Linux  - 84How to Auto start Services on Boot in Linux  - 29How to Auto start Services on Boot in Linux  - 51How to Auto start Services on Boot in Linux  - 28How to Auto start Services on Boot in Linux  - 71How to Auto start Services on Boot in Linux  - 39How to Auto start Services on Boot in Linux  - 4How to Auto start Services on Boot in Linux  - 46How to Auto start Services on Boot in Linux  - 42How to Auto start Services on Boot in Linux  - 30How to Auto start Services on Boot in Linux  - 41How to Auto start Services on Boot in Linux  - 41How to Auto start Services on Boot in Linux  - 53How to Auto start Services on Boot in Linux  - 90How to Auto start Services on Boot in Linux  - 81How to Auto start Services on Boot in Linux  - 81How to Auto start Services on Boot in Linux  - 5How to Auto start Services on Boot in Linux  - 98