Go语言基础 —— (23)Linux服务部署方案
»
    这是从网络的文章中总结得到的最佳Linux服务部署方案。我(张人杰)的方案:

    go-search.service:

[Unit]     				
Description=go search server
After=network.target

[Service]
WorkingDirectory=/root/
Type=forking
ExecStart=/root/start-go-search.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -9 $MAINPID
PrivateTmp=true
Restart=always
RestartSec=15
StartLimitInterval=0
StartLimitBurst=5

[Install]
WantedBy=multi-user.target


    go-nginx.service:

[Unit]     				
Description=go nginx server
After=network.target

[Service]
WorkingDirectory=/root/nginx-compiled/
Type=forking
ExecStart=/root/nginx-compiled/sbin/nginx
ExecReload=/root/nginx-compiled/sbin/nginx  -s reload
ExecStop=/bin/killall nginx
PrivateTmp=true
Restart=always
RestartSec=10
StartLimitInterval=0
StartLimitBurst=5

[Install]
WantedBy=multi-user.target


    start-go-search.sh:

#!/bin/bash
cd /root/
nohup ./go-search > /dev/null 2>&1  &

    文件部署:
    1、go-search.service与go-nginx.service放到/etc/systemd/system/目录里;
    2、使用systemctl enable go-search、systemctl enable go-nginx和systemctl daemon-reload使能两个服务的自启动;
    3、使用service go-search start和service go-nginx start启动服务;
    4、判断服务运行状态service go-search status和service go-nginx status。

    加一段英文:The difference between this solution and rc.local  is: the process will be restarted in this solution whenever the process is down by other reasons.
«
——张人杰·www.v-signon.com学习者共勉
返回上一页
备案号:京ICP备19038994号-2
个人作品网站:www.up-task.com 主办:个人 English
免责声明:本网站3d地球模型购买自3d.3d66.com,如权利人发现存在误传其作品情形,请及时与本站联系。