-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_manager
executable file
·190 lines (167 loc) · 6.91 KB
/
start_manager
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/bash
# ---------------------------------------------------------------------------
# start_manager - Starts a daeploy manager on this machine
# Copyright 2020, [email protected]
# All rights reserved.
# Usage: start_manager [-h|--help] [-v|--version version] [-d|--docker-username docker_username] [-t|--docker-token docker_token] [-n|--host-name host_name] [-p|--http-port http_port] [-P|--https-port https_port] [-A|--auth-enabled] [-l|--log-level log_level] [-a|--disable-access-logs] [-H|--https-enabled] [-s|--https-staging-server] [-e|--config-email email] [-E|--config-password password] [-S|--smtp-server smtp_server] [-N|--smtp-port smtp_port]
# Revision history:
# 2020-12-21 Created by new_script ver. 3.3
# ---------------------------------------------------------------------------
PROGNAME=${0##*/}
VERSION="0.1"
clean_up() { # Perform pre-exit housekeeping
return
}
error_exit() {
echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
clean_up
exit 1
}
graceful_exit() {
clean_up
exit
}
signal_exit() { # Handle trapped signals
case $1 in
INT)
error_exit "Program interrupted by user" ;;
TERM)
echo -e "\n$PROGNAME: Program terminated" >&2
graceful_exit ;;
*)
error_exit "$PROGNAME: Terminating on unknown signal" ;;
esac
}
usage() {
echo -e "Usage: $PROGNAME -v version [-h|--help] [-d|--docker-username docker_username] [-t|--docker-token docker_token] [-n|--host-name host_name] [-p|--http-port http_port] [-P|--https-port https_port] [-A|--auth-enabled] [-l|--log-level log_level] [-a|--disable-access-logs] [-H|--https-enabled] [-s|--https-staging-server] [-e|--config-email email] [-E|--config-password password] [-S|--smtp-server smtp_server] [-N|--smtp-port smtp_port] [-w|--admin-password admin_password]"
}
help_message() {
cat <<- _EOF_
$PROGNAME ver. $VERSION
Starts a daeploy manager on this machine.
$(usage)
Options:
-h, --help Display this help message and exit.
-v, --version Manager version. Mandatory argument
Where 'version' is the manager version to start up.
-d, --docker-username Docker username
Where 'docker_username' is the username to docker hub.
-t, --docker-token Docker token
where 'docker_token' is the docker token.
-n, --host-name host_name Host name
Where 'host_name' is the host name.
-p, --http-port http_port Proxy HTTP port
Where 'http_port' is the HTTP port of the proxy.
-P, --https-port https_port Proxy HTTPS port
Where 'https_port' is the HTTPS port of the proxy.
-A, --auth-enabled Authentication enabled
-l, --log-level log_level Log level
Where 'log_level' is the DEBUG, INFO, WARNING or CRITICAL.
-a, --disable-access-logs Disable access logs
-H, --https-enabled Enable HTTPS
-s, --https-staging-server HTTPS staging server, for testing
-e, --config-email email Configuration email for sending notification emails and getting SSL certificate notification
Where 'email' is the email address.
-E, --config-password password Configuration email password
Where 'password' is the Password for the configuration email and the smtp server.
-S, --smtp-server smtp_server SMTP email server for sending email notifications
Where 'smtp_server' is the smtp server url.
-N, --smtp-port smtp_port SMTP server port, usually 465 or 587
Where 'smtp_port' is the port.
-w --admin-password Password for admin user
Where admin_password is the password for the admin user.
_EOF_
return
}
# Trap signals
trap "signal_exit TERM" TERM HUP
trap "signal_exit INT" INT
environ=""
# Parse command-line
while [[ -n $1 ]]; do
case $1 in
-h | --help)
help_message; graceful_exit ;;
-v | --version)
echo "Manager version"; shift; version="$1" ;;
-d | --docker-username)
echo "Docker username"; shift; docker_username="$1" ;;
-t | --docker-token)
echo "Docker token"; shift; docker_token="$1" ;;
-i | --image-path)
echo "Manager image path"; shift; image_path="$1" ;;
-n | --host-name)
echo "Host name"; shift; environ="$environ -e DAEPLOY_HOST_NAME=$1" ;;
-p | --http-port)
echo "Proxy HTTP port"; shift; http_port="$1"; environ="$environ -e DAEPLOY_PROXY_HTTP_PORT=$http_port" ;;
-P | --https-port)
echo "Proxy HTTPS port"; shift; https_port="$1"; environ="$environ -e DAEPLOY_PROXY_HTTPS_PORT=$https_port" ;;
-A | --auth-enabled)
echo "Authentication enabled"; environ="$environ -e DAEPLOY_AUTH_ENABLED=true" ;;
-l | --log-level)
echo "Log level"; shift; environ="$environ -e DAEPLOY_LOG_LEVEL=$1" ;;
-a | --disable-access-logs)
echo "Disabled access logs"; environ="$environ -e DAEPLOY_ACCESS_LOGS_ENABLED=false" ;;
-H | --https-enabled)
echo "Enable HTTPS"; environ="$environ -e DAEPLOY_PROXY_HTTPS=true" ;;
-s | --https-staging-server)
echo "HTTPS staging server, for testing"; environ="$environ -e DAEPLOY_HTTPS_STAGING_SERVER=true" ;;
-e | --config-email)
echo "Configuration email for sending notification emails and getting SSL certificate notification"; shift; environ="$environ -e DAEPLOY_CONFIG_EMAIL=$1" ;;
-E | --config-password)
echo "Configuration email password"; shift; environ="$environ -e DAEPLOY_CONFIG_EMAIL_PASSWORD=$1" ;;
-S | --smtp-server)
echo "SMTP email server for sending email notifications"; shift; environ="$environ -e DAEPLOY_NOTIFICATION_SMTP_SERVER=$1" ;;
-N | --smtp-port)
echo "SMTP server port, usually 465 or 587"; shift; environ="$environ -e DAEPLOY_NOTIFICATION_SMTP_PORT=$1" ;;
-w | --admin-password)
echo "Admin password"; shift; environ="$environ -e DAEPLOY_ADMIN_PASSWORD=$1" ;;
-* | --*)
usage
error_exit "Unknown option $1" ;;
*)
echo "Argument $1 to process..." ;;
esac
shift
done
# Main logic
# Setting default values
if [[ -z $http_port ]]; then
http_port=80
fi
if [[ -z $https_port ]]; then
https_port=443
fi
if [[ -z $version ]]; then
version=latest
fi
# Download the image from docker or get it from a file
if [[ -z $docker_username || -z $docker_token ]]; then
if [[ -z $image_path ]]; then
echo "No image path or docker credentials given."
echo "Will pull manager image with without logging in"
else
docker load -i $image_path
fi
else
echo "Logging in to docker account"
docker login -u $docker_username -p $docker_token
fi
echo "Stopping and removing current Docker container:"
docker rm -f daeploy_manager
echo "Creating docker volume for persistent db storage:"
docker volume create daeploy_data
echo "Running version $version of the daeploy Manager"
docker run \
--name daeploy_manager \
-v /var/run/docker.sock:/var/run/docker.sock \
-v daeploy_data:/data \
-p $http_port:$http_port \
-p $https_port:$https_port \
$environ \
--restart always \
--log-driver json-file \
--log-opt max-size=100m \
--log-opt max-file=5 \
-d daeploy/manager:$version
graceful_exit