Advertisement
devinteske

nfsd_stats init.d script

Mar 13th, 2020
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.27 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # nfsd_stats - script to start/stop nfsd_stats daemon
  4. #
  5. # chkconfig:   2345 99 10
  6. # description: daemon to dump nfsd_stats.log statistics to InfluxDB
  7. #              (requires telegraf)
  8. # processname: nfsd_stats
  9. # pidfile:     /var/run/nfsd_stats.pid
  10.  
  11. # Source function library.
  12. . /etc/rc.d/init.d/functions
  13.  
  14. nfsd_stats=/usr/local/bin/nfsd_stats
  15. prog=${nfsd_stats##*/}
  16.  
  17. pidfile="/var/run/$prog.pid"
  18.  
  19. start()
  20. {
  21.     local st
  22.  
  23.     if st=$( status ); then
  24.         echo "$st"
  25.         return
  26.     fi
  27.     [ -x $nfsd_stats ] || exit 5
  28.     echo -n "Starting $prog: "
  29.     $nfsd_stats <&- >&- 2> /var/run/$prog.stderr &
  30.     sleep 3
  31.     if kill -0 $! 2> /dev/null; then
  32.         echo success
  33.         echo $! > $pidfile
  34.     else
  35.         echo failed
  36.     fi
  37. }
  38.  
  39. stop()
  40. {
  41.     local st
  42.  
  43.     if ! st=$( status ); then
  44.         echo "$st"
  45.         return
  46.     fi
  47.     echo -n "Stopping $prog: "
  48.     pkill -P $( cat $pidfile )
  49.     if [ $? -eq 0 ]; then
  50.         echo killed
  51.     else
  52.         echo failed
  53.     fi
  54. }
  55.  
  56. status()
  57. {
  58.     local pid
  59.  
  60.     if pid=$( cat $pidfile 2> /dev/null ) &&
  61.        pgrep -P $pid telegraf > /dev/null
  62.     then
  63.         echo "$prog is running (pid $pid)"
  64.     else
  65.         echo "$prog not running"
  66.         return 1
  67.     fi
  68. }
  69.  
  70. case "$1" in
  71. start|stop|status) $1 ;;
  72. restart) stop && sleep 3 && start ;;
  73. *)
  74.     echo "Usage: $0 {start|stop|restart|status}"
  75.     exit 2
  76. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement