Skip to content

Instantly share code, notes, and snippets.

@zaheeraws
Created February 23, 2023 12:37
Show Gist options
  • Save zaheeraws/15d3639ed0cb88838ead76e8df806ca0 to your computer and use it in GitHub Desktop.
Save zaheeraws/15d3639ed0cb88838ead76e8df806ca0 to your computer and use it in GitHub Desktop.
script.sh
#! /bin/bash
source ${HOME}/.bashrc
cd /absolute/path/to/my/project
export NODE_ENV=development
npm start
Now change it's mode to be executable
chmod +x script.sh
Now we can create our service (located for instance in /etc/systemd/system/my-project.service)
my-project.service
[Unit]
Description=My Project
After=syslog.target network.target
[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/path/to/my/script.sh
User=root
[Install]
WantedBy=multi-user.target
And now let's run it and enable it
systemctl start my-project
systemctl enable my-project
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment