2025-06-04 18:17:39 +08:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
if [[ $# != 3 ]]; then
|
|
|
|
echo "Usage: app.sh \${command} \${server} \${id}"
|
|
|
|
echo " command: start/stop/restart"
|
|
|
|
echo " server: the name of the server"
|
|
|
|
echo " id: the number greater than zero of the server id"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
CMD=$1
|
|
|
|
SVR=$2
|
|
|
|
SID=$3
|
|
|
|
|
|
|
|
cd ${SVR}_${SID}
|
|
|
|
|
|
|
|
start_server() {
|
2025-07-16 10:05:22 +08:00
|
|
|
pid=`ps -ef | grep ezs_${SVR} | grep ${SVR}_${SID}.json | awk '{print $2}'`
|
2025-06-04 18:17:39 +08:00
|
|
|
|
|
|
|
if [ ! -z ${pid} ]; then
|
|
|
|
echo "The server '${SVR}' with id:${SID} is running."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2025-07-16 10:05:22 +08:00
|
|
|
if [ ! -x ./bin/ezs_${SVR} ]; then
|
|
|
|
chmod +x ./bin/ezs_${SVR}
|
2025-06-04 18:17:39 +08:00
|
|
|
fi
|
|
|
|
|
2025-07-16 10:05:22 +08:00
|
|
|
nohup ./bin/ezs_${SVR} -conf ./conf/${SVR}_${SID}.json > ./ezs_${SVR}_${SID}.out 2>&1 &
|
2025-06-04 18:17:39 +08:00
|
|
|
|
|
|
|
sleep 2
|
|
|
|
|
2025-07-16 10:05:22 +08:00
|
|
|
pid=`ps -ef | grep ezs_${SVR} | grep ${SVR}_${SID}.json | awk '{print $2}'`
|
2025-06-04 18:17:39 +08:00
|
|
|
|
|
|
|
if [ -z ${pid} ]; then
|
|
|
|
echo "The server '${SVR}' with id:${SID} start failed."
|
2025-07-16 10:05:22 +08:00
|
|
|
tail -n30 ./bin/ezs_${SVR}_${SID}.out
|
2025-06-04 18:17:39 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "The server '${SVR}' with id:${SID} was started, pid: ${pid}"
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_server() {
|
2025-07-16 10:05:22 +08:00
|
|
|
pid=`ps -ef | grep ezs_${SVR} | grep ${SVR}_${SID}.json | awk '{print $2}'`
|
2025-06-04 18:17:39 +08:00
|
|
|
|
|
|
|
if [ ! -z ${pid} ]; then
|
|
|
|
kill ${pid}
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
echo "The server '${SVR}' with id:${SID} was stopped, pid: ${pid}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
case ${CMD} in
|
|
|
|
start)
|
|
|
|
start_server
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop_server
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
stop_server
|
|
|
|
start_server
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown command: ${CMD}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|