"Fossies" - the Fresh Open Source Software Archive

Member "opendhcp/rc.opendhcp" (21 Jun 2021, 1914 Bytes) of package /linux/misc/opendhcpV1.80.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "rc.opendhcp": V1.64_vs_V1.65.

    1 #!/bin/bash
    2 #chkconfig: 2345 20 80
    3 #description: #start/stop open dhcp
    4 #Originally Contributed by sharne, slightly modified.
    5 ### BEGIN INIT INFO
    6 # Provides:          opendhcpd
    7 # Required-Start:    $local_fs $network
    8 # Required-Stop:     $local_fs $network
    9 # Default-Start:     2 3 4 5
   10 # Default-Stop:      0 1 6
   11 # Short-Description: Start daemon at boot time
   12 # Description:       Enable service provided by daemon.
   13 ### END INIT INFO
   14 
   15 ##### Modify lines below for location of executive and other files #####
   16 EXEFILE=/opt/opendhcp/opendhcpd
   17 INIFILE=/opt/opendhcp/opendhcp.ini
   18 LOGFILE=/opt/opendhcp/log/opendhcp%Y%m%d.log
   19 STATEFILE=/tmp/opendhcp.state
   20 ##### There is generally no need to modify anything below this line #####
   21 
   22 # Get pid
   23 getpid() {
   24 pidnum=$( ps -eaf | grep -v grep | grep -w opendhcpd | awk '{ print $3,$2 }' | sort | head -1 | awk '{ print $2 }' )
   25 }
   26 
   27 # Start opendhcp:
   28 opendhcp_start() {
   29 ${EXEFILE} -i ${INIFILE} -l ${LOGFILE} -s ${STATEFILE}
   30 getpid
   31 if [ -n "$pidnum" ]; then
   32 echo "Open DHCP Server started"
   33 else
   34 echo "Open DHCP Server failed to start"
   35 fi
   36 }
   37 
   38 # Stop opendhcp:
   39 opendhcp_stop() {
   40 kill $pidnum
   41 while [ true ]
   42 do
   43 getpid
   44 if [ -z "$pidnum" ] ; then
   45 echo "Open DHCP Server stopped"
   46 break
   47 fi
   48 sleep 1
   49 done
   50 }
   51 
   52 case "$1" in
   53 'start')
   54 getpid
   55 if [ -z "$pidnum" ] ; then
   56 opendhcp_start
   57 RETVAL=0
   58 else
   59 echo "Open DHCP Server is already running - Try restart"
   60 RETVAL=1
   61 fi
   62 ;;
   63 'stop')
   64 getpid
   65 if [ -z "$pidnum" ] ; then
   66 echo "Open DHCP Server is not running"
   67 RETVAL=1
   68 else
   69 opendhcp_stop
   70 RETVAL=0
   71 fi
   72 ;;
   73 'restart')
   74 getpid
   75 if [ -z "$pidnum" ] ; then
   76 echo "Open DHCP Server is not running"
   77 opendhcp_start
   78 else
   79 opendhcp_stop
   80 opendhcp_start
   81 fi
   82 RETVAL=0
   83 ;;
   84 'status')
   85 getpid
   86 if [ -z "$pidnum" ] ; then
   87 echo "Open DHCP Server is stopped"
   88 RETVAL=1
   89 else
   90 echo "Open DHCP Server is running - Pid : $pidnum"
   91 RETVAL=0
   92 fi
   93 ;;
   94 *)
   95 echo "Usage $0 { start | stop | restart | status }"
   96 RETVAL=1
   97 ;;
   98 esac
   99 exit $RETVAL
  100 
  101 # Enjoy!
  102