soapui_mockservicerunner_script.sh

转自:https://gist.github.com/apuredol/e22b73d85daa3562e2f0a26ede9fd5e1

#!/bin/bash
#
# Designed for running SoapUI mockservicerunner.sh script in background as command line tool
# Credits to: tinogomes on github https://gist.github.com/tinogomes/447191
# References:
# http://stackoverflow.com/questions/14061876/control-to-the-next-statement-after-running-eval-command
# http://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes/6481337#6481337
# Changes for supporting multiple instances

# Variables to edit according to your environment
SOAPUI_HOME=$HOME/SoapUI-5.2.1
PROJECT_HOME=$HOME/somefolder/soap-ui
USR=`echo whoami`
# Default variables
PID=soapui-server.pid
LOG=soapui-server.log
if [ -z "$2" ]
then
  PORT=8080
else
  PORT=$2
fi

#Project name containing spaces goes in ""
COMMAND="$SOAPUI_HOME/bin/mockservicerunner.sh -p $PORT -m \"REST MockServices\" $PROJECT_HOME/my-project.xml"
echo "Running "$COMMAND

status() {
    if [ -f $PID ]
    then
        echo
        echo "Pid file: $( cat $PID ) [$PID]"
        echo
        ps -ef | grep -v grep | grep $( cat $PID )
    else
        echo
        echo "No Pid file"
    fi
}

start() {
  if [ -f $PID ]
    then
        echo
        echo "Already started. PID: [$( cat $PID )]"
    else
        touch $PID
        #eval command for avoid conflicts with "" in the command line parameters
        if (nohup `eval  $COMMAND`) >>$LOG 2>&1 &
        then echo $! >$PID
             echo "Done."
             echo "$(date '+%Y-%m-%d %X'): START" >>$LOG
        else echo "Error... "
             /bin/rm $PID
        fi
    fi
}

stop() {
    if [ -f $PID ]
    then
        if kill -- -$(ps -o pgid= $(cat $PID) | grep -o [0-9]*)
        then echo "Done."
             echo "$(date '+%Y-%m-%d %X'): STOP" >>$LOG
        fi
        /bin/rm $PID
    else
        echo "No pid file. Already stopped?"
    fi
}

case "$1" in
    'start')
            start
            ;;
    'stop')
            stop
            ;;
    'restart')
            stop ; echo "Sleeping..."; sleep 1 ;
            start
            ;;
    'status')
            status
            ;;
    *)
            echo
            echo "Usage: $0 { start [#port] | stop | restart [#port] | status }"
            echo
            exit 1
            ;;
esac

exit 0

Sign up for free

 

转载于:https://www.cnblogs.com/z1500592/p/6517883.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值