systemd 服务文件配置
[Unit]
Description=mhs_pc
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/java -jar /root/java_projects/mhs/admin/mhs_pc.jar --spring.config.location=/root/java_projects/mhs/admin/application.yml
WorkingDirectory=/root/java_projects/mhs/admin
User=root
Group=root
Restart=on-failure
[Install]
WantedBy=multi-user.target
- WorkingDirectory:确保 WorkingDirectory 指向你的应用程序所在目录,这样可以确保相对路径的配置文件能够被正确找到。
不设置log4j2日志会写到linux系统日志messages文件中 - 如果要显示指定日志配置文件 ExecStart=/usr/bin/java -Dlog4j.configurationFile=/root/java_projects/mhs/admin/log4j2.xml -jar /root/java_projects/mhs/admin/mhs_pc.jar --spring.config.location=/root/java_projects/mhs/admin/application.yml