Register a auto-start-up service

Background:

1.All services script are stored under :  /etc/init.d

2.runlevel options:

   use "runlevel" to check which level the os is running.

   there are 6 runlevels:

     0:  shutdown.
     1:  single user mode.
     2:  multi user under a command line mode without NET connection .
     3: compared to 2, with NET connection.
     4: not avaiable.
     5: multi user with Xwindow.
     6: reboot

3.Services are corresponding to runlevel by means of store links under /etc/rc<runlevel>.d

4.links name as a format of "S/K<order><serviceName>":

    S indicates "startup service", while K means "kill service".

    order is the priority to start the service compared to other services.



sysv-rc-conf usage:

Steps:

  1. put your script(e.g. a file named "hadoop" ) into the dir of "/etc/init.d", hence we get a service(e.g hadoop).

  2. start the software by "sysv-rc-conf", enter into the service mgt gui.

010210_2Dvk_947997.png

    3. choose runlevels for service scenarios of start-up and stop(if needed).

    4. service register done. now you can test it by restart server(test auto-start-up) or shutdown(end service).


chkconfig usage:

    1. put your script(e.g. a file named "hadoop" ) into the dir of "/etc/init.d", hence we get a service(e.g hadoop).

    note: you script should provode startup/stop runlevel info by comments(Default-Start and Default-Stop), take OenTSDB service(a script with the path of "/etc/init.d/opentsdb") for example:

    #!/bin/sh -e    
    #
    # Modified from original source: Elastic Search
    # https://github.com/elasticsearch/elasticsearch
    # Thank you to the Elastic Search authors
    #
    ### BEGIN INIT INFO
    # Provides:          opentsdb
    # Required-Start:    $network $named
    # Required-Stop:     $network $named
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Starts OpenTSDB TSD
    # Description:       Starts an OpenTSDB time series daemon
    ### END INIT INFO
    PATH=/bin:/usr/bin:/sbin:/usr/sbin

       2. execute following command to register a service:

    chkconfig --add hadoop

       3. set the runlevel for the new added service by:

    chkconfig --level 2345 hadoop on
    chkconfig --level 06 hadoop off

     note : after the execution of this step, we can see soft link created under dir "/etc/rc<runlevel>.d":

    mose@mose-vritual:/etc/rc3.d$ ll    
    total 20
    drwxr-xr-x   2 root root  4096  3月 25 00:10 ./
    drwxr-xr-x 131 root root 12288  3月 22 22:01 ../
    -rw-r--r--   1 root root   677 10月 16 17:30 README
    lrwxrwxrwx   1 root root    18  3月 11 16:58 S01opentsdb -> ../init.d/opentsdb*
      .....
    lrwxrwxrwx   1 root root    18  3月  9 10:39 S05rc.local -> ../init.d/rc.local*
    lrwxrwxrwx   1 root root    16  3月 25 00:10 S20hadoop -> ../init.d/hadoop*

 update-rc.d 

     this is another service mgt software, which is also very easy to use.


Above all, we get a new service registered. since the script of /etc/init.d/hadoop can accept different opeation args, following command can be supported by this service.

service hadoop start/stop/restart/status


转载于:https://my.oschina.net/mose/blog/647012

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值