-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdruml-remote-ac-command.sh
executable file
·58 lines (47 loc) · 1.27 KB
/
druml-remote-ac-command.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
#!/bin/bash
# Get Druml dir.
SCRIPT_DIR=$1
shift
# Load includes.
source $SCRIPT_DIR/druml-inc-init.sh
# Display help.
if [[ ${#ARG[@]} -lt 2 || -n $PARAM_HELP ]]
then
echo "usage: druml remote-ac-command [--config=<path>] [--docroot=<path>]"
echo " [--server=<number>]"
echo " <environment> <command>"
exit 1
fi
# Read parameters.
SUBSITE=$(get_site_alias $PARAM_SITE)
ENV=$(get_environment ${ARG[1]})
COMMAND=${ARG[2]}
# Set variables.
DRUSH=$(get_drush_command)
DRUSH_ALIAS=$(get_drush_alias $ENV)
SSH_ARGS=$(get_ssh_args $ENV $PARAM_SERVER)
PROXY_PARAM_SERVER=$(get_param_proxy "server")
# Say Hello.
echo "=== Executing AC commands on $ENV"
echo ""
echo "Command to be executed:"
echo "$COMMAND"
OUTPUT=$(ssh -Tn $SSH_ARGS "$DRUSH $DRUSH_ALIAS $COMMAND" 2>&1)
RESULT="$?"
TASK=$(echo $OUTPUT | awk '{print $2}')
if [[ $TASK == ":" ]]; then
TASK=$(echo $OUTPUT | awk '{print $3}')
fi
# Eixt upon an error.
if [[ $RESULT > 0 ]]; then
echo "Error executing command."
exit 1
fi
echo "Command execution scheduled, task id is $TASK."
# Check task status.
run_script remote-ac-status $PROXY_PARAM_SERVER $ENV $TASK
if [[ $? > 0 ]]; then
echo "Command execution failed!"
exit 1
fi
echo "Command execution completed!"