咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

Linux下jar包做成 systemctl 服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$ vim /etc/systemd/system/myjar.service


[Unit]
Description=myjar-server
#在哪个服务之后启动
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
User=root
Group=root
#启动命令
#ExecStart=java -jar /usr/local/myjar.jar --spring.profiles.active=pro
ExecStart=java -jar /usr/local/myjar.jar --spring.profiles.active=pro
# nohup命令无效
#ExecStart=nohup java -jar /usr/local/myjar.jar --spring.profiles.active=pro >>/usr/local/myjar.log&


ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

# 开启开机启动
$ systemctl enable myjar
Created symlink /etc/systemd/system/multi-user.target.wants/myjar.service → /etc/systemd/system/myjar.service.

# 查看服务是否开机启动:
$ systemctl is-enabled myjar
enabled

# 禁止开机启动
$ systemctl disable myjar
Removed /etc/systemd/system/multi-user.target.wants/myjar.service.

# 查看服务状态
$ systemctl status myjar
● myjar.service - myjar-server
Loaded: loaded (/etc/systemd/system/myjar.service; disabled; vendor prese>
Active: inactive (dead)

# 查看服务详情
$ systemctl show myjar

# 手动启动服务
$ systemctl start myjar
# 手动停止服务
$ systemctl stop myjar


# 查看日志
$ journalctl -u myjar