#!/bin/bash #进入rest所有目录,后续在此目录执行动作 cd /data/www/vhosts/go/ #rest的进程数,由于脚本名称为restart_rest.sh,所以排除了对restart_rest的搜索 n=`ps -ef|grep rest|grep -v grep|grep -v restart_rest|wc -l` if [ 0 -eq $n ]; then #进程不存在 echo "rest进程不存在" #nohup ./rest > /dev/null 2>&1 & else #rest进程存在,杀掉进程 echo "rest进程已存在,杀掉进程" ps -ef|grep rest|grep -v grep|grep -v restart_rest|awk '{print $2}'|xargs kill -9 fi echo "rest启动服务"
#使用nohup在后台执行服务 nohup ./rest > /dev/null 2>&1 &
转载于:https://www.cnblogs.com/ai594ai/p/10491120.html