-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathndeploy-nc.sh
91 lines (67 loc) · 2.09 KB
/
ndeploy-nc.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
#!/bin/bash
# Put all other nodes but this local machine inside the parentheses separated by spaces
NODES=()
# Put the path for the application server inside the quotation marks
APPSRV_HOME=""
# This is where this script will watch for files to deploy
CLUSTER_DEPLOY_DIR="${APPSRV_HOME}/ndeploy/deploy"
# Change to the correct path for the deploy dir of your application server
APPSRV_DEPLOY_DIR="${APPSRV_HOME}/webapps"
##
show_usage() {
echo "Usage: $0 <options>"
echo
echo "Options:"
echo -e " -d, --daemon \t\t\t\t\t\t Daemon mode monitoring $CLUSTER_DEPLOY_DIR directory."
echo -e " -i, --install, --deploy <application.war> \t\t Deploy .war application."
echo -e " -u, --uninstall, --undeploy <application.war> \t\t Undeploy .war application."
echo -e " -h, --help \t\t\t\t\t\t Show this message."
}
deploy() {
rsync $opts --del "$1" "${APPSRV_DEPLOY_DIR}" &
for node in "${NODES[@]}"; do
tar -c "$1" | ./nc.openbsd -q 0 $node 3300 &
done
wait
}
undeploy() {
app="${APPSRV_DEPLOY_DIR}/${1##*/}"
app="${app%/}"
if [[ -a "$app" ]]; then
rm -rf "$app"
for node in "${NODES[@]}"; do
ssh "$node" rm -rf "$app"
done
else
echo "ERROR: The application $1 does not exist!" >&2
exit 1
fi
}
daemon_mode() {
./nc.openbsd -l -k -p 3300 | tar x -C "$APPSRV_DEPLOY_DIR" &
while true; do
if [[ $(ls -A "${CLUSTER_DEPLOY_DIR}") ]]; then
for app in "${CLUSTER_DEPLOY_DIR}"/*; do
deploy "${app}"
rm -rf "${app}"
done
fi
sleep 5
done
}
first_param="${@:1}"
if [[ $# -eq 0 || "${first_param:0:1}" != "-" ]]; then show_usage; exit 1; fi
SHORTOPTS="di:u:h"
LONGOPTS="daemon,install:,deploy:,uninstall:,undeploy:,help"
ARGS=$(getopt --name $0 --longoptions="$LONGOPTS" --options="$SHORTOPTS" -- "$@")
eval set -- "$ARGS"
while true; do
case "$1" in
-d|--daemon) daemon_mode; shift ;;
-i|--install|--deploy) deploy "$2"; shift 2 ;;
-u|--uninstall|--undeploy) undeploy "$2"; shift 2 ;;
-h|--help) show_usage; exit 0 ;;
--) shift; break ;;
*) show_usage; exit 1 ;;
esac
done