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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 🤪