Last active
May 22, 2024 07:12
-
-
Save ccarrasc/c42e4c2e16231d21d891 to your computer and use it in GitHub Desktop.
Install a Node.js service for systemctl on CentOS 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
After=network.target | |
[Service] | |
ExecStart=/usr/bin/node /var/node/my-service/app.js | |
#Type=forking | |
Restart=always | |
StandardOutput=syslog | |
TimeoutSec=90 | |
SyslogIdentifier=my-service | |
User=nobody | |
Group=nobody | |
Environment=PATH=/usr/bin:/usr/local/bin | |
Environment=NODE_ENV=production | |
[Install] | |
WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
curl -sL https://rpm.nodesource.com/setup | bash - | |
yum install -y nodejs gcc-c++ make | |
sudo mkdir -p /var/node/my-service/ | |
# ... cp project into /var/node/my-service/ | |
cd /var/node/my-service/ | |
npm install | |
sudo cp my-service.service /etc/systemd/system/ | |
systemctl enable my-service | |
systemctl start my-service.service |
enable
will enable the service to start at boot, but this script (node-daemon.sh
) is meant to install, enable, and start app.js
as a service. So at the end, it start
s the service immediately. Otherwise, you would have to reboot to start it.
(I have no idea if this still works, as it's quite old 🤪)
I’m doing a similar thing actually and I thought enable would start the service (which will start the js script), but maybe I need to add the start command as well, cuz I can see that the service is enabled but the script doesn’t seem to start 🤪
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could be wrong but shouldn't enable start the service on boot up, thus no need for
systemctl start
?