Skip to content

Instantly share code, notes, and snippets.

@apuredol
Last active September 9, 2021 13:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save apuredol/e22b73d85daa3562e2f0a26ede9fd5e1 to your computer and use it in GitHub Desktop.
Save apuredol/e22b73d85daa3562e2f0a26ede9fd5e1 to your computer and use it in GitHub Desktop.
Sample script to start/stop soapui mockservicerunner with nohup
#!/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 to join this conversation on GitHub. Already have an account? Sign in to comment