@@ -62,7 +62,7 @@ fn-services-list() {
62
62
[[ -d $f ]] || continue
63
63
services+=(" $f " )
64
64
done
65
- popd & > /dev/null || pushd " /tmp" > /dev/null
65
+ popd > /dev/null 2>&1 || pushd " /tmp" > /dev/null
66
66
67
67
if [[ " ${# services[@]} " -eq 0 ]]; then
68
68
return
@@ -282,7 +282,7 @@ service_backup() {
282
282
BACKUP_TMPDIR=$( mktemp -d --tmpdir)
283
283
trap ' rm -rf "$BACKUP_TMPDIR" > /dev/null' RETURN INT TERM EXIT
284
284
285
- " $DOCKER_BIN " container inspect " $ID " & > /dev/null || dokku_log_fail " Service container does not exist"
285
+ " $DOCKER_BIN " container inspect " $ID " > /dev/null 2>&1 || dokku_log_fail " Service container does not exist"
286
286
is_container_status " $ID " " Running" || dokku_log_fail " Service container is not running"
287
287
288
288
(service_export " $SERVICE " > " ${BACKUP_TMPDIR} /export" )
@@ -483,7 +483,7 @@ service_enter() {
483
483
local SERVICE_ROOT=" $PLUGIN_DATA_ROOT /$SERVICE "
484
484
local ID=" $( cat " $SERVICE_ROOT /ID" ) "
485
485
486
- " $DOCKER_BIN " container inspect " $ID " & > /dev/null || dokku_log_fail " Service container does not exist"
486
+ " $DOCKER_BIN " container inspect " $ID " > /dev/null 2>&1 || dokku_log_fail " Service container does not exist"
487
487
is_container_status " $ID " " Running" || dokku_log_fail " Service container is not running"
488
488
489
489
local EXEC_CMD=" "
@@ -691,7 +691,7 @@ service_logs() {
691
691
DOKKU_LOGS_ARGS+=" --follow"
692
692
fi
693
693
694
- " $DOCKER_BIN " container inspect " $ID " & > /dev/null || dokku_log_fail " Service container does not exist"
694
+ " $DOCKER_BIN " container inspect " $ID " > /dev/null 2>&1 || dokku_log_fail " Service container does not exist"
695
695
is_container_status " $ID " " Running" || dokku_log_warn " Service logs may not be output as service is not running"
696
696
697
697
# shellcheck disable=SC2086
@@ -810,79 +810,78 @@ service_root_password() {
810
810
811
811
service_port_expose () {
812
812
declare desc=" wrapper for exposing service ports"
813
- declare SERVICE=" $1 "
814
- service_start " $SERVICE " " true"
815
- service_port_unpause " $SERVICE " " true" " ${@: 2} "
816
- }
817
-
818
- service_port_pause () {
819
- declare desc=" pause service exposure"
820
- declare SERVICE=" $1 " LOG_FAIL=" $2 "
813
+ declare SERVICE=" $1 " PORTS=(${@: 2} )
821
814
local SERVICE_ROOT=" $PLUGIN_DATA_ROOT /$SERVICE "
822
- local EXPOSED_NAME=" $( get_service_name " $SERVICE " ) .ambassador"
823
815
local PORT_FILE=" $SERVICE_ROOT /PORT"
816
+ local SERVICE_NAME=" $( get_service_name " $SERVICE " ) "
817
+ local EXPOSED_NAME=" $SERVICE_NAME .ambassador"
824
818
825
- if [[ " $LOG_FAIL " == " true" ]]; then
826
- [[ ! -f " $PORT_FILE " ]] && dokku_log_fail " Service not exposed"
827
- else
828
- [[ ! -f " $PORT_FILE " ]] && return 0
819
+ if [[ ${# PORTS[@]} -eq 0 ]]; then
820
+ # shellcheck disable=SC2206
821
+ PORTS=(${PORTS[@]:- $(get_random_ports ${# PLUGIN_DATASTORE_PORTS[@]} )} )
829
822
fi
830
823
831
- local GREP_NAME=" ^/${EXPOSED_NAME} $"
832
- local CONTAINER_NAME=" $( " $DOCKER_BIN " container ps -f name=" $GREP_NAME " --format " {{.Names}}" ) "
833
- if [[ -z " $CONTAINER_NAME " ]]; then
834
- if [[ " $LOG_FAIL " == " true" ]]; then
835
- dokku_log_info1 " Service $SERVICE unexposed"
836
- fi
824
+ [[ " ${# PORTS[@]} " != " ${# PLUGIN_DATASTORE_PORTS[@]} " ]] && dokku_log_fail " ${# PLUGIN_DATASTORE_PORTS[@]} ports to be exposed need to be provided in the following order: ${PLUGIN_DATASTORE_PORTS[*]} "
837
825
838
- return
826
+ if [[ -s " $PORT_FILE " ]]; then
827
+ # shellcheck disable=SC2207
828
+ PORTS=($( cat " $PORT_FILE " ) )
829
+ dokku_log_fail " Service $SERVICE already exposed on port(s) ${PORTS[*]} "
839
830
fi
840
831
841
- " $DOCKER_BIN " container stop " $EXPOSED_NAME " > /dev/null 2>&1 || true
842
- " $DOCKER_BIN " container rm " $EXPOSED_NAME " > /dev/null 2>&1 || true
843
- if [[ " $LOG_FAIL " == " true " ]] ; then
844
- dokku_log_info1 " Service $SERVICE unexposed "
832
+ if " $DOCKER_BIN " container inspect " $EXPOSED_NAME " > /dev/null 2>&1 ; then
833
+ dokku_log_warn " Service $SERVICE has an untracked expose container, removing "
834
+ " $DOCKER_BIN " container stop " $EXPOSED_NAME " > /dev/null 2>&1 || true
835
+ suppress_output " $DOCKER_BIN " container rm " $EXPOSED_NAME "
845
836
fi
837
+
838
+ echo " ${PORTS[@]} " > " $PORT_FILE "
839
+
840
+ service_start " $SERVICE " " true"
841
+ service_port_reconcile_status " $SERVICE "
842
+ dokku_log_info1 " Service $SERVICE exposed on port(s) [container->host]: $( service_exposed_ports " $SERVICE " ) "
846
843
}
847
844
848
845
service_port_unexpose () {
849
846
declare desc=" wrapper for pausing exposed service ports"
850
847
declare SERVICE=" $1 "
851
848
local SERVICE_ROOT=" $PLUGIN_DATA_ROOT /$SERVICE "
852
849
local PORT_FILE=" $SERVICE_ROOT /PORT"
853
- service_port_pause " $SERVICE " " true "
850
+
854
851
rm -rf " $PORT_FILE "
852
+ service_port_reconcile_status " $SERVICE "
853
+ dokku_log_info1 " Service $SERVICE unexposed"
855
854
}
856
855
857
- service_port_unpause () {
858
- declare desc=" start service exposure"
859
- declare SERVICE=" $1 " LOG_FAIL=" $2 "
856
+ service_port_reconcile_status () {
857
+ declare SERVICE=" $1 "
860
858
local SERVICE_ROOT=" $PLUGIN_DATA_ROOT /$SERVICE "
861
- local SERVICE_NAME=" $( get_service_name " $SERVICE " ) "
862
- local EXPOSED_NAME=" ${SERVICE_NAME} .ambassador"
863
859
local PORT_FILE=" $SERVICE_ROOT /PORT"
864
- # shellcheck disable=SC2068
865
- local PORTS=(${@: 3} )
866
- # shellcheck disable=SC2068
867
- PORTS=(${PORTS[@]:- $(get_random_ports ${# PLUGIN_DATASTORE_PORTS[@]} )} )
868
- local ID=$( cat " $SERVICE_ROOT /ID" )
860
+ local SERVICE_NAME=" $( get_service_name " $SERVICE " ) "
861
+ local EXPOSED_NAME=" $SERVICE_NAME .ambassador"
869
862
870
- [[ " ${# PORTS[@]} " != " ${# PLUGIN_DATASTORE_PORTS[@]} " ]] && dokku_log_fail " ${# PLUGIN_DATASTORE_PORTS[@]} ports to be exposed need to be provided in the following order: ${PLUGIN_DATASTORE_PORTS[*]} "
863
+ if [[ ! -s " $PORT_FILE " ]]; then
864
+ if " $DOCKER_BIN " container inspect " $EXPOSED_NAME " > /dev/null 2>&1 ; then
865
+ " $DOCKER_BIN " container stop " $EXPOSED_NAME " > /dev/null 2>&1 || true
866
+ suppress_output " $DOCKER_BIN " container rm " $EXPOSED_NAME "
867
+ return $?
868
+ fi
869
+ return
870
+ fi
871
871
872
- if [[ " $LOG_FAIL " == " true" ]]; then
873
- [[ -f " $PORT_FILE " ]] && PORTS=($( cat " $PORT_FILE " ) ) && dokku_log_fail " Service $SERVICE already exposed on port(s) ${PORTS[*]} "
874
- else
875
- [[ ! -f " $PORT_FILE " ]] && return 0
876
- PORTS=($( cat " $PORT_FILE " ) )
872
+ if is_container_status " $EXPOSED_NAME " " Running" ; then
873
+ return
877
874
fi
878
875
879
- echo " ${PORTS[@]} " > " $PORT_FILE "
876
+ if " $DOCKER_BIN " container inspect " $EXPOSED_NAME " > /dev/null 2>&1 ; then
877
+ suppress_output " $DOCKER_BIN " container start " $EXPOSED_NAME "
878
+ return $?
879
+ fi
880
880
881
+ # shellcheck disable=SC2207
882
+ PORTS=($( cat " $PORT_FILE " ) )
881
883
# shellcheck disable=SC2046
882
884
" $DOCKER_BIN " container run -d --link " $SERVICE_NAME :$PLUGIN_COMMAND_PREFIX " --name " $EXPOSED_NAME " $( docker_ports_options " ${PORTS[@]} " ) --restart always --label dokku=ambassador --label " dokku.ambassador=$PLUGIN_COMMAND_PREFIX " " $PLUGIN_AMBASSADOR_IMAGE " > /dev/null
883
- if [[ " $LOG_FAIL " == " true" ]]; then
884
- dokku_log_info1 " Service $SERVICE exposed on port(s) [container->host]: $( service_exposed_ports " $SERVICE " ) "
885
- fi
886
885
}
887
886
888
887
service_promote () {
@@ -946,7 +945,9 @@ service_pause() {
946
945
if [[ -n $ID ]]; then
947
946
dokku_log_info2_quiet " Pausing container"
948
947
" $DOCKER_BIN " container stop " $SERVICE_NAME " > /dev/null
949
- service_port_pause " $SERVICE "
948
+ if " $DOCKER_BIN " container inspect " $ID " > /dev/null 2>&1 ; then
949
+ " $DOCKER_BIN " container stop " $SERVICE_NAME .ambassador" > /dev/null 2>&1 || true
950
+ fi
950
951
dokku_log_verbose_quiet " Container paused"
951
952
else
952
953
dokku_log_verbose_quiet " No container exists for $SERVICE "
0 commit comments