How to ensure a service or program starts on boot on Centos Linux
Enjoying this content? Subscribe to the Channel!
Stop Services from Breaking on Reboot: How to Auto-Start Any Program in Linux
Hi there! This is Darren O’Neill from Darren’s Tech Tutorials, and today we are tackling one of the most common frustrations in server management: ensuring your essential services actually start when your Linux machine boots up.
You’ve installed a critical service—maybe a database like MariaDB, a web server, or a custom application—only to discover that after a routine server reboot, it’s totally offline. That’s a huge problem! Luckily, solving this is incredibly easy and only requires running one simple command.
We recorded this tutorial on CentOS 8, but this method utilizing the chkconfig command is reliable and should work flawlessly across most major Linux distributions, including Ubuntu and Debian.
The Critical Problem: Services That Don’t Survive a Reboot
When you install a new service on Linux, it often starts up fine for your current session. But by default, many services are not configured to automatically run when the operating system loads.
Let’s look at the problem in action, using MariaDB as our example database service.
-
Check the initial status (before reboot):
sudo service mariadb statusResult: Running. Great!
-
Reboot the machine.
-
Check the status again (after reboot): Result: Not Running.
This scenario means every time your server undergoes a power cycle or maintenance reboot, your database is unavailable, leaving your users and applications stranded. We need to tell the system, “Hey, this service is important—make sure it launches automatically!”
The Linux Boot Fix: Introducing the chkconfig Command
The tool we use to manage the starting and stopping of services during the system boot sequence is called chkconfig. This command allows us to register services to run automatically at specific runlevels.
If you want a service to survive a reboot and be available immediately, you need to use the chkconfig command combined with the on parameter.
The Essential Command Syntax
The core command you need to learn is simple. Just substitute servicename with the actual name of the program you want to auto-start:
sudo chkconfig servicename on
Step-by-Step Guide: How to Ensure Your Service Starts on Boot
To correctly enable auto-start for any service, follow these three simple steps. We will continue using MariaDB (mariadb) as our example service.
Step 1: Ensure Your Service is Currently Running
Before you tell the system to start a service on boot, you should ensure the service is actually started and functional right now. If it’s not running, start it up first.
sudo service mariadb start
Double-check its status to make sure it’s running correctly:
sudo service mariadb status
Step 2: Enable the Service for Auto-Start
Now we execute the magic command! This tells the Linux system to include the MariaDB service in the list of programs that must initialize during the system boot sequence.
Type the following command carefully:
sudo chkconfig mariadb on
If the command executes without error, congratulations! You have successfully configured MariaDB to start automatically.
Step 3: Verify the Fix with a Reboot
The only true test is a reboot. We need to confirm that our configuration change actually sticks.
-
Restart your Linux machine. (Wait patiently for it to come back online.)
-
Once the system is back up, check the service status immediately:
sudo service mariadb status
The expected result? You should see the status report that MariaDB is up and running!
This method works for any service. Simply substitute mariadb with the correct name of the service you need to manage (like httpd, nginx, ssh, etc.).
Summary and Next Steps
Preventing service downtime after a server reboot is crucial for reliability. By leveraging the straightforward chkconfig servicename on command, you ensure that your essential applications are always available exactly when you need them. It’s a quick fix that makes a massive difference in server stability!
I hope this short guide was helpful! If you found this quick Linux trick useful, please take a moment to like this post and subscribe to Darren’s Tech Tutorials for more clear, accessible technology guides.
Thanks for watching!