linux 设置go程序开机启动

采用chkconfig 方式设置程序开机启动
1,编写启动脚本,路径  cd /etc/init.d/名称


#!/bin/bash

# chkconfig: – 85 15

# description: rc.local is a local customized. It is used to serve

# @Author:dfsxh

# @Date: 2019-06-29 17:44:45

# @Last Modified by: dfsxh

# @Last Modified time: 2019-06-29 17:44:45

start(){ 

        cd /www/wwwroot/qncms/

        nohup ./qn_web_api &

        echo “服务已启动…”

        sleep 1

stop(){ 

        killall qn_web_api

        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 


也可以复制程序自带脚本 aegis 在start() 方法中直接添加启动指令即可

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

3,服务添加到服务列表 chkconfig –add 名称

4,查询服务列表确认添加成功 chkconfig –list

5,开启服务 chkconfig 名称 on

6,启动服务 service 名称 start

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

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容