-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.sh
executable file
·96 lines (80 loc) · 2.17 KB
/
server.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
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
usage()
{
cat << EOF
USAGE: `basename $0` [options]
-u bring up the server instance
-d bring down the server instance
-i Cromwell server instance ID
-k path to your EC2 keypair for SSH login
-r AWS region
EOF
}
server_up()
{
aws ec2 start-instances \
--instance-ids ${instance_id} \
--region ${region}
aws ec2 wait instance-status-ok \
--instance-ids ${instance_id} \
--region ${region}
# get public DNS name
addr=`aws ec2 describe-instances --instance-ids ${instance_id} --region ${region} --query "Reservations[0].Instances[0].{Instance:PublicDnsName}" --output text`
echo "Cromwell server address: ${addr}"
ssh -i ${keypair} ec2-user@${addr} ./startup.sh
# send ready message to Slack
if [ "$slack_hook_key" != "null" ]
then
python3 notify_slack.py \
--hook-key="${slack_hook_key}" \
--message="Cromwell/Job Manager is available at http://${addr}:4200"
fi
echo "Cromwell/Job Manager is available at http://${addr}:4200"
}
server_down()
{
aws ec2 stop-instances \
--instance-ids ${instance_id} \
--region ${region}
aws ec2 wait instance-stopped \
--instance-ids ${instance_id} \
--region ${region}
# send ready message to Slack
if [ "$slack_hook_key" != "null" ]
then
python3 notify_slack.py \
--hook-key="${slack_hook_key}" \
--message="Cromwell/Job Manager is stopped."
fi
echo "Cromwell/Job Manager is stopped."
}
while getopts "udi:k:r:h" OPTION
do
case $OPTION in
u) action="up" ;;
d) action="down" ;;
i) instance_id=$OPTARG ;;
k) keypair=$OPTARG ;;
r) region=$OPTARG ;;
h) usage; exit 1 ;;
*) usage; exit 1 ;;
esac
done
if [ -z "$instance_id" ] || [ -z "$keypair" ] || [ -z "$region" ]
then
usage
exit 1
fi
# get slack hook key
slack_hook_key=`aws ssm get-parameters --name="scata-slack-noti-dev" --query="Parameters[0].Value" --region ${region} | sed 's/"//g'`
if [ "$action" == 'up' ]
then
server_up
exit 0
fi
if [ "$action" == 'down' ]
then
server_down
exit 0
fi
usage