One of the essential for a system administrator to know is how to configure service at boot, so when a server gets reboot, they start automatically.
There could be various reasons for server reboot, including the following.
- Scheduled as 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.
The following examples are for two popular distros tested on DigitalOcean servers.
Let’s configure Apache HTTP server to start at boot.
You can keep any script file name, and here I’ve kept
- 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
[[email protected] init.d]# chkconfig --add httpd [[email protected] init.d]# chkconfig httpd on
- Confirm script is added successfully with
[[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]#
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
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.