systemd

ststemd is an system and service manager which will start, monitor and terminate process by a script. it is the first daemon to start during booting and the last daemon to terminate during shutdown. For more info visit https://systemd.io/

Create a system service

To create a systemd service, we need to create a service file

filename: webswitch.service

[Unit]
Description="webSwitch node service"
After=network.target

[Service]
Type=Simple
WorkingDirectory=/home/pi/Documents/webSwitch/node
ExecStart=/usr/bin/node /home/pi/Documents/webSwitch/node/app.js &

[Install]
WantedBy=multi-user.target

systemd basic commands

To Enable a service (this will be used when very first time)

sudo systemctl enable webswitch.service

To Start a Service

systemctl start webswitch.service

To Stop a service

systemctl stop webswitch.service

To restart a service

systemctl restart webswitch.service

To reaload a service

systemctl daemon-reload

To view logs of an service

journalctl -u webswitch.service

©2023-2024 rculock.com