ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Making an RC Script on Linux

    Scheduled Pinned Locked Moved IT Discussion
    linuxrc script
    1 Posts 1 Posters 276 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      Often we need to build our own RC scripts which can be managed via the chkconfig command but we don’t know where to start. Here is a blank framework that simply needs to be filled out in order to work. Once completed, just put into /etc/init.d and use “chkconfig -add scriptname” to enable it.

      #!/bin/sh
      #
      # name          This shell script takes care of starting and stopping
      #               the "name" services.
      #
      # chkconfig: - 60 20
      # description: Fill in description
      # probe: true
      # config: If there is a config file
       
      RETVAL=0
      uid=`id | cut -d\( -f1 | cut -d= -f2`
       
      # See how we were called.
      case "$1" in
        start)
                      # Start the process
                      # Only root can stop the service
                      [ $uid -ne 0 ] && exit 4
                      ;;
        stop)
                      # Stop the process
                      # Only root can stop the service
                      [ $uid -ne 0 ] && exit 4
                      ;;
        status)
                      # Check on app
                      ;;
        restart)
                      $0 stop
                      $0 start
                      ;;
        *)
                      echo $"Usage: nfs {start|stop|status|restart}"
                      RETVAL=2
                      ;;
      esac
       
      exit $RETVAL
      

      Originally found on my Linux blog in 2014: http://web.archive.org/web/20140825114908/http://www.scottalanmiller.com/linux/2014/06/27/making-an-rc-script/

      1 Reply Last reply Reply Quote 2
      • 1 / 1
      • First post
        Last post