rocketmq 启动脚本
时间: 2023-11-15 19:50:36 浏览: 67
RocketMQ的启动脚本主要有两种方式,一种是通过init.d方式启动,另一种是通过chkconfig方式启动。下面是两种方式的示例脚本:
1. init.d方式启动脚本(/etc/init.d/rocketmq-namesrv):
```shell
#!/bin/sh
#chkconfig: 2345 65 35
#description: start or stop rocketmq using chkconfig
dir=/app/rocketmq/bin
export JAVA_HOME=/usr/local/jdk
ret=0
start() {
if [ -f $dir/mqnamesrv ]; then
echo "starting rocketmq namesrv.."
cd $dir
nohup sh mqnamesrv >> namesrv.log 2>&1 &
ret=$?
echo "start success"
return $ret
fi
}
stop() {
if [ -f $dir/mqshutdown ]; then
echo "stopping rocketmq namesrv.."
cd $dir
./mqshutdown namesrv
ret=$?
echo "stop success"
return $ret
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo "restarting rocketmq namesrv.."
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage:$0 {start|stop|restart}"
exit 1
;;
esac
exit $ret
```
2. chkconfig方式启动脚本(/etc/rc.d/init.d/rocketmq-namesrv):
```shell
#!/bin/sh
#chkconfig: 2345 65 35
#description: start or stop rocketmq using chkconfig
dir=/app/rocketmq/bin
export JAVA_HOME=/usr/local/jdk
ret=0
start() {
if [ -f $dir/mqnamesrv ]; then
echo "starting rocketmq namesrv.."
cd $dir
nohup sh mqnamesrv >> namesrv.log 2>&1 &
ret=$?
echo "start success"
return $ret
fi
}
stop() {
if [ -f $dir/mqshutdown ]; then
echo "stopping rocketmq namesrv.."
cd $dir
./mqshutdown namesrv
ret=$?
echo "stop success"
return $ret
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo "restarting rocketmq namesrv.."
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage:$0 {start|stop|restart}"
exit 1
;;
esac
exit $ret
```
阅读全文