Running Applications as a system service

In this post, we will talk about how to configure your applications to run as a system service in Linux.

STEP 1. Make a backoffice.service file in /etc/systemd/system/ directory.

#/etc/systemd/system/backoffice.service[Unit] 
Description= Back office service
After=mysqld.service
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/env node /path/to/server/app.js

[Install]
WantedBy=multi-user.target

STEP 2. Run this command to make your daemon aware of your application.

systemctl daemon-reload

STEP 3. Run this command to start your application.

systemctl start backoffice
systemctl enable backoffice

STEP 4. Check your application as a service

service backoffice status
or
journalctl -u backoffice

You can also use other services such as nohup, forever, pm2, etc. to configure your application or you can use Linux crontab as well to make your application available all the time.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store