使用vim命令在/etc/init.d目录下新建一个xx.sh,文件名可自定义,以test.sh为例

vim /etc/init.d/start.sh 也可以用 touch start.sh 命令创建文件(Python和Java主要区别在于启动命令不一样,其他操作是一样的

#!/bin/sh
### BEGIN INIT INFO
# Provides:          start.sh
# Required-start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the start.sh daemon
# Description:       starts start.sh using start-stop-daemon
### END INIT INFO
 
cd /home/app/gang_bao_li/
nohup java -Xms2048m -Xmx2048m -Xmn682m -Dspring.profiles.active=prod -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/app/gang_bao_li/heapdump -Dloader.path=./lib -jar gang-bao-li.jar > out.log 2>&1 &
 
echo 'starting...'

注意:上面的注释要存在,不然不生效。

编辑完成后,按ESC键,输入:wq 按回车保存并退出。

保存成功以后,设置文本权限,否则不生效

sudo chmod 755 /etc/init.d/start.sh

将命令脚本添加到启动脚本中去

cd /etc/init.d
sudo update-rc.d start.sh defaults

如需移除自启动,运行以下命令

cd /etc/init.d
sudo update-rc.d -f start.sh remove

查看启动项

ls /etc/rc*.d/

 

输入 reboot 命令重启服务器,使用命令查看jar包是否已经成功自启动。

ps -ef | grep jar名称

 

python找环境路径

列举环境列表

conda env list

  

 

posted on 2025-03-14 11:19  田坤坤  阅读(12)  评论(0)    收藏  举报