How to make a simple system.d service for a node.js server
Put this content:
[Unit]
Description={name}
[Service]
Type=simple
User={user}
ExecStart=/usr/bin/node {full-path-to-script}.js
[Install]
WantedBy=multi-user.target
... somewhere as {name}.service, where:
- {name} is the name of the service
- {user} is the name of the user to run the script (optional)
... then:
- run: this sudo ln -s /{full_path}/{name}.service /lib/systemd/system/{name}.service
- then this: sudo systemctl daemon-reload
- then this: sudo systemctl enable {name}.service
- and finally this: sudo systemctl start {name}
How does it work?
- It starts the service on boot (see WantedBy section).
- Using ExecStart command. Important: we specify the full path to node
- SystemD remembers the PID of the new process and considers the service is ongoing until the process is died.
- So any subsequent systemctrl start {name} won't do anything if the previous process is alive.
- This behavior is determined by Type=Simple
Комментарии
Оставить комментарий
modules/comment
window._Comment_content_article_178 = new classes.Comment( '#comment_block_content_article_178',
{
type: 'content_article',
node_id: '178',
user: 1,
user_id: 0,
admin: 0,
view_time: null,
msg: {
empty: 'Комментарий пуст',
ask_link: 'Ссылка:',
ask_img: 'Ссылка на изображение:' }
});