-
Notifications
You must be signed in to change notification settings - Fork 6
/
functions
57 lines (46 loc) · 2.36 KB
/
functions
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
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
source "$PLUGIN_AVAILABLE_PATH/domains/functions"
source "$PLUGIN_AVAILABLE_PATH/certs/functions"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions"
monit_build_app_config() {
local app="$1"
local plugin_path="$(dirname "${BASH_SOURCE[0]}")"
local dokku_bin="/usr/bin/dokku"
local template_file="$plugin_path/templates/monit.sigil"
local monit_config_file="$DOKKU_ROOT/$app/monitrc"
local domains=($(get_app_domains "$app"))
local domain="$(escape_domain ${domains[0]})"
local address="localhost"
local ssl=false
local scheme="http"
local port=$(escape_number $(config_get "$app" DOKKU_PROXY_PORT || config_get "$app" DOKKU_NGINX_PORT))
if is_ssl_enabled "$app"; then
local ssl=true
local scheme="https"
local port=$(escape_number $(config_get "$app" DOKKU_PROXY_SSL_PORT || config_get "$app" DOKKU_NGINX_SSL_PORT))
fi
local content="$(escape_string "$(config_get "$app" MONIT_CONTENT || true)")"
local request="$(escape_string "$(config_get "$app" MONIT_REQUEST || true)")"
local alert="$(escape_string "$(config_get "$app" MONIT_ALERT || true)")"
local restart_timeout="$(escape_number "$(config_get "$app" MONIT_RESTART_TIMEOUT || true)")"
local restart_cycles="$(escape_number "$(config_get "$app" MONIT_RESTART_CYCLES || true)")"
local unmonitor_restarts="$(escape_number "$(config_get "$app" MONIT_UNMONITOR_RESTARTS || true)")"
local unmonitor_cycles="$(escape_number "$(config_get "$app" MONIT_UNMONITOR_CYCLES || true)")"
local monit_enabled="$(config_get "$app" MONIT_ENABLED || true)"
sigil -f "$template_file" APP="$app" DOMAIN="$domain" ALERT="$alert" CONTENT="$content" REQUEST="$request" RESTART_TIMEOUT="$restart_timeout" RESTART_CYCLES="$restart_cycles" UNMONITOR_RESTARTS="$unmonitor_restarts" UNMONITOR_CYCLES="$unmonitor_cycles" PORT="$port" SCHEME="$scheme" SSL="$ssl" DOKKU_BIN="$dokku_bin" MONIT_ENABLED="$monit_enabled" ADDRESS="$address" > "$monit_config_file"
}
monit_cmd() {
monit $@
}
monit_reload() {
monit_cmd reload
}
monit_enable() {
config_set --no-restart "$1" "MONIT_ENABLED=true"
}
monit_disable() {
config_unset --no-restart "$1" "MONIT_ENABLED"
}