How to start your project using systemd service
In this guide I'll show you how you can utilize systemd service to start long-running command on server boot.
Before we start let me explain why should use this to start your project.
Systemd is a process manager that can start, stop, and manage processes on your machine. You can order it when to start, what command to execute, restart it on crash and more.
This is really helpful because, if correctly done, service will ensure maximum uptime of the project, even if it crashes for some reason.
Creating a service is really easy.
First, we need to create a file called
/etc/systemd/system/ directory. You can name it however you want, it just needs to have
.service as an extension.
Next, open up that file with the editor of your choice.
and past code below in it.
After creating and saving this configuration, you need to give it the correct permissions
The next step is to start our service. YAY!
First, we need to create a symlink, and we do that by enabling the service
After that, we have to start our newly created service
After starting the successfully service no message should be printed in the console. To see if our service is working we will use
If you see similar output to this
then your service is working as it should, and you will be able to visit your app by visiting the server's IP.