Advertisement
arxcorp

openvas-manager init script fails first time with error

Jun 14th, 2012
261
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None
  1. #!/bin/sh -e
  2. #
  3. # /etc/init.d/openvas-manager
  4. #
  5. ### BEGIN INIT INFO
  6. # Provides: openvas-manager
  7. # Required-Start: $remote_fs
  8. # Required-Stop: $remote_fs
  9. # Should-Start:
  10. # Should-Stop:
  11. # Default-Start:
  12. # Default-Stop: 0 6
  13. # Short-Description: Start and stop the OpenVAS Manager
  14. # Description: Controls the OpenVAS daemon "openvasmd".
  15. ### END INIT INFO
  16.  
  17. # time to wait for daemons death, in seconds
  18. # don't set it too low or you might not let openvasmd die gracefully
  19. DODTIME=5
  20.  
  21. # Read config
  22. [ -r /etc/default/openvas-manager ] && . /etc/default/openvas-manager
  23.  
  24. [ "$DATABASE_FILE" ] && DAEMONOPTS="--database="$DATABASE_FILE
  25. [ "$MANAGER_ADDRESS" ] && DAEMONOPTS="$DAEMONOPTS --listen=$MANAGER_ADDRESS"
  26. [ "$MANAGER_PORT" ] && DAEMONOPTS="$DAEMONOPTS --port=$MANAGER_PORT"
  27. [ "$SCANNER_ADDRESS" ] && DAEMONOPTS="$DAEMONOPTS --slisten=$SCANNER_ADDRESS"
  28. [ "$SCANNER_PORT" ] && DAEMONOPTS="$DAEMONOPTS --sport=$SCANNER_PORT"
  29.  
  30. DAEMON=/usr/sbin/openvasmd
  31. PIDFILE=/var/run/openvasmd.pid
  32. NAME=openvasmd
  33. LABEL="OpenVAS Manager"
  34.  
  35. test -x $DAEMON || exit 0
  36.  
  37.  
  38. running()
  39. {
  40. # No pidfile, probably no daemon present
  41. #
  42. [ ! -f "$PIDFILE" ] && return 1
  43. pid=`cat $PIDFILE`
  44.  
  45. # No pid, probably no daemon present
  46. [ -z "$pid" ] && return 1
  47.  
  48. [ ! -d /proc/$pid ] && return 1
  49. cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
  50. # No openvasmd?
  51. [ `basename "$cmd"` != "$NAME" ] && return 1
  52.  
  53. return 0
  54. }
  55.  
  56. start_daemon() {
  57. start-stop-daemon --start --exec $DAEMON -- $DAEMONOPTS 2>&1 >/dev/null
  58. errcode=$?
  59. # If we don't sleep then running() might not see the pidfile
  60. sleep $DODTIME
  61. return $errcode
  62. }
  63.  
  64. force_stop() {
  65. [ ! -e "$PIDFILE" ] && return
  66. if running ; then
  67. kill -15 $pid
  68. # Is it really dead?
  69. sleep "$DODTIME"s
  70. if running ; then
  71. kill -9 $pid
  72. sleep "$DODTIME"s
  73. if running ; then
  74. echo "Cannot kill $LABEL (pid=$pid)!"
  75. exit 1
  76. fi
  77. fi
  78. fi
  79. rm -f $PIDFILE
  80. }
  81.  
  82. case "$1" in
  83. start)
  84. echo -n "Starting $LABEL: "
  85. if start_daemon && running ; then
  86. echo "openvasmd."
  87. else
  88. echo "ERROR."
  89. exit 1
  90. fi
  91. ;;
  92. stop)
  93. echo -n "Stopping $LABEL: "
  94. if running ; then
  95. start-stop-daemon --stop --pidfile $PIDFILE --quiet --oknodo --exec $DAEMON
  96. sleep "$DODTIME"s
  97. fi
  98. if running; then
  99. force_stop
  100. fi
  101. echo "openvasmd."
  102. ;;
  103. restart)
  104. echo -n "Restarting $LABEL: "
  105. if running; then
  106. start-stop-daemon --stop --pidfile $PIDFILE --quiet --oknodo --exec $DAEMON
  107. sleep "$DODTIME"s
  108. fi
  109. if running; then
  110. force_stop
  111. fi
  112. if start_daemon && running ; then
  113. echo "openvasmd."
  114. else
  115. echo "ERROR."
  116. exit 1
  117. fi
  118. ;;
  119. reload|force-reload)
  120. echo -n "Reloading $LABEL configuration files: "
  121. start-stop-daemon --stop --pidfile $PIDFILE --signal 1 --exec $DAEMON
  122. sleep "$DODTIME"s
  123. if running ; then
  124. echo "done."
  125. else
  126. echo "ERROR."
  127. exit 1
  128. fi
  129. ;;
  130. status)
  131. echo -n "$LABEL is "
  132. if running ; then
  133. echo "running"
  134. else
  135. echo " not running."
  136. exit 1
  137. fi
  138. ;;
  139. update)
  140. echo "Updating the NVT cache"
  141. $DAEMON $DAEMONOPTS --update
  142. ;;
  143. rebuild)
  144. echo "Rebuilding the NVT cache"
  145. $DAEMON $DAEMONOPTS --rebuild
  146. ;;
  147. *)
  148. echo "Usage: /etc/init.d/openvas-manager {start|stop|restart|reload|status|update|rebuild}"
  149. exit 1
  150. ;;
  151. esac
  152.  
  153. exit 0
Advertisement
RAW Paste Data Copied
Advertisement