Advertisement
snadge

entropyfd init script

Aug 23rd, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.35 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # entropyfd: gathers entropy from another host via tcp
  4. ### BEGIN INIT INFO
  5. # Provides: entropyfd
  6. # Required-Start: $network
  7. # Required-Stop: $network
  8. # Default-Start: 3
  9. # Default-Stop:
  10. # Description: entropyfd
  11. # Short-Description: gathers entropy from another host via tcp
  12. ### END INIT INFO
  13. #
  14. # - originally written by Henri Gomez, Keith Irwin, and Nicolas Mailhot
  15. # - heavily rewritten by Deepak Bhole and Jason Corley
  16. #
  17.  
  18. # Get instance specific config file
  19. if [ -r "/etc/sysconfig/entropyfd" ]; then
  20.     . /etc/sysconfig/entropyfd
  21. fi
  22.  
  23. # Source function library.
  24. INITD=/etc/rc.d/init.d
  25. . $INITD/functions
  26.  
  27. # Set the game server pid file
  28. ENTROPYFD_PID="/var/run/entropyfd.pid"
  29.  
  30. script_result=0
  31.  
  32. function checkpid() {
  33.     local i
  34.     for i in $* ; do
  35.         if [ -d "/proc/${i}" ]; then
  36.             return 0
  37.         fi
  38.     done
  39.     return 1
  40. }
  41.  
  42. function start() {
  43.     ENTROPYFD_START=$"Starting entropyfd service: "
  44.     if [ -f "/var/lock/subsys/entropyfd" ] ; then
  45.         if [ -f "$ENTROPYFD_PID" ]; then
  46.             read kpid < $ENTROPYFD_PID
  47.                 if checkpid $kpid 2>&1; then
  48.                     echo
  49.                     echo "Process already running"
  50.                     echo_failure
  51.                     exit 1
  52.                     echo
  53.                 else
  54.                     echo
  55.                     echo "lock file found but no process running for"
  56.                     echo "pid $kpid, continuing"
  57.                 fi
  58.         fi
  59.     fi
  60.  
  61.     echo -n "$ENTROPYFD_START"
  62.  
  63. #    /usr/bin/nc -n $ENTROPYFD_HOST $ENTROPYFD_PORT |/sbin/rngd -f -r /dev/stdin 2>&1|/usr/bin/logger -t entropyfd
  64.     /usr/bin/nc -n $ENTROPYFD_HOST $ENTROPYFD_PORT |/sbin/rngd -f -r /dev/stdin 2>&1
  65.  
  66.     RETVAL="$?"
  67.     if [ "$RETVAL" -eq 0 ]; then
  68.         success "$ENTROPYFD_START"
  69.         echo
  70.         if [ ! -z "$ENTROPYFD_PID" ]; then
  71.           echo $! > $ENTROPYFD_PID
  72.         fi
  73.         touch /var/lock/subsys/entropyfd
  74.     else
  75.         failure "$ENTROPYFD_START"
  76.         echo
  77.         script_result=1
  78.     fi
  79. }
  80.  
  81. function stop() {
  82.     echo -n "Stopping entropyfd service: "
  83.     if [ -f "/var/lock/subsys/entropyfd" ]; then
  84.         kill $ENTROPYFD_PID
  85.         RETVAL="$?"
  86.         if [ "$RETVAL" -eq "0" ]; then
  87.             rm -f /var/lock/subsys/entropyfd $ENTROPYFD_PID
  88.             echo_success
  89.         else
  90.             echo_failure
  91.         fi
  92.         echo
  93.     fi
  94. }
  95.  
  96. function status() {
  97.     RETVAL="1"
  98.     if [ -f "$ENTROPYFD_PID" ]; then
  99.         read kpid < $ENTROPYFD_PID
  100.         if checkpid $kpid 2>&1; then
  101.             echo "entropyfd is already running (${kpid})"
  102.             RETVAL="0"
  103.         else
  104.             echo "lock file found but no process running for pid $kpid"
  105.         fi
  106.     else
  107.         pid="$(/usr/bin/pgrep /sbin/rngd)"
  108.         if [ -n "$pid" ]; then
  109.             echo "$0 running (${pid}) but no PID file exists"
  110.             RETVAL="0"
  111.         else
  112.             echo "$0 is stopped"
  113.         fi
  114.     fi
  115.     return $RETVAL
  116. }
  117.  
  118. # See how we were called.
  119. case "$1" in
  120.     start)
  121.         start
  122.         ;;
  123.     stop)
  124.         stop
  125.         ;;
  126.     restart)
  127.         stop
  128.         sleep 2
  129.         start
  130.         ;;
  131.     status)
  132.         status
  133.         ;;
  134.     *)
  135.         echo -n "Usage: entropyfd "
  136.         echo "{start|stop|restart|status}"
  137.         exit 1
  138. esac
  139.  
  140. exit $script_result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement