美文网首页服务端
服务部署 nohup 或 shell

服务部署 nohup 或 shell

作者: Super淳语 | 来源:发表于2021-10-14 17:00 被阅读0次

nohup

通过 Linux 的 nohup 命令使程序在后台执行。
 nohup /data/mix/bin/mixapp api >/dev/null 2>&1 &

shell

通常我们会使用一个简单的 shell 脚本来管理 mix 进程,保存以下脚本为 mix.sh:
file mix 入口文件绝对路径
cmd 使用的 mix 命令名称

#!/bin/sh
echo "============`date +%F' '%T`==========="

file=/data/mix/bin/mixapp
cmd=api

getpid()
{
  docmd=`ps aux | grep ${file} | grep ${cmd} | grep -v 'grep' | grep -v '\.sh' | awk '{print $2}' | xargs`
  echo $docmd
}

start()
{
  pidstr=`getpid`
  if [ -n "$pidstr" ];then
    echo "running with pids $pidstr"
  else
     $file $cmd -d
     sleep 1
     pidstr=`getpid`
     echo "start with pids $pidstr"
  fi
}

stop()
{
  pidstr=`getpid`
  if [ ! -n "$pidstr" ];then
     echo "Not Executed!"
     return
  fi

  echo "kill $pidstr"
  kill $pidstr
}

restart()
{
  stop
  sleep 1
  start
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
esac

sh mix.sh start
sh mix.sh stop
sh mix.sh restart

相关文章

网友评论

    本文标题:服务部署 nohup 或 shell

    本文链接:https://www.haomeiwen.com/subject/pgduoltx.html