一、直接给代码
1. start.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function read_dir() { if [ $# -eq 0 ] then echo "Usage: $0 [DirFile]" exit 1 fi
echo "Service is starting...."
cd ./$1 mkdir logs/ &> /dev/null & nohup npm run serve >& logs/catalina-$(date +%Y-%m-%d).log &
echo "Service starting succuesful!" }
read_dir $1
|
2. stop.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
function read_dir() { if [ $# -eq 0 ] then echo "Usage: $0 [DirFile]" exit 1 fi
echo "Service is stop...."
if [[ -f $1 ]] then echo "$1 is not a DirFile!" exit 1 fi
pid=`ps -ef | grep $1 | grep -v grep | awk '{print $2}'` if [ -z $pid ]; then echo "" echo "Service $1 is not running! It's not necessary to stop it!" echo "" else kill -9 $pid echo "" echo "Servuce stop successfuly! pid:${pid} which has been killid forcibly!" echo "" fi }
read_dir $1
|
3.status.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
function read_dir() { if [ $# -eq 0 ] then echo "Usage: $0 [DirFile]" exit 1 fi
if [[ -f $1 ]] then echo "$1 is not a DirFile!" exit 1 fi
pid=`ps -ef | grep $1 | grep -v grep | awk '{print $2}'` if [ -z $pid ]; then echo "" echo "Service $1 is not running!" echo "" else echo "" echo "Servuce $1 is running. It's pids=${pid}" echo "" fi }
read_dir $1
|
二、结束语
评论区可留言,可私信,可互相交流学习,共同进步,欢迎各位给出意见或评价,本人致力于做到优质文章,希望能有幸拜读各位的建议!
专注品质,热爱生活。
交流技术,寻求同志。
—— 嗝屁小孩纸 QQ:1160886967