|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +SERVICE="cloudstack-usage" |
| 4 | +DESC="usage server" |
| 5 | + |
| 6 | +MGMT_SERVICE="cloudstack-management" |
| 7 | +USAGE_SERVICE="cloudstack-usage" |
| 8 | + |
| 9 | +find_pids() { |
| 10 | + service=$1 |
| 11 | + pids=$(ps aux |grep "[j]ava" |grep "$service" |awk '{print $2}') |
| 12 | + echo $pids |
| 13 | +} |
| 14 | + |
| 15 | +stop_pid() { |
| 16 | + pids=$1 |
| 17 | + for pid in $pids;do |
| 18 | + kill $pid |
| 19 | + done |
| 20 | +} |
| 21 | + |
| 22 | +start_management() { |
| 23 | + source /etc/default/cloudstack-management |
| 24 | + tini -- /usr/bin/java $JAVA_DEBUG $JAVA_OPTS -cp $CLASSPATH $BOOTSTRAP_CLASS > /dev/null 2>&1 & |
| 25 | +} |
| 26 | + |
| 27 | +start_usage() { |
| 28 | + source /etc/default/cloudstack-usage |
| 29 | + tini -- /usr/bin/java -Dpid=$$ $JAVA_OPTS $JAVA_DEBUG -cp $CLASSPATH $JAVA_CLASS > /dev/null 2>&1 & |
| 30 | +} |
| 31 | + |
| 32 | +start_service() { |
| 33 | + service=$1 |
| 34 | + if [ "$service" = "$MGMT_SERVICE" ];then |
| 35 | + start_management |
| 36 | + elif [ "$service" = "$USAGE_SERVICE" ];then |
| 37 | + start_usage |
| 38 | + fi |
| 39 | +} |
| 40 | + |
| 41 | +process_status() { |
| 42 | + service=$1 |
| 43 | + pids=$(find_pids $SERVICE) |
| 44 | + if [ "$pids" != "" ];then |
| 45 | + echo >&2 "CloudStack $DESC is running with pid $pids" |
| 46 | + else |
| 47 | + echo >&2 "CloudStack $DESC is stopped" |
| 48 | + fi |
| 49 | +} |
| 50 | + |
| 51 | +process() { |
| 52 | + action=$1 |
| 53 | + if [ "$action" = "status" ] || [ "$action" = "" ];then |
| 54 | + process_status $SERVICE |
| 55 | + fi |
| 56 | + pids=$(find_pids $SERVICE) |
| 57 | + if [ "$pids" != "" ];then |
| 58 | + if [ "$action" = "start" ];then |
| 59 | + echo >&2 "CloudStack $DESC is running with pid $pids" |
| 60 | + action= |
| 61 | + elif [ "$action" = "stop" ] || [ "$action" = "restart" ];then |
| 62 | + echo >&2 "Stopping $DESC with pid $pids" |
| 63 | + stop_pid $pids |
| 64 | + echo >&2 "Stopped $DESC with pid $pids" |
| 65 | + fi |
| 66 | + fi |
| 67 | + if [ "$action" = "start" ] || [ "$action" = "restart" ];then |
| 68 | + echo >&2 "Starting $DESC" |
| 69 | + start_service $SERVICE |
| 70 | + echo >&2 "Started $DESC" |
| 71 | + fi |
| 72 | +} |
| 73 | + |
| 74 | +process $1 |
0 commit comments