Skip to content

Instantly share code, notes, and snippets.

@rousan
Created July 17, 2021 14:29
Show Gist options
  • Save rousan/574e4988bbb2ee29002c787ebb4b6c16 to your computer and use it in GitHub Desktop.
Save rousan/574e4988bbb2ee29002c787ebb4b6c16 to your computer and use it in GitHub Desktop.
How to add .service file in Ubuntu?

How to add .service file in Ubuntu?

  1. Write the my-server.service file name with the following content:
[Unit]
Description=Some description about the app.

[Service]
User=www-data
Group=www-data
WorkingDirectory=/home/ubuntu
ExecStart=/home/ubuntu/my-server

Environment="HOST=8080"
Environment="PORT=3001"

[Install]
WantedBy=multi-user.target
  1. Add the my-server.service file in the following path:
/etc/systemd/system/my-server.service
  1. Now you can stop/start/restart the service as follows:
$ sudo systemctl start my-server.service
$ sudo systemctl stop my-server.service
$ sudo systemctl restart my-server.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment