Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: arpwatch
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. ### END INIT INFO
  9. # /etc/init.d/arpwatch: v9 2004/08/14 KELEMEN Peter <fuji@debian.org>
  10. # Based on /etc/init.d/skeleton (1.8 03-Mar-1998 miquels@cistron.nl)
  11. # 2001/10/26 fuji@debian.org Support multiple instances.
  12. # 2001/11/24 fuji@debian.org Use POSIX-style functions.
  13. # 2001/12/17 fuji@debian.org Use --pidfile on startup, fix restart.
  14. # 2004/08/10 fuji@debian.org Source /etc/default/arwpatch .
  15. # Create datafile if it doesn't exist.
  16. # Run daemon only if executable.
  17.  
  18. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  19. NAME=arpwatch
  20. DAEMON=/usr/sbin/$NAME
  21. DESC="Ethernet/FDDI station monitor daemon"
  22. DATADIR=/var/lib/$NAME
  23.  
  24. test -x $DAEMON || exit 0
  25.  
  26. ### You shouldn't touch anything below unless you know what you are doing.
  27.  
  28. [ -f /etc/default/arpwatch ] && . /etc/default/arpwatch
  29.  
  30. # Decide whether we have to deal with multiple interfaces.
  31. CONF=/etc/arpwatch.conf
  32. MULTIPLE=0
  33. if [ -r $CONF ]; then
  34. grep -c '^[a-z]' $CONF 2>&1 >/dev/null && MULTIPLE=1
  35. fi
  36.  
  37. # Check whether we have to drop privileges.
  38. if [ -n "$RUNAS" ]; then
  39. if getent passwd "$RUNAS" >/dev/null; then
  40. ARGS="-u ${RUNAS} $ARGS"
  41. else
  42. RUNAS=""
  43. fi
  44. fi
  45.  
  46. start_instance () {
  47. IFACE=$1
  48. INSTANCE=${NAME}-${IFACE}
  49. IFACE_OPTS="-i ${IFACE} -f ${IFACE}.dat $2"
  50. DATAFILE=$DATADIR/${IFACE}.dat
  51.  
  52. echo -n "Starting $DESC: "
  53. if [ ! -f $DATAFILE ]; then
  54. echo -n "(creating $DATAFILE) "
  55. :> $DATAFILE
  56. fi
  57. if [ -n "$RUNAS" ]; then
  58. echo -n "(chown $RUNAS $DATAFILE) "
  59. chown $RUNAS $DATAFILE
  60. fi
  61. start-stop-daemon --start --quiet \
  62. --pidfile /var/run/${INSTANCE}.pid \
  63. --exec $DAEMON -- $IFACE_OPTS $ARGS
  64. echo "${INSTANCE}."
  65. ps h -C $NAME -o pid,args | \
  66. awk "/$IFACE/ { print \$1 }" > /var/run/${INSTANCE}.pid
  67. }
  68.  
  69. stop_instance () {
  70. IFACE=$1
  71. INSTANCE=${NAME}-${IFACE}
  72. [ -f /var/run/${INSTANCE}.pid ] || return 0
  73. echo -n "Stopping $DESC: "
  74. start-stop-daemon --stop --quiet --oknodo \
  75. --pidfile /var/run/${INSTANCE}.pid
  76. echo "${INSTANCE}."
  77. rm -f /var/run/${INSTANCE}.pid
  78. }
  79.  
  80. process_loop_break_line () {
  81. __IFACE=$1
  82. shift
  83. __IOPTS="$@"
  84. }
  85.  
  86. process_loop () {
  87. OPERATION=$1
  88. grep '^[a-z]' $CONF 2>/dev/null | \
  89. while read LINE
  90. do
  91. process_loop_break_line $LINE
  92. I=$__IFACE
  93. I_OPTS="$__IOPTS"
  94. $OPERATION $I "$I_OPTS"
  95. done
  96. }
  97.  
  98. start_default () {
  99. echo -n "Starting $DESC: "
  100. if [ ! -f $DATADIR/arp.dat ]; then
  101. echo -n "(creating $DATADIR/arp.dat) "
  102. :> $DATADIR/arp.dat
  103. fi
  104. if [ -n "$RUNAS" ]; then
  105. echo -n "(chown $RUNAS $DATADIR/arp.dat) "
  106. chown $RUNAS $DATADIR/arp.dat
  107. fi
  108. start-stop-daemon --start --quiet \
  109. --exec $DAEMON -- $ARGS
  110. echo "$NAME."
  111. }
  112.  
  113. stop_default () {
  114. echo -n "Stopping $DESC: "
  115. start-stop-daemon --stop --quiet --oknodo \
  116. --exec $DAEMON
  117. echo "$NAME."
  118. rm -f /var/run/$NAME.pid
  119. }
  120.  
  121. startup () {
  122. if [ "$MULTIPLE" -gt 0 ]; then
  123. process_loop start_instance
  124. else
  125. start_default
  126. fi
  127. }
  128.  
  129. shutdown () {
  130. if [ "$MULTIPLE" -gt 0 ]; then
  131. process_loop stop_instance
  132. else
  133. stop_default
  134. fi
  135. }
  136.  
  137. case "$1" in
  138. start)
  139. startup
  140. ;;
  141. stop)
  142. shutdown
  143. ;;
  144. reload)
  145. echo "Reload operation not supported -- use restart."
  146. exit 1
  147. ;;
  148. restart|force-reload)
  149. #
  150. # If the "reload" option is implemented, move the "force-reload"
  151. # option to the "reload" entry above. If not, "force-reload" is
  152. # just the same as "restart".
  153. #
  154. shutdown
  155. sleep 1
  156. startup
  157. ;;
  158. *)
  159. N=/etc/init.d/$NAME
  160. # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
  161. echo "Usage: $N {start|stop|restart|force-reload}" >&2
  162. exit 1
  163. ;;
  164. esac
  165.  
  166. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement