Skip to content

Instantly share code, notes, and snippets.

@awabcodes
Last active June 18, 2022 20:42
Show Gist options
  • Save awabcodes/cbd1d599402bfc318f3d32c1b29789b5 to your computer and use it in GitHub Desktop.
Save awabcodes/cbd1d599402bfc318f3d32c1b29789b5 to your computer and use it in GitHub Desktop.
[Systemd Config] #systemd #linux #systemd_service

Create a systemd service

sudo nano /etc/systemd/system/webapp.service
[Unit]
Description=Webapp Service
[Service]
User=username

#the workspace
WorkingDirectory=/home/username/webapp

#command or path to executable.
ExecStart=/path/to/java -jar -Dspring.profiles.active=prod webapp.jar

SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target

Enable and start the service

sudo systemctl daemon-reload

sudo systemctl enable webapp.service
sudo systemctl start webapp
sudo systemctl status webapp

Show service logs

sudo journalctl -f -u webapp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment