1.7 KiB
1.7 KiB
SystemD
There are many ways to create a systemd compatible service file. This guide is tailored to be "production ready".
Guide
- Create a new user named drawit:
sudo useradd --system --create-home --shell /usr/sbin/nologin drawit - Create env directory:
sudo mkdir -p /etc/drawit - Copy
.env.examplehere:sudo cp .env.example /etc/drawit/drawit.env - Change directory to /opt:
cd /opt - Follow instructions to clone the repo. Skip steps 4, 5, and 8.
- Change permissions to drawit:
sudo chown -R drawit:drawit /opt/drawit /etc/drawit - Create a new service file:
sudo nano /etc/systemd/system/drawit.service - Paste in these contents:
[Unit]
Description=DrawIt
After=syslog.target network.target remote-fs.target nss-lookup.target network-online.target
Wants=network-online.target
Requires=nginx.service
[Service]
Type=simple
User=drawit
Group=drawit
WorkingDirectory=/opt/drawit
Environment=NODE_ENV=production
Environment=PORT=3000
EnvironmentFile=/etc/drawit/drawit.env
ExecStart=/usr/bin/npm run start
RestartSec=5
KillSignal=SIGINT
TimeoutStopSec=30
SyslogIdentifier=drawit
TimeoutSec=30
StandardOutput=journal
StandardError=journal
Restart=always
[Install]
WantedBy=multi-user.target
- If you want to use a different port, make sure to change it e.g.
Environment=PORT=10000 - OPTIONALLY reload system daemon:
sudo systemctl daemon-reload - Enable and start the service:
sudo systemctl enable --now drawit.service - Check the service for errors:
sudo systemctl status drawit.service
You should now be running your very own DrawIt instance!
Additional reading
After you know it works!, you should set up a reverse proxy.