forked from dokku/dokku-graphite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
executable file
·101 lines (84 loc) · 3.91 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
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
#!/usr/bin/env bash
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
if [[ -f "$PLUGIN_AVAILABLE_PATH/docker-options/functions" ]]; then
source "$PLUGIN_AVAILABLE_PATH/docker-options/functions"
fi
# non-generic functions
service_create() {
local SERVICE="$1"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
[[ ! -d "$PLUGIN_DATA_ROOT/$SERVICE" ]] || dokku_log_fail "$PLUGIN_SERVICE service $SERVICE already exists"
SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; LINKS_FILE="$SERVICE_ROOT/LINKS"
if ! docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " ; then
docker pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed"
fi
mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory"
mkdir -p "$SERVICE_ROOT/data" || dokku_log_fail "Unable to create service data directory"
mkdir -p "$SERVICE_ROOT/config" || dokku_log_fail "Unable to create service config directory"
touch "$LINKS_FILE"
password=$(openssl rand -hex 16)
echo "$password" > "$SERVICE_ROOT/PASSWORD"
chmod 640 "$SERVICE_ROOT/PASSWORD"
if [[ -n $GRAPHITE_CUSTOM_ENV ]]; then
echo "$GRAPHITE_CUSTOM_ENV" | tr ';' "\n" > "$SERVICE_ROOT/ENV"
else
echo "" > "$SERVICE_ROOT/ENV"
fi
service_create_container "$SERVICE"
}
service_create_container() {
local SERVICE="$1"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local SERVICE_NAME="$(get_service_name "$SERVICE")"
ID=$(docker run --name "$SERVICE_NAME" -v "$SERVICE_ROOT/data/whisper:/opt/graphite/storage/whisper" -v "$SERVICE_ROOT/data/grafana:/opt/grafana/data" -e "GRAPHITE_PASSWORD=$PASSWORD" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=graphite "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION")
echo "$ID" > "$SERVICE_ROOT/ID"
IP=$(get_container_ip "$ID")
dokku_log_verbose_quiet "Waiting for container to be ready"
docker run --rm --link "$SERVICE_NAME:$PLUGIN_COMMAND_PREFIX" dokkupaas/wait:0.2 -p "$PLUGIN_DATASTORE_WAIT_PORT" > /dev/null
dokku_log_info2 "$PLUGIN_SERVICE container created: $SERVICE"
service_info "$SERVICE"
dokku_log_info1 "Service $SERVICE available under $IP:80"
dokku_log_info1 "Initial login/pass: admin/admin. Please change it on first login"
}
service_export() {
local SERVICE="$1"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
dokku_log_fail "Not yet implemented"
}
service_import() {
local SERVICE="$1"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
dokku_log_fail "Not yet implemented"
}
service_start() {
local SERVICE="$1"
local QUIET="$2"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local SERVICE_NAME="$(get_service_name "$SERVICE")"
local ID=$(docker ps -f status=running | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
if [[ -n $ID ]]; then
[[ -z $QUIET ]] && dokku_log_warn "Service is already started"
return 0
fi
dokku_log_info1_quiet "Starting container"
local PREVIOUS_ID=$(docker ps -f status=exited | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
local IMAGE_EXISTS=$(docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " && true)
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
if [[ -n $PREVIOUS_ID ]]; then
docker start "$PREVIOUS_ID" > /dev/null
service_port_unpause "$SERVICE"
dokku_log_info2 "Container started"
elif $IMAGE_EXISTS && [[ -n "$PASSWORD" ]]; then
service_create_container "$SERVICE"
else
dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE"
fi
}
service_url() {
local SERVICE="$1"
local SERVICE_ALIAS="$(service_alias "$SERVICE")"
echo "$PLUGIN_SCHEME://$SERVICE_ALIAS:${PLUGIN_DATASTORE_PORTS[0]}"
}