Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # entropyfd: gathers entropy from another host via tcp
- ### BEGIN INIT INFO
- # Provides: entropyfd
- # Required-Start: $network
- # Required-Stop: $network
- # Default-Start: 3
- # Default-Stop:
- # Description: entropyfd
- # Short-Description: gathers entropy from another host via tcp
- ### END INIT INFO
- #
- # - originally written by Henri Gomez, Keith Irwin, and Nicolas Mailhot
- # - heavily rewritten by Deepak Bhole and Jason Corley
- #
- # Get instance specific config file
- if [ -r "/etc/sysconfig/entropyfd" ]; then
- . /etc/sysconfig/entropyfd
- fi
- # Source function library.
- INITD=/etc/rc.d/init.d
- . $INITD/functions
- # Set the game server pid file
- ENTROPYFD_PID="/var/run/entropyfd.pid"
- script_result=0
- function checkpid() {
- local i
- for i in $* ; do
- if [ -d "/proc/${i}" ]; then
- return 0
- fi
- done
- return 1
- }
- function start() {
- ENTROPYFD_START=$"Starting entropyfd service: "
- if [ -f "/var/lock/subsys/entropyfd" ] ; then
- if [ -f "$ENTROPYFD_PID" ]; then
- read kpid < $ENTROPYFD_PID
- if checkpid $kpid 2>&1; then
- echo
- echo "Process already running"
- echo_failure
- exit 1
- echo
- else
- echo
- echo "lock file found but no process running for"
- echo "pid $kpid, continuing"
- fi
- fi
- fi
- echo -n "$ENTROPYFD_START"
- # /usr/bin/nc -n $ENTROPYFD_HOST $ENTROPYFD_PORT |/sbin/rngd -f -r /dev/stdin 2>&1|/usr/bin/logger -t entropyfd
- /usr/bin/nc -n $ENTROPYFD_HOST $ENTROPYFD_PORT |/sbin/rngd -f -r /dev/stdin 2>&1
- RETVAL="$?"
- if [ "$RETVAL" -eq 0 ]; then
- success "$ENTROPYFD_START"
- echo
- if [ ! -z "$ENTROPYFD_PID" ]; then
- echo $! > $ENTROPYFD_PID
- fi
- touch /var/lock/subsys/entropyfd
- else
- failure "$ENTROPYFD_START"
- echo
- script_result=1
- fi
- }
- function stop() {
- echo -n "Stopping entropyfd service: "
- if [ -f "/var/lock/subsys/entropyfd" ]; then
- kill $ENTROPYFD_PID
- RETVAL="$?"
- if [ "$RETVAL" -eq "0" ]; then
- rm -f /var/lock/subsys/entropyfd $ENTROPYFD_PID
- echo_success
- else
- echo_failure
- fi
- echo
- fi
- }
- function status() {
- RETVAL="1"
- if [ -f "$ENTROPYFD_PID" ]; then
- read kpid < $ENTROPYFD_PID
- if checkpid $kpid 2>&1; then
- echo "entropyfd is already running (${kpid})"
- RETVAL="0"
- else
- echo "lock file found but no process running for pid $kpid"
- fi
- else
- pid="$(/usr/bin/pgrep /sbin/rngd)"
- if [ -n "$pid" ]; then
- echo "$0 running (${pid}) but no PID file exists"
- RETVAL="0"
- else
- echo "$0 is stopped"
- fi
- fi
- return $RETVAL
- }
- # See how we were called.
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- stop
- sleep 2
- start
- ;;
- status)
- status
- ;;
- *)
- echo -n "Usage: entropyfd "
- echo "{start|stop|restart|status}"
- exit 1
- esac
- exit $script_result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement