Linux笔记-利用chkconfig创建脚本使得Rabbimq开机自启

vim /etc/init.d/rabbitmq

#!/bin/bash
#
# chkconfig: 2345 80 05
# description: rabbitmq 
# processname: rabbitmq
 
#RabbitMQ安装目录
source /etc/profile
RABBITMQ_HOME=/root/rabbitmq/rabbitmq_server-3.6.15
export RABBITMQ_HOME

export HOME=/root
ERLANG_HOME=/root/rabbitmq/otp_src_20.3
export PATH=$PATH:$ERLANG_HOME/bin
 
case "$1" in
    start)
    echo "Starting RabbitMQ ..."
	cd $RABBITMQ_HOME/sbin
	rabbitmq-server -detached
    ;;
stop)
    echo "Stopping RabbitMQ ..."
	cd $RABBITMQ_HOME/sbin
    rabbitmqctl stop
    ;;
status)
    echo "Status RabbitMQ ..."
	cd $RABBITMQ_HOME/sbin
    rabbitmqctl status
    ;;
restart)
    echo "Restarting RabbitMQ ..."
	cd $RABBITMQ_HOME/sbin
    rabbitmq-server -detached
    ;;
 
*)
    echo "Usage: $prog {start|stop|status|restart}"
    ;;
esac
exit 0

这里有几个环境变量相关的,大家看着改:

#RabbitMQ安装目录
source /etc/profile
RABBITMQ_HOME=/root/rabbitmq/rabbitmq_server-3.6.15
export RABBITMQ_HOME

export HOME=/root
ERLANG_HOME=/root/rabbitmq/otp_src_20.3
export PATH=$PATH:$ERLANG_HOME/bin

赋予权限:

cd /etc/init.d/
chmod 777 rabbitmq

添加到启动项:

chkconfig --add /etc/init.d/rabbitmq

查看启动项:

chkconfig --list

设置启动:

chkconfig rabbitmq on

写好了后,要测试

service rabbimtq start
service rabbimtq stop
service rabbimtq status

如果有问题,要处理,不然服务器重启是起不来的。

上面测试都通过后

reboot

 

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页