Create a Start-up Service for Node.js*
These steps show you how to create a system service for a Node.js* file (blink sample). You can then start the service at boot.
For this example, we create a system service called blinkjs. This service runs a blink sample on the Intel® Edison Kit for Arduino* during boot. You can find the JavaScript blink sample at GitHub.
To create the service file for Node.js, complete the following steps:
-
Create and name the service file with a .service extension in the /etc/system/system/ directory:
root@MyEdison:~# vi blinkjs.service /etc/systemd/system
-
Put the following content inside the file and change it to meet the needs of your service (Do not include comments):
[Unit]
Description=Blink JavaScript //Brief description of your system service[Service]
ExecStart=/usr/bin/node/blink.js //Commands with their arguments that execute when service startsRestart=always //Service restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.
Environment=NODE_PATH=/usr/lib/node_modules //Path to command's binary
[Install]
WantedBy=multi-user.target -
To start the service, use the systemctl start command:
root@MyEdison:~# systemctl start blinkjs.service
blinkjs.service: Blink JavaScript with Node.js
Loaded: loaded (/etc/systemd/system/blinkjs.service; disabled)
Active: active (running) since Wed 2015-08-05 17:44:45 UTC; 137ms ago
Main PID: 400 (node)
CGroup: /system.slice/blinkjs.service
+-400 /usr/bin/node /home/root/blink.js
Aug 05 17:44:45 EDISON1_WW25.5 systemd[1]: Started Blink JavaScript with Node.js.
-
To check the status of the system service, use the systemctl status command:
root@MyEdison:~# systemctl status blinkjs.service
-
To enable service to start at boot time, use the systemctl enable command:
root@MyEdison:~# systemctl enable blinkjs.service
-
To restart the system service when changes are made to the service file, use the systemctl daemon-reload command:
root@MyEdison:~# systemctl daemon-reload