How to Enable Service Autostart on a VPS?
Virtual Private Servers (VPS) provide you with great flexibility and complete control over your servers. One important aspect of server management is configuring services to autostart. This allows your server to automatically launch the necessary services upon boot. In this article, we will look at how to enable service autostart on a VPS.
First, let’s determine which service we want to start automatically. For example, let’s say we need the nginx service to start automatically when the server boots. To do this, we need to follow a few steps.
Step 1: Configuring systemd
To configure service autostart on a VPS, we will use systemd — an init system that provides extensive capabilities for managing processes and services in Linux. To enable a service to autostart, we need to create a new unit file.
Open the terminal and execute the command:
sudo nano /etc/systemd/system/nginx.service
In the opened file, you need to add the following code:
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target
[Service]
Type=forking
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
Save the changes and close the editor.
Step 2: Updating systemd Configuration
For systemd to recognize our new unit file, you need to update its configuration. To do this, execute the command:
sudo systemctl daemon-reload
Now the system is ready to launch the nginx service automatically when the server boots.
Step 3: Enabling Service Autostart
To enable the nginx service to autostart, execute the command:
sudo systemctl enable nginx
Now, every time the server boots, the nginx service will automatically start.
Thus, we have considered the process of enabling service autostart on a VPS using systemd. This method provides a reliable and convenient way to manage services on your server.
Be careful when configuring service autostart on your server and monitor its performance. Thanks for your attention!