shell脚本模版
#!/bin/bash
cd /usr/local/software/rocketmq-dashboard-1.0.0
APP_NAME=rocketmq-dashboard-1.0.0.jar
APP_LOG_PATH=./logs/rocketmq-dashboard
APP_LOG_FILE=rocketmq-dashboard.log
APP_LOG=$APP_LOG_PATH/$APP_LOG_FILE
usage() {
echo "Usage: sh demo.sh [start|stop|restart|status]"
exit 1
}
is_exist() {
pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}' `
if [ -z "$pid" ]; then
return 1
else
return 0
fi
}
start() {
is_exist
if [ $? -eq "0" ]; then
echo "$APP_NAME is already running. pid=$pid ."
else
if [ ! -d $APP_LOG_PATH ];then
mkdir -p $APP_LOG_PATH
fi
nohup java -jar $APP_NAME >> $APP_LOG 2>&1 & tail -f $APP_LOG
echo "log path:"$APP_LOG_PATH$APP_LOG_FILE
fi
}
stop() {
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
else
echo "$APP_NAME is not running"
fi
}
status() {
is_exist
if [ $? -eq "0" ]; then
echo "$APP_NAME is running. Pid is $pid"
else
echo "$APP_NAME is not running."
fi
}
restart() {
stop
start
}
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac
shell脚本多开,批量打开
#!/bin/bash
cd /usr/local/software/app-start
usage() {
echo "Usage: sh demo.sh [start|stop|restart|status]"
exit 1
}
start() {
sh server-rocketmq.sh start >/dev/null 2>&1 &
echo "server-rocketmq running"
sh broker-rocketmq.sh start >/dev/null 2>&1 &
echo "broker-rocketmq running"
sh dshboard-rocketmq.sh start >/dev/null 2>&1 &
echo "dshboard-rocketmq running"
}
stop() {
sh server-rocketmq.sh stop && sh broker-rocketmq.sh stop && sh dshboard-rocketmq.sh stop
}
status() {
sh server-rocketmq.sh status
sh broker-rocketmq.sh status
sh dshboard-rocketmq.sh status
}
restart() {
stop
echo "正在停止服务中"
sleep 10s
echo "准备启动服务中"
start
}
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac