Skip to content

Instantly share code, notes, and snippets.

@ccarrasc
Last active May 22, 2024 07:12
Show Gist options
  • Save ccarrasc/c42e4c2e16231d21d891 to your computer and use it in GitHub Desktop.
Save ccarrasc/c42e4c2e16231d21d891 to your computer and use it in GitHub Desktop.
Install a Node.js service for systemctl on CentOS 7
[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
#! /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
@Addibro
Copy link

Addibro commented Nov 9, 2022

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