linux系统启动和停止服务进程

1.启动进程

##!/bin/bash

APP_NAME=demo.jar
PID='ps -ef |grep "APP_NAME" | grep -v "grep" | awk '{print $2}''
if [-z $PID ]; then
   echo "process id is empty,process is not existed..."
else
   echo $PID
        for id in $PID
        do 
        echo "kill Pid : $id"
        done
fi

echo "stop success...,begin to restart"        

nohup java -jar $APP_NAME > /dev/null 2>&1 &
sleep 1
PID='ps -ef |grep "APP_NAME" | grep -v "grep" | awk '{print $2}''
if [-z $PID];then
    echo "peocess restart failure"
else
    echo "process restart success:$PID"
fi    

2.停止进程

(1)

ps aux|grep demo.jar|grep -v "grep"|awk '{print $2}' |xargs kill -9

(2)

#!/bin/bash
appserver=redis-server

pid=`ps -ef|grep ${appserver} |grep -v grep|awk '{print $2}'`

if ["$pid" != ""] then
   echo "kill ${appserver}: $pid"
   kill -9 $pid
else
   echo "${appserver} is not running."   
fi   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值