不错的linux下通用的java程序启动脚本(转载)_rodert-CSDN博客_java 启动脚本

https://blog.csdn.net/qq_40374604/article/details/91820355
Linux shell脚本启动 停止 重启jar包 - 君哥~ - 博客园
https://www.cnblogs.com/wangfajun/p/9585530.html

创建启动脚本

  1. cd jar
  2. vim autostart.sh
  3. #!/bin/sh
  4. source /etc/profile
  5. RUN_DIR="/root/jar";
  6. nohup java -Xms512m -Xmx1024m -jar $RUN_DIR/scancode.jar >> $RUN_DIR/scancode.log 2>&1 &
  7. nohup java -Xms1024m -Xmx1024m -jar $RUN_DIR/settle-0.0.1-SNAPSHOT.jar --spring.profiles.active=local >> $RUN_DIR/settle.log 2>&1 &
  8. chmod +x ./autostart.sh

添加开机自启

  1. vim /usr/lib/systemd/system/jar.service
  2. [Unit]
  3. Description=jar
  4. After=network.target
  5. [Service]
  6. Type=forking
  7. ExecStart=/root/jar/autostart.sh
  8. PrivateTmp=true
  9. [Install]
  10. WantedBy=multi-user.target
  11. chmod 755 /usr/lib/systemd/system/jar.service
  12. systemctl daemon-reload
  13. systemctl enable jar.service

关闭开机自启

  1. systemctl disable jar.service