Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. ### Creating a systemd Service File
  2. >$ cd /lib/systemd/system
  3.  
  4. >$ sudo vi /lib/systemd/system/myNode.service
  5.  
  6. and put the following contents in it (example):
  7.  
  8. ```sh
  9. [Unit]
  10. Description=Start app.js on my Node
  11. After=network.target
  12.  
  13. [Service]
  14. Environment=NODE_PORT=3001
  15. Type=simple
  16. User=pi
  17. ExecStart=/usr/bin/node /home/pi/myApp/app.js
  18. Restart=on-failure
  19.  
  20. [Install]
  21. WantedBy=multi-user.target
  22.  
  23. ```
  24.  
  25. ### Using systemctl To Control Our App
  26.  
  27. **You have to do this whenever any of the service files change at all so that systemd picks up the new info.**
  28. >$ sudo systemctl daemon-reload
  29.  
  30. **If you want to make the application start up when the machine boots, you accomplish that by enabling it**
  31. >$ sudo systemtl enable myNode.service
  32.  
  33. **Other options**
  34. >$ sudo systemctl [status,start,stop,restart,enable,disable] myNode.service
  35.  
  36. **List**
  37. >$ systemctl list-unit-files | grep enabled
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement