To create a Linux service that runs a the worker script, you can use a systemd unit file. First, create a systemd service configuration file, and then start and enable the service using the systemctl command.
Follow these steps:
- Create a new service file for your Node.js script.
sudo nano /etc/systemd/system/dlaas.service- Add the following content to the service file, replacing
/path/to/your-worker-script.jswith the actual path to your Node.js script:
[Unit]
Description=DLaaS Worker Service
After=network.target
[Service]
ExecStart=/usr/bin/node /path/to/your-worker-script.js
Restart=always
User=nobody
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/path/to/your-worker-script
[Install]
WantedBy=multi-user.target-
Save the file and exit the text editor.
-
Reload the systemd daemon to apply the new service configuration:
sudo systemctl daemon-reload- Enable and start the service:
sudo systemctl enable dlaas.service
sudo systemctl start dlaas.service- Check the status of your service:
sudo systemctl status dlaas.serviceYour DLaaS worker script should now be running as a Linux service. The service will automatically restart if the script crashes or if the system is rebooted.