Skip to content

Instantly share code, notes, and snippets.

@aissam-en
Last active August 7, 2024 12:13
Show Gist options
  • Save aissam-en/40a4042a0f809e38c5a129babfa82512 to your computer and use it in GitHub Desktop.
Save aissam-en/40a4042a0f809e38c5a129babfa82512 to your computer and use it in GitHub Desktop.
Creating a Systemd Service for Spring Boot Application to run it in test environments

Create service file :

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

The content of my_app.service file:

[Unit]
Description=Springboot app for BLABLA (test-env)
After=syslog.target network.target

[Service]
User=aissam
Environment=MY_APP_PORT=2003
Environment=MY_APP_SECRET_KEY=blablablablablablablabla
Environment=MY_APP_DB_PASSWORD=blablabla
ExecStart=/usr/bin/java -cp '/home/aissam/springboot_app/dep1.jar:/home/aissam/springboot_app/dep2.jar:/home/aissam/springboot_app/my_app.jar' org.springframework.boot.loader.launch.JarLauncher
ExecStop=/bin/kill -15 $MAINPID
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

Reload systemd daemon:

sudo systemctl daemon-reload

Start 'my_app' service:

sudo systemctl start my_app

View status/logs of 'my_app' service:

sudo systemctl status my_app

Follow logs:

sudo journalctl -u my_app -f

Enable 'my_app' service to start on boot:

sudo systemctl enable my_app
# to disable it : sudo systemctl disable my_app

Stop 'my_app' service:

sudo systemctl stop my_app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment