first - broken - pass at start/stop commands and working expose/expose commands

note that at the moment the iptables calls complete successfully but the container isn't actually exposed. We'll probably need to use the ambassador pattern to do this properly.
This commit is contained in:
Jose Diaz-Gonzalez
2015-08-31 15:29:23 -04:00
parent 075a39fe13
commit ac50d9c37c
3 changed files with 115 additions and 23 deletions

View File

@@ -129,6 +129,18 @@ case "$1" in
service_logs "$2" "$3"
;;
$PLUGIN_COMMAND_PREFIX:start)
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$2"
service_start "$2"
;;
$PLUGIN_COMMAND_PREFIX:stop)
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$2"
service_stop "$2"
;;
$PLUGIN_COMMAND_PREFIX:restart)
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$2"
@@ -171,34 +183,13 @@ case "$1" in
$PLUGIN_COMMAND_PREFIX:expose)
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$2"
SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; PORT_FILE="$SERVICE_ROOT/PORT"; DESTINATION_FILE="$SERVICE_ROOT/IPTABLES_DESTINATION"
[[ -f "$PORT_FILE" ]] && PORT=$(cat "$PORT_FILE") && dokku_log_fail "Service $SERVICE already exposed on port $PORT"
ID=$(cat "$SERVICE_ROOT/ID")
IP=$(get_container_ip "$ID")
PORT=$(get_random_port)
echo "$PORT" > "$PORT_FILE"
echo "$IP:$PLUGIN_DATASTORE_PORT" > "$DESTINATION_FILE"
iptables -t nat -A DOCKER -p tcp --dport "$PORT" -j DNAT --to-destination "$IP:$PLUGIN_DATASTORE_PORT"
dokku_log_info1 "Service $SERVICE exposed on port $PORT"
service_port_expose "$2"
;;
$PLUGIN_COMMAND_PREFIX:unexpose)
[[ -z $2 ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$2"
SERVICE="$2"; SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"; PORT_FILE="$SERVICE_ROOT/PORT"; DESTINATION_FILE="$SERVICE_ROOT/IPTABLES_DESTINATION"
[[ ! -f "$PORT_FILE" ]] && dokku_log_fail "Service not exposed"
ID=$(cat "$SERVICE_ROOT/ID")
IP=$(get_container_ip "$ID")
PORT=$(cat "$PORT_FILE")
DESTINATION=$(cat "$DESTINATION_FILE")
iptables -t nat -D DOCKER -p tcp --dport "$PORT" -j DNAT --to-destination "$DESTINATION"
rm -rf "$PORT_FILE"
service_port_unexpose "$2"
;;
help)