linux 设置go程序开机启动

采用chkconfig 方式设置程序开机启动

编写启动脚本,路径 cd /etc/init.d/名称 eg: test

#!/etc/init.d/
# chkconfig: - 85 15
# description: rc.local is a local customized. It is used to serve
# @Author: zyzhan
# @Date: 2023-03-01 17:44:45
# @Last Modified by: zyzhan
# @Last Modified time: 2023-03-01 17:44:45

start(){ 
        cd //home/wwwroot/default/
        nohup ./TjServer_linux &
        echo "服务已启动..."
        sleep 1
} 

stop(){ 
        killall TjServer_linux
        echo "服务已停止..."
        sleep 1
}

case "$1" in 
    start) start;;
    stop) stop;;
    restart) start;;
    reload) start;;
    status) start;;
    *)
        echo "$0 {start|stop|restart|reload|status}"
        exit 4
        ;;
esac 

命令执行

chkconfig 
chkconfig add test
chkconfig test on

  • 使用chmod 777 名称 脚本文件和授权文件有执行权限

  • 服务添加到服务列表 chkconfig --add 名称

  • 查询服务列表确认添加成功 chkconfig --list

  • 开启服务 chkconfig 名称 on

  • 启动服务 service 名称 start

  • 重启服务器程序即可开机启动

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值