Create new file with
.service
extension inside directory/lib/systemd/system/
. In this case, i will create with the namepajak.service
Here is a simple structure to create service, fill the file we have created above with this and adapt with your app.
[Unit] Description=Kurs Pajak [Service] Group=akhmad Type=simple Restart=always RestartSec=5s WorkingDirectory=/home/akhmad/pajak/ ExecStart=env HTTP_PORT=":8080" /home/akhmad/pajak/pajak PermissionsStartOnly=true StandardOutput=syslog StandardError=syslog SyslogIdentifier=sleepservice [Install] WantedBy=multi-user.target
From above service configuration, my app binary is inside
/home/akhmad/pajak/
directory that have the namepajak
.Config you need to give attention is
ExecStart
, andWorkingDirectory
ExecStart
should be point to the executable binary, just like how you usually run the app directly. In my example above, i haveenv HTTP_PORT=":8080"
that will be passed to the app as HTTP Port to access the app.WorkingDirectory
here will be relative path for the app. It’s not depends to the binary file you have, so you can change it anywhere you want. I have set this inside/home/akhmad/pajak/
to store a file created from the app, and to read the file from the app.
Also, any output or error from the app will be saved to syslog, you can check it with command
sudo systemctl status pajak.service
As for another configuration, you can always check the man-page of systemd service here.
After the service is ready, and have been configured, you can start the service with command
sudo systemctl start <file_name.service>
in this case, will be
sudo systemctl start pajak.service
If there is an error says can’t find the service, it seems you need to reload the daemon first
sudo systemctl daemon-reload
As to make sure the service will be running at booting, make sure to run this command
sudo systemctl enable pajak.service