centos service脚本编写开机启动

Published on 2022-10-01 19:22 in 分类: 软件 with 狂盗一枝梅
分类: 软件

以zookeeper为例,在/etc/rc.d/init.d目录下,新建一个文件zookeeper,内容如下

#!/bin/bash
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
export JAVA_HOME=//usr/local/jdk
case $1 in
        start) su root /usr/local/zookeeper/bin/zkServer.sh start;;
        stop) su root /usr/local/zookeeper/bin/zkServer.sh stop;;
        status) su root /usr/local/zookeeper/bin/zkServer.sh status;;
        restart) su /usr/local/zookeeper/bin/zkServer.sh restart;;
        *) echo "require start|stop|status|restart" ;;
esac

然后添加可执行权限

chmod +x zookeeper

最后就可以使用

service zookeeper start
service zookeeper status
service zookeeper stop
service zookeeper restart

命令管理zookeeper了

开机启动使用命令

 chkconfig --add zookeeper 

可以使用命令

chkconfig --list

查看被SysV管理的程序

[root@hadoop03 init.d]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
zookeeper       0:off   1:off   2:on    3:on    4:on    5:on    6:off

#linux #centos #service
目录
复制 复制成功