summaryrefslogtreecommitdiff
path: root/scripts/ctrlroom/sydra-manager.sh
blob: bd6c24ba87f258ef09914779d5db88e2bee47ee0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash

############################

ROOT_D="$1"
GROUP_NAME="$2"

############################

printUsage() {
  echo "Usage: $0 <basedir> <groupname>"
}

if [ -z "$ROOT_D" ] || [ -z "$GROUP_NAME" ]; then
  printUsage
  exit 1
fi
if [ ! -d "$ROOT_D" ]; then
  echo "ERROR: can't change to non-existent directory: $ROOT_D"
  exit 2
fi

. ./include.sh

PIPE="$ROOT_D/sydra-manager.sock"
trap "rm -f $PIPE" EXIT
if [[ ! -p $PIPE ]]; then
    mkfifo $PIPE
fi

cd "$ROOT_D"
MAIN_STAT_FILE="sydra-receiver.main"
echo "00" > $MAIN_STAT_FILE

while true
do
    if read line <$PIPE; then
        cmd=${line%% *}
        arg=${line##* }
        case $cmd in
          restart)
            get_num $arg
            if [ -z "$NUM" ]; then NUM=$arg; fi
            supervisorctl restart "$GROUP_NAME:$NUM"
            NUM=''
            ;;
          select)
            get_num $arg
            if [ -n "$NUM" ]; then
              echo "$NUM" > $MAIN_STAT_FILE
              supervisorctl restart "$GROUP_NAME:main"
            else
              echo "unkown client: $arg" >&2
            fi
            NUM=''
            ;;
          reloadconfig)
            kill -SIGHUP `cat supervisord.pid`
            ;;
          killall)
            kill `cat supervisord.pid`
            ;;
          *)
            echo "unkown command: $cmd" >&2
            ;;
        esac
    fi
done

exit 0