1、进入服务根目录
cd /etc/rc.d/init.d/
2、创建和编辑服务脚步
vi zookeeper
内容如下:
#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
export JAVA_HOME=/opt/jdk1.7.0_07
export PATH=$JAVA_HOME/bin:$PATH
case $1 in
start) su root /usr/local/zookeeper-3.4.6/bin/zkServer.sh start;;
stop) su root /usr/local/zookeeper-3.4.6/bin/zkServer.sh stop;;
status) su root /usr/local/zookeeper-3.4.6/bin/zkServer.sh status;;
restart) su root /usr/local/zookeeper-3.4.6/bin/zkServer.shrestart;;
*) echo "require start|stop|status|restart" ;;
esac
其中,标蓝内容为服务的启动级别和开启、关闭的优先级。
标红为zookeeper的操作命令
3、为服务文件赋予执行权限
chmod +x zookeeper
4、增加服务,服务默认开机自启动
chkconfig --add zookeeper
5、验证
service zookeeper start
service zookeeper stop
service zookeeper restart
service zookeeper status
6、shell中使用了switch-case语法
echo "input type value:"
read type
case ${type} in
0) echo "type is 0"
;;
1) echo "type is 1"
;;
2|3)
echo "type is 2 or 3"
;;
*) echo "type error"
;;
esac