Running Applications as a system service
Jan 6, 2021
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.