Advertisement
Guest User

Untitled

a guest
Apr 8th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: datastax-agent
  4. # Required-Start: $network $local_fs $remote_fs $named $syslog $time
  5. # Required-Stop: $network $local_fs $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: DataStax Agent
  9. ### END INIT INFO
  10.  
  11. DESC="DataStax Agent"
  12. NAME="datastax-agent"
  13. USER="cassandra"
  14. MONITOR_NAME="datastax-agent-monitor"
  15.  
  16. TAC="datastax-agent.*-standalone.jar"
  17. PIDFILE="/var/run/datastax-agent/datastax-agent.pid"
  18. MONITOR_PIDFILE="/var/run/datastax-agent/datastax-agent-monitor.pid"
  19. LOG="/var/log/datastax-agent/agent.log"
  20. STARTUP_LOG="/var/log/datastax-agent/startup.log"
  21. OPSC_SSL_DIR="/var/lib/datastax-agent/ssl"
  22. OPSC_ADDR_DIR="/var/lib/datastax-agent/conf"
  23. INIT_VERBOSE=yes
  24.  
  25. SCRIPTNAME="$0"
  26.  
  27. # Read configuration variable file if it is present
  28. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  29.  
  30. # Load the VERBOSE setting and other rcS variables
  31. [ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
  32.  
  33. # Define LSB log_* functions.
  34. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  35. . /lib/lsb/init-functions
  36.  
  37. [ -d "/var/run/$NAME" ] || mkdir "/var/run/$NAME"
  38. [ -d "/var/log/$NAME" ] || mkdir "/var/log/$NAME"
  39. [ -f "$LOG" ] || touch "$LOG"
  40. [ -f "$STARTUP_LOG" ] || touch "$STARTUP_LOG"
  41. [ -e "$PIDFILE" ] || touch $PIDFILE
  42.  
  43. chown -RL $USER:$USER "/var/log/$NAME" "/var/run/$NAME"
  44.  
  45. is_running()
  46. {
  47. if [ -f "$PIDFILE" ]; then
  48. PID=$(cat "$PIDFILE" 2>/dev/null)
  49. grep -q "$TAC" "/proc/$PID/cmdline" 2>/dev/null && return 0
  50. return 1
  51. fi
  52. return 3
  53. }
  54.  
  55. do_start()
  56. {
  57. # Return
  58. # 0 if daemon has been started
  59. # 1 if daemon was already running
  60. # 2 if daemon could not be started
  61.  
  62. is_running && return 1
  63.  
  64. nohup /usr/share/datastax-agent/bin/datastax_agent_monitor >> /var/log/datastax-agent/agent.log 2>&1 &
  65. sleep 1
  66.  
  67. export OPSC_SSL_DIR OPSC_ADDR_DIR PID="$PIDFILE"
  68. nohup start-stop-daemon --start -c $USER --pidfile $PIDFILE --exec /usr/share/datastax-agent/bin/datastax-agent > $STARTUP_LOG 2>&1 &
  69. return 0
  70. }
  71.  
  72. do_stop()
  73. {
  74. # Return
  75. # 0 if daemon has been stopped
  76. # 1 if daemon was already stopped
  77. # 2 if daemon could not be stopped
  78. # other if a failure occurred
  79.  
  80. # stop the monitor process first
  81. # we don't use --exec /bin/bash because it doesn't seem to always work
  82. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
  83. --pidfile "$MONITOR_PIDFILE"
  84. MONITOR_RETVAL=$?
  85.  
  86. [ $MONITOR_RETVAL -eq 2 ] && return 2 # Couldn't stop
  87. [ $MONITOR_RETVAL -eq 3 ] && return 3 # Other error
  88. rm -f "$MONITOR_PIDFILE"
  89.  
  90. is_running || return 1
  91.  
  92. # then stop the agent
  93. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
  94. --pidfile "$PIDFILE"
  95.  
  96. RETVAL=$?
  97. [ $RETVAL -eq 2 ] && return 2 # Couldn't stop
  98. [ $RETVAL -eq 3 ] && return 3 # Other error
  99. rm -f "$PIDFILE"
  100. return "$RETVAL"
  101. }
  102.  
  103. case "$1" in
  104. start)
  105. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  106. do_start
  107. case "$?" in
  108. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  109. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  110. esac
  111. ;;
  112. stop)
  113. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  114. do_stop
  115. case "$?" in
  116. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  117. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  118. esac
  119. ;;
  120. status)
  121. is_running
  122. stat=$?
  123. case "$stat" in
  124. 0) log_daemon_msg "$DESC $NAME is running" ;;
  125. 1) log_daemon_msg "could not access pidfile for $DESC $NAME" ;;
  126. *) log_daemon_msg "$DESC $NAME is not running" ;;
  127. esac
  128. exit "$stat"
  129. ;;
  130. #reload|force-reload)
  131. #
  132. # If do_reload() is not implemented then leave this commented out
  133. # and leave 'force-reload' as an alias for 'restart'.
  134. #
  135. #log_daemon_msg "Reloading $DESC" "$NAME"
  136. #do_reload
  137. #log_end_msg $?
  138. #;;
  139. restart|force-reload)
  140. #
  141. # If the "reload" option is implemented then remove the
  142. # 'force-reload' alias
  143. #
  144. log_daemon_msg "Restarting $DESC" "$NAME"
  145. do_stop
  146. case "$?" in
  147. 0|1)
  148. do_start
  149. case "$?" in
  150. 0) log_end_msg 0 ;;
  151. 1) log_end_msg 1 ;; # Old process is still running
  152. *) log_end_msg 1 ;; # Failed to start
  153. esac
  154. ;;
  155. *)
  156. # Failed to stop
  157. log_end_msg 1
  158. ;;
  159. esac
  160. ;;
  161. *)
  162. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  163. exit 3
  164. ;;
  165. esac
  166.  
  167. :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement