-
Notifications
You must be signed in to change notification settings - Fork 6
/
connect.sh
executable file
·84 lines (79 loc) · 3.01 KB
/
connect.sh
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash -e
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <service> [action]"
echo " action"
echo " bash : starts an interactive bash console (default)"
echo " log : get the full service log"
echo " tail : get a tailf of the service log"
echo " restart : restart the process in the container"
echo " jstack : create a jstack of the Java process in the container"
echo " <cmd> : execute any command directly"
fi
CONTAINER=$1
SERVICE=$(echo $CONTAINER | grep -o -e '^[^0-9]*')
if [ "$#" == "1" ]; then
ACTION=bash
else
shift
ACTION=$*
if [ "$SERVICE" == "cassandra" ]; then
LOG=/var/log/cassandra/system.log
elif [ "$SERVICE" == "elasticsearch" ]; then
LOG=/var/log/elasticsearch/coscale.log
elif [ "$SERVICE" == "postgresql" ]; then
LOG=/var/log/postgresql/postgresql-9.3-main.log
elif [ "$SERVICE" == "memcached" ]; then
LOG=/var/log/memcached.log
elif [ "$SERVICE" == "rabbitmq" ]; then
LOG=/var/log/rabbitmq/rabbit*.log
elif [ "$SERVICE" == "rum" ]; then
LOG=/var/log/nginx/*.log
elif [ "$SERVICE" == "streamingroller" ]; then
DOCKER_LOGS=true
elif [ "$SERVICE" == "streamingrollerwriteback" ]; then
DOCKER_LOGS=true
elif [ "$SERVICE" == "streamingtriggermatcher" ]; then
DOCKER_LOGS=true
elif [ "$SERVICE" == "anomalyaggregator" ]; then
DOCKER_LOGS=true
elif [ "$SERVICE" == "anomalydetector" ]; then
DOCKER_LOGS=true
elif [ "$SERVICE" == "kafka" ]; then
DOCKER_LOGS=true
elif [ "$SERVICE" == "zookeeper" ]; then
DOCKER_LOGS=true
elif [ "$SERVICE" == "kafkamirror" ]; then
DOCKER_LOGS=true
else
LOG=/var/log/$SERVICE/current
fi
if [ "$ACTION" == "log" ] && [ "$DOCKER_LOGS" != "true" ]; then
ACTION="cat $LOG"
elif [ "$ACTION" == "tail" ] && [ "$DOCKER_LOGS" != "true" ]; then
ACTION="tail -f -n 100 $LOG"
elif [ "$ACTION" == "jstack" ]; then
ACTION='jstack `ps aux | grep java | grep -v grep | awk '"'"'{ print $2; }'"'"'`'
elif [ "$ACTION" == "restart" ]; then
ACTION="sv restart $SERVICE"
if [ "$SERVICE" == "app" ] || [ "$SERVICE" == "api" ]; then
ACTION="rm /opt/coscale/$SERVICE/RUNNING_PID && $ACTION"
elif [ "$SERVICE" == "rum" ]; then
ACTION="/etc/init.d/nginx restart"
elif [ "$SERVICE" == "rabbitmq" ]; then
ACTION="/etc/init.d/rabbitmq-server restart"
elif [ "$SERVICE" == "cassandra" ] || [ "$SERVICE" == "memcached" ] || [ "$SERVICE" == "postgresql" ] || [ "$SERVICE" == "elasticsearch" ]; then
ACTION="/etc/init.d/$SERVICE restart"
elif [ "$SERVICE" == "haproxy" ]; then
ACTION="killall haproxy; /etc/init.d/haproxy start"
fi
fi
fi
if [ "$SERVICE" == "postgresql" ] && [ "$1" == "psql" ]; then
docker exec -it coscale_$CONTAINER /bin/bash -c "PGPASSWORD=coscale psql -h localhost -U coscale -d app"
elif [ "$ACTION" == "log" ]; then
docker logs coscale_$CONTAINER
elif [ "$ACTION" == "tail" ]; then
docker logs -f --tail 100 coscale_$CONTAINER
else
docker exec -it coscale_$CONTAINER /bin/bash -c "export TERM=xterm && $ACTION"
fi