Chạy ứng dụng java JAR như một service

Thứ tư - 27/03/2024 11:11 95 0
Chạy ứng dụng java JAR như một service, ví dụ là tạo service để chạy ứng dung IP QUORUM Application của IBM
Lo hong leo thang dac quyen Systemd moi anh huong
Lo hong leo thang dac quyen Systemd moi anh huong
Cài đặt JAVA
[root@ip-qourum ~]# dnf install java

Tạo một file tên là ip_quorum.service đặt trong thư mục /etc/systemd/system/
[root@ip-qourum ~]# vi /etc/systemd/system/ip_quorum.service

Nội dung của file
[Unit]
Description=IBM IP Quorum Service                          # Mo ta dich vu
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
User=root                                                                  # user chay dich vu
WorkingDirectory=/opt/
ExecStart=/usr/bin/java -jar /opt/ip_quorum.jar        # chay lenh -jar /opt/ip_quorum.jar tuong duong voi lenh java -jar /opt/ip_quorum.jar
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target 

Reload để SystemD nhận dịch vụ mới
[root@ip-qourum ~]# sudo systemctl daemon-reload

Chạy service sau khi đã reload
[root@ip-qourum ~]# sudo systemctl start ip_quorum.service

Kiểm tra trạng thái của service
[root@ip-qourum ~]# sudo systemctl status ip_quorum.service

Cho phép service chạy khi máy chủ khởi động
[root@ip-qourum ~]# sudo systemctl enable ip_quorum.service

Tổng số điểm của bài viết là: 0 trong 0 đánh giá

Click để đánh giá bài viết
Bạn đã không sử dụng Site, Bấm vào đây để duy trì trạng thái đăng nhập. Thời gian chờ: 60 giây