Skip to content

Instantly share code, notes, and snippets.

@wooglie
Created February 18, 2022 13:56
Show Gist options
  • Save wooglie/6c5d065da91ba1511f40b1ea97fc3225 to your computer and use it in GitHub Desktop.
Save wooglie/6c5d065da91ba1511f40b1ea97fc3225 to your computer and use it in GitHub Desktop.
Linux service cheat sheet

linux_service

How to make a service in Ubuntu Linux

Save the following at /lib/systemd/system/you_service_name.service:

[Unit]
Description=My First Service
After=network-online.target

[Service]
Restart=on-failure
# do chdir before running the service
WorkingDirectory=/path/to/your/app
ExecStart=/usr/bin/node /path/to/your/app/app.js
# limit CPU and RAM quota for our service
CPUAccounting=true
CPUQuota=10%
MemoryAccounting=true
MemoryLimit=50M

[Install]
WantedBy=multi-user.target

Let the system know about our service:

systemctl daemon-reload

Load this service on boot:

systemctl enable you_service_name

Run:

systemctl restart you_service_name

Watch:

journalctl -lf -u you_service_name

Stop:

systemctl stop you_service_name

Disable:

systemctl disable you_service_name

Status:

systemctl status you_service_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment