Skip to content

Instantly share code, notes, and snippets.

@jgcasta
Last active April 23, 2019 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgcasta/4b7c1f90c44ad5f27bc36eb37d62d1fc to your computer and use it in GitHub Desktop.
Save jgcasta/4b7c1f90c44ad5f27bc36eb37d62d1fc to your computer and use it in GitHub Desktop.
Systemd configuration

Configuration

sudo nano /etc/systemd/system/app.service

Edit file content

[Unit]
Description=APP name service

[Service]
WorkingDirectory=/home/ubuntu/appdir
ExecStart=/opt/jdk1.8.0_201/bin/java -jar /home/ubuntu/appdir/app.jar
User=ubuntu
Type=simple
Restart=on-failure
RestartSec=5
StandardOutput=null
[Install]
WantedBy=multi-user.target

Enable and start

sudo systemctl daemon-reload
sudo systemctl enable app.service
sudo systemctl start app
sudo systemctl status app

Systemctl commands

-- list managed services
systemctl list-unit-files --type service

-- list services
systemctl list-units --type=service --state=running

-- show systemctl log
journalctl -f

-- edit service
systemctl edit app.service
systemctl daemon-reload
systemctl restart app.service

-- delete service
systemctl stop app
systemctl disable app
rm /etc/systemd/system/app
rm /etc/systemd/system/app
systemctl daemon-reload
systemctl reset-failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment