简单脚本实现服务监控

服务经常会重启失败,写了个简单的shell叫脚本,可以发现服务端口是否起来,没有发现监听端口会重启服务 1.监控脚本 if [ -z "`lsof -i:443 | grep LISTEN`" ];then echo -e "restart $(date +'%Y-%m-%d %H:%M:%S')" systemctl restart pixiublog fi 2.系统定时任务 */3 * * * * /usr/local/pixiublog/monitor.sh >> /usr/local/pixiublog/monitor.log 2>&1

October 16, 2020

haokiu网站启动脚本

haokiu 的启动脚本,配置 https 可以参考beego 通过acms.sh 使用 https #!/bin/sh siteDir='/usr/local/pixiublog' appName='pixiublogMain' echo "kill the running program" ps -ef | grep $appName | grep -v grep | awk '{print $2}' | xargs kill -9 echo "sleep 3 secons for app to shutdown" sleep 3 echo "start program" cd $siteDir nohup $siteDir/$appName >> $siteDir/console.log 2>&1 &

October 15, 2020

beego 通过acme.sh 使用 https

beego 通过 acme.sh 使用 https 安装acms.sh curl https://get.acme.sh | sh 生成证书 如果使用的是 beego 框架,需添加可访问的静态文件目录: //acme.sh 自动验证网站目录,不使用https可以忽略 beego.SetStaticPath("/.well-known", ".well-known") acme.sh --issue -d haokiu.com -d www.haokiu.com --webroot /usr/local/pixiublog/ 设置pixiublog开机启动 1. 编写开机启动脚本 vim /usr/lib/systemd/system/pixiublog.service [Unit] Description=The pixiublog Process Manager After=syslog.target network.target [Service] Type=forking ExecStart=sh /usr/local/pixiublog/start.sh ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill -SIGINT $MAINPID [Install] WantedBy=multi-user.target 2. 设置开机启动 systemctl enable pixiublog 安装证书 acme.sh --install-cert -d haokiu.com \ --cert-file /home/blog/cert/cert.pem \ --key-file /home/blog/cert/key.pem \ --fullchain-file /home/blog/cert/fullchain.pem \ --reloadcmd "systemctl restart pixiublog" beego app.conf 配置 EnableHTTPS = true HTTPSPort = 443 HTTPSCertFile = "/home/blog/cert/fullchain.pem" HTTPSKeyFile = "/home/blog/cert/key.pem" 参考 acme.sh 使用

October 13, 2020

网站部署脚本

网站的部署脚本 #!/bin/sh #部署目录 siteDir='/usr/local/pixiublog' # 源代码目录 cd /root/pixiublog echo "update code" git pull echo "build pixiublog" go build main.go echo "remove old" rm -rf $siteDir/views rm -rf $siteDir/static rm -rf $siteDir/pixiublog echo "mv new program to $siteDir" cp main $siteDir/pixiublog cp -rf views $siteDir/ cp -rf static $siteDir/ echo "kill the running program" ps -ef | grep 'pixiublog' | grep -v grep | awk '{print $2}' | xargs kill -9 echo "start program" cd $siteDir nohup $siteDir/pixiublog >> $siteDir/console.log 2>&1 &

September 17, 2020