0

Menjalankan Program Java sebagai Service pada Ubuntu

Buat sebuah Service

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

Copy/paste kode berikut ini ke dalam file myjava.service

[Unit]
Description=My Java Service

[Service]
User=ubuntu
# The configuration file application.properties should be here:

#change this to your workspace
WorkingDirectory=/home/ubuntu/workspace

#path to executable. 
#executable is a bash script which calls jar file
ExecStart=/home/ubuntu/workspace/start

SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Buat file Bash Script untuk memanggil Service

nano /home/ubuntu/workspace/start

Copy/paste kode berikut:

#!/bin/sh 
/usr/bin/java -jar myjava.jar

Start Service

sudo systemctl enable myjava.service
sudo systemctl start myjava.service