学习资料
<packaging>jar</packaging> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <executable>true</executable> </configuration> </plugin> </plugins> </build>
[Unit] Description=A Spring Boot application After=syslog.target [Service] User=myapplication ExecStart=/opt/my-application.jar SuccessExitStatus=143 Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
/etc/systemd/system/
sudo chmod 500 my-application.jar sudo journalctl -u my-application.service
~/.config/systemd/user/my_service.servicesystemctl --user start my_service.service
~/.config/systemd/user/my_service.service
[Unit] Description=mbiolance-graph After=syslog.target [Service] Environment="JAVA_HOME=/home/wy/software/jdk1.8.0_202" ExecStart=/home/wangyang/workspace/knowledge-graph/target/knowledge-graph-1.0-SNAPSHOT.jar SuccessExitStatus=143 Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
systemctl --user status mbiolance-graph.service journalctl -u mbiolance-graph.service cp mbiolance-graph.service /home/wangyang/.config/systemd/user systemctl --user daemon-reload
创建文件/application/tools/jekens.sh,写入以下内容
/application/tools/jekens.sh
#!/bin/bash java -jar /application/tools/jenkins.war
运行下面命令
chmod +x /application/tools/jekens.sh
创建文件/application/tools/mbiolance-jenkins.service,写入以下内容
/application/tools/mbiolance-jenkins.service
[Unit] Description=mbiolance-graph After=syslog.target [Service] ExecStart=/application/tools/jekens.sh SuccessExitStatus=143 Restart=always RestartSec=5 [Install] WantedBy=multi-user.target
创建文件
mkdir -p ~/.config/systemd/user
拷贝文件到~/.config/systemd/user
~/.config/systemd/user
cp /application/tools/mbiolance-jenkins.service ~/.config/systemd/user ll ~/.config/systemd/user
运行程序
systemctl --user start mbiolance-jenkins.service
查看状态
systemctl --user status mbiolance-jenkins.service
查看log
journalctl --user -u mbiolance-jenkins.service
注意修改配置后需要roload
systemctl --user daemon-reload
设置开机自启
systemctl --user enable mbiolance-jenkins.service
Created symlink /home/shanjun/.config/systemd/user/multi-user.target.wants/mbiolance-jenkins.service → /home/shanjun/.config/systemd/user/mbiolance-jenkins.service.
Environment="One=1" "Three=3" Environment="Two=2" Environment="Four=4"