提交 1b6f2430 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

shell to check and restart the service

上级 60c71cd9
Version = 2.0
Version = 2.1
Language = zh
Url = http://zentaopms.ngtesting.com/
Account = admin
......
......@@ -450,6 +450,7 @@
"id": "fail_heart_beat",
"translation": "Fail to send heartbeat request."
},
{
"id": "find_new_ver",
"translation": "Find new version %s"
......
......@@ -457,6 +457,7 @@
"id": "fail_heart_beat",
"translation": "发送心跳请求失败。"
},
{
"id": "find_new_ver",
"translation": "发现新版本%s。"
......
......@@ -9,7 +9,7 @@ import (
)
func Clean() {
path := vari.ZTFDir + constant.LogDir
path := vari.ExeDir + constant.LogDir
bak := path[:len(path)-1] + "-bak" + string(os.PathSeparator) + path[len(path):]
os.RemoveAll(path)
......
......@@ -51,7 +51,7 @@ func NewServer() *Server {
func (s *Server) Init() {
vari.IP, vari.MAC = serverUtils.GetIp()
vari.AgentLogDir = vari.ZTFDir + serverConst.AgentLogDir + constant.PthSep
vari.AgentLogDir = vari.ExeDir + serverConst.AgentLogDir + constant.PthSep
err := fileUtils.MkDirIfNeeded(vari.AgentLogDir)
if err != nil {
logUtils.PrintTof("mkdir %s error %s", vari.AgentLogDir, err.Error())
......@@ -166,7 +166,7 @@ func (s *Server) post(req *http.Request) (resp domain.RespData, err error) {
}
func Download(w http.ResponseWriter, fi string) {
logDir := vari.ZTFDir + "log-agent" + constant.PthSep
logDir := vari.ExeDir + "log-agent" + constant.PthSep
file, _ := os.Open(logDir + strings.Replace(fi, "-", "/", 1))
defer file.Close()
......
......@@ -16,7 +16,6 @@ import (
"github.com/fatih/color"
"github.com/inconshreveable/go-update"
"github.com/mholt/archiver/v3"
"github.com/sirupsen/logrus"
"os"
"strconv"
"strings"
......@@ -91,7 +90,7 @@ func (s *UpgradeService) DownloadFile(version string) (pass bool, err error) {
}
func (s *UpgradeService) RestartVersion(version string) (err error) {
currExePath := vari.ZTFDir + constant.AppName
currExePath := vari.ExeDir + constant.AppName
bakExePath := currExePath + "_bak"
newExePath := vari.AgentLogDir + version + constant.PthSep + constant.AppName + constant.PthSep + constant.AppName
if commonUtils.IsWin() {
......@@ -99,7 +98,7 @@ func (s *UpgradeService) RestartVersion(version string) (err error) {
bakExePath += ".exe"
newExePath += ".exe"
}
logrus.Println(currExePath)
logUtils.PrintTo(currExePath)
rd, _ := os.Open(newExePath)
err = update.Apply(rd, update.Options{OldSavePath: bakExePath})
......
......@@ -15,7 +15,7 @@ import (
)
func GetSysInfo() (info serverModel.SysInfo) {
info.AgentDir = vari.ZTFDir
info.AgentDir = vari.ExeDir
info.SysArch = runtime.GOARCH
info.SysCores = runtime.GOMAXPROCS(0)
......
......@@ -22,10 +22,10 @@ import (
)
func InitConfig() {
vari.ZTFDir, vari.IsDebug = fileUtils.GetZTFDir()
vari.ExeDir, vari.IsDebug = fileUtils.GetZTFDir()
CheckConfigPermission()
vari.ConfigPath = vari.ZTFDir + constant.ConfigFile
vari.ConfigPath = vari.ExeDir + constant.ConfigFile
vari.Config = getInst()
// screen size
......@@ -125,12 +125,12 @@ func getInst() model.Config {
}
func CheckConfigPermission() {
//err := syscall.Access(vari.ZTFDir, syscall.O_RDWR)
//err := syscall.Access(vari.ExeDir, syscall.O_RDWR)
err := fileUtils.MkDirIfNeeded(vari.ZTFDir + "conf")
err := fileUtils.MkDirIfNeeded(vari.ExeDir + "conf")
if err != nil {
logUtils.PrintToWithColor(
i118Utils.I118Prt.Sprintf("perm_deny", vari.ZTFDir), color.FgRed)
i118Utils.I118Prt.Sprintf("perm_deny", vari.ExeDir), color.FgRed)
os.Exit(0)
}
}
......
......@@ -172,7 +172,7 @@ func GetZTFDir() (dir string, isDebug bool) { // where ztf command in
}
func GetLogDir() string {
path := vari.ZTFDir + constant.LogDir
path := vari.ExeDir + constant.LogDir
if vari.ServerWorkDir != "" {
path = vari.ServerWorkDir + constant.LogDir
}
......
......@@ -12,7 +12,7 @@ var (
MainViewHeight int
ConfigPath string
ZTFDir string
ExeDir string
ServerWorkDir string
ServerProjectDir string
LogDir string
......
#!/usr/bin/env bash
dftPortZtf=8848
dftPortZd=8849
interval=7
nowTime=`date +"%Y-%m-%d %H:%M:%S"`
nowDate=`date +"%Y-%m-%d"`
PARAM_NAME=$1
PARAM_PORT=$2
if [ -z "$PARAM_NAME" ]; then
echo "first parameter - name can't be empty"
exit 1
fi
DIR="$( cd "$( dirname "$0" )" && pwd )"
PORT=`ps -ef | grep "$PARAM_NAME" | grep -v "grep" | grep -v ".sh" | awk '{print $10}'`
echo name: $PARAM_NAME, dir: $DIR, port $PORT
if [ -z "$PARAM_PORT" ]; then
if [ -z "$PORT" ]; then
if [ "$PARAM_NAME" = "ztf" ]; then
PARAM_PORT="$dftPortZtf"
else
PARAM_PORT="$dftPortZd"
fi
else
PARAM_PORT="$PORT"
fi
fi
for var in 1 2
do
if [ -n "$PORT" ]; then
if [ $PORT = $PARAM_PORT ]; then
echo Thread is still alive, sleep $interval second the $var time.
sleep $interval
else
echo kill service on port $PORT.
ps -ef | grep "$PARAM_NAME" | grep -v "grep" | grep -v ".sh" | awk '{print $2}' | xargs kill -9
PORT=
fi
else
echo $nowTime start service on port $PARAM_PORT in dir $DIR.
cd $DIR
nohup ./ztf -P $PARAM_PORT > nohup.log 2&>zenops-agent-$nowDate.log &
echo ""
break
fi
done
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册