启动脚本

 #!/bin/bash
# chkconfig: 2345 20 80
# description: Saves and restores system strapi
# start stop restart
source /root/.bash_profile
_proj=`echo $0 | awk -F '/' '{print $NF}'`
_PID=`/usr/bin/ps -ef | grep node | grep $_proj | grep start | awk  '{print $2}'`
_dir="/data/$_proj"
status(){
  if [ -n "$_PID" ]
  then
    echo "strapi is running ..."
  else
    echo "strapi is not running ..."
  fi
}
start() {
  if [ -n "$_PID" ];then
    echo "strapi is already running ..."
    exit 0
  fi
  #export NODE_ENV="staging"
  #export NODE_ENV="production"
  cd $_dir
  if [[ ! -d node_modules ]];then
     echo "node_modules does not exist. Install first."
     npm install && npm run build
  fi
  nohup /opt/node/bin/npm run start >output 2>1 &
  echo "Starting strapi daemon..."
  sleep 10
  #grep error output >/dev/null 2>&1
  /usr/bin/ps -ef | grep node | grep $_proj | grep start >/dev/null 2>&1
  if [[ $? -eq 1 ]];then
    echo "Starting strapi failed.Here's the strapi log..."
    cat output
    exit 1
  fi
  echo "Starting strapi ok"
}
stop() {
  if [ -n "$_PID" ]
  then
   echo "Stopping strapi daemon..."
   kill -9 $_PID
   _PID=""
   echo "Stopping strapi ok"
  else
   echo "strapi is not running ..."
  fi
}
restart(){
    stop
    sleep 1
    start
}
case "$1" in
start)
    start
;;
stop)
    stop
;;
status)
status
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
posted @   ianCloud  阅读(61)  评论(0编辑  收藏  举报
编辑推荐:
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
点击右上角即可分享
微信分享提示