You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by wi...@apache.org on 2020/11/02 08:58:26 UTC

[incubator-streampipes-installer] branch dev updated: [STREAMPIPES-251] Add stop/start command to CLI, modified restart command with force-create option

This is an automated email from the ASF dual-hosted git repository.

wiener pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-installer.git


The following commit(s) were added to refs/heads/dev by this push:
     new 63d472a  [STREAMPIPES-251] Add stop/start command to CLI, modified restart command with force-create option
63d472a is described below

commit 63d472aa80cff13b76979197fef2be94da6ccdd3
Author: Patrick Wiener <wi...@fzi.de>
AuthorDate: Mon Nov 2 09:57:48 2020 +0100

    [STREAMPIPES-251] Add stop/start command to CLI, modified restart command with force-create option
---
 cli/README.md                  | 30 ++++++++++++++++----
 cli/bin/commands/ps            | 30 +++++++++++++++++---
 cli/bin/commands/restart       | 64 ++++++++++++++++++++++++++++--------------
 cli/bin/commands/{ps => start} | 26 +++++++++++------
 cli/bin/commands/{ps => stop}  | 26 +++++++++++------
 cli/streampipes                | 12 ++++++--
 6 files changed, 138 insertions(+), 50 deletions(-)

diff --git a/cli/README.md b/cli/README.md
index 0b9ece4..1d03684 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -71,7 +71,9 @@ Commands:
   logs        Get container logs for specific container
   ps          List all StreamPipes container for running environment
   pull        Download latest images from Dockerhub
-  restart     Restart StreamPipes environment
+  restart     Restart StreamPipes container
+  start       Start StreamPipes container
+  stop        Stop StreamPipes container
   up          Create and start StreamPipes container environment
 
 Run 'streampipes COMMAND --help' for more info on a command.
@@ -130,6 +132,13 @@ streampipes up -d kafka consul
 streampipes env
 ```
 
+**List containers** of environment.
+```bash
+streampipes ps
+# include also stopped container
+streampieps ps --all
+```
+
 **Get logs** of specific service and use optional `--follow` flag to stay attached to the logs.
 ```bash
 streampipes logs --follow backend
@@ -140,11 +149,22 @@ streampipes logs --follow backend
 streampipes pull
 ```
 
-**Restart** all services of current environment or specific services
+**Stop** existing StreamPipes containers
+```bash
+streampipes stop pipeline-elements-all-jvm
+```
+
+**Start** existing StreamPipes containers
+```bash
+streampipes start pipeline-elements-all-jvm
+```
+
+**Restart** existing services
 ```bash
-streampipes restart
-# restart backend & consul
-# streampipes restart backend consul
+# restart backend consul container
+streampipes restart backend consul
+# restart existing services by removing and recreating container instance
+streampipes restart --force-create pipeline-elements-all-jvm
 ```
 
 **Clean** your system and remove created StreamPipes Docker volumes, StreamPipes docker network and dangling StreamPipes images of old image layers.
diff --git a/cli/bin/commands/ps b/cli/bin/commands/ps
index 455c1bd..4a70e80 100755
--- a/cli/bin/commands/ps
+++ b/cli/bin/commands/ps
@@ -16,11 +16,16 @@
 set -e
 . "$STREAMPIPES_WORKDIR/bin/common"
 
+list_stopped_containers=false
+
 cli_help_ps() {
   cat << EOF
-List all StreamPipes containers, volumes for running environment
+List all StreamPipes containers
+
+Usage: streampipes ps [OPTIONS]
 
-Usage: streampipes ps
+Options:
+  -a, --all    Show all stopped containers
 EOF
 
   exit 1
@@ -28,13 +33,30 @@ EOF
 
 [ "$1" == '--help' ] || [ "$1" == '-h' ] && cli_help_ps
 
-if [ "$#" -gt 1 ]; then
+if [ "$#" -gt 2 ]; then
     fatal "Illegal number of arguments, see 'streampipes ${0##*/} --help'"
 fi
 
+while [[ "$#" -gt 0 ]]; do
+    case $1 in
+        -a|--all) list_stopped_containers=true; shift ;;
+        -|--*=) fatal "Unsupported flag $1, see 'streampipes ${0##*/} --help'" >&2 ; shift ;;
+        *) fatal "Wrong usage, see 'streampipes ${0##*/} --help'" ;;
+    esac
+done
+
 if is_streampipes_running; then
   project_name=$(sed -n 's/^COMPOSE_PROJECT_NAME=//p' $STREAMPIPES_WORKDIR/.env)
-  docker ps --filter "name=${project_name}_*" --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'
+  if [ "$list_stopped_containers" = true ]; then
+    docker ps \
+        --filter "name=${project_name}_*" \
+        --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}' \
+        --all
+  else
+    docker ps \
+      --filter "name=${project_name}_*" \
+      --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'
+  fi
 else
   info "No StreamPipes environment running"
 fi
diff --git a/cli/bin/commands/restart b/cli/bin/commands/restart
index da02241..a343b6b 100755
--- a/cli/bin/commands/restart
+++ b/cli/bin/commands/restart
@@ -16,18 +16,16 @@
 set -e
 . "$STREAMPIPES_WORKDIR/bin/common"
 
+remove_container=false
+
 cli_help_restart() {
   cat <<EOF
-Restart StreamPipes environment or individual services
-
-Usage: streampipes restart [SERVICE...]
+Restart running StreamPipes containers
 
-Example:
-# Restart complete StreamPipes environment
-streampipes restart
+Usage: streampipes restart [OPTIONS] [SERVICE...]
 
-# Restart individual services in StreamPipes environment
-streampipes restart backend consul
+Options:
+  -f, --force-create   Remove container before restarting
 EOF
 
   exit 1
@@ -35,21 +33,45 @@ EOF
 
 [ "$1" == '--help' ] || [ "$1" == '-h' ] && cli_help_restart
 
-if is_streampipes_running; then
+if [ -z "$1" ]; then
+    fatal "Argument missing, see 'streampipes ${0##*/} --help'"
+fi
+
+while [[ "$#" -gt 0 ]]; do
+    case $1 in
+        -f|--force-create) 
+          if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
+            remove_container=true
+            svc=$2
+            shift 2
+          else
+            fatal "Argument for $1 is missing" >&2
+          fi
+          ;;
+        -*|--*=) fatal "Unsupported flag $1, see 'streampipes ${0##*/} --help'" >&2 ;;
+        *) svc+=("$1"); shift ;;
+    esac
+done
 
-  if [ -z "$1" ]; then
-    get_curr_environment
+remove_and_restart() {
+    info "Removing and restarting ${svc[*]}"
     concatenate_compose_files
-    info "Restarting all services in environment: '$curr_environment'"
-    run "$docker_compose_files restart"
-  else
-    for svc in "$@"
-    do
-      info "Restarting $svc"
-      concatenate_compose_files
-      run "$docker_compose_files restart $svc"
-    done
-  fi
+    run "$docker_compose_files rm --stop -f ${svc[*]}"
+    run "$docker_compose_files up -d ${svc[*]}"
+}
+
+restart() {
+    info "Restarting ${svc[*]}"
+    concatenate_compose_files
+    run "$docker_compose_files restart ${svc[*]}"  
+}
+
+if is_streampipes_running; then
+    if [ "$remove_container" = true ]; then
+      remove_and_restart
+    else
+      restart
+    fi
 else
   info "No StreamPipes environment running"
 fi
diff --git a/cli/bin/commands/ps b/cli/bin/commands/start
similarity index 64%
copy from cli/bin/commands/ps
copy to cli/bin/commands/start
index 455c1bd..327f7ca 100755
--- a/cli/bin/commands/ps
+++ b/cli/bin/commands/start
@@ -16,25 +16,33 @@
 set -e
 . "$STREAMPIPES_WORKDIR/bin/common"
 
-cli_help_ps() {
-  cat << EOF
-List all StreamPipes containers, volumes for running environment
+cli_help_start() {
+  cat <<EOF
+Start existing StreamPipes containers
 
-Usage: streampipes ps
+Usage: streampipes start [SERVICE...]
 EOF
 
   exit 1
 }
 
-[ "$1" == '--help' ] || [ "$1" == '-h' ] && cli_help_ps
+[ "$1" == '--help' ] || [ "$1" == '-h' ] && cli_help_start
 
-if [ "$#" -gt 1 ]; then
-    fatal "Illegal number of arguments, see 'streampipes ${0##*/} --help'"
+if [ -z "$1" ]; then
+    fatal "Argument missing, see 'streampipes ${0##*/} --help'"
 fi
 
+while [[ "$#" -gt 0 ]]; do
+    case $1 in
+        -*|--*=) fatal "Unsupported flag $1, see 'streampipes ${0##*/} --help'" >&2 ;;
+        *) svc+=("$1"); shift ;;
+    esac
+done
+
 if is_streampipes_running; then
-  project_name=$(sed -n 's/^COMPOSE_PROJECT_NAME=//p' $STREAMPIPES_WORKDIR/.env)
-  docker ps --filter "name=${project_name}_*" --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'
+    info "Starting ${svc[*]}"
+    concatenate_compose_files
+    run "$docker_compose_files start ${svc[*]}"
 else
   info "No StreamPipes environment running"
 fi
diff --git a/cli/bin/commands/ps b/cli/bin/commands/stop
similarity index 64%
copy from cli/bin/commands/ps
copy to cli/bin/commands/stop
index 455c1bd..f194c5f 100755
--- a/cli/bin/commands/ps
+++ b/cli/bin/commands/stop
@@ -16,25 +16,33 @@
 set -e
 . "$STREAMPIPES_WORKDIR/bin/common"
 
-cli_help_ps() {
-  cat << EOF
-List all StreamPipes containers, volumes for running environment
+cli_help_stop() {
+  cat <<EOF
+Stop individual StreamPipes containers
 
-Usage: streampipes ps
+Usage: streampipes stop [SERVICE...]
 EOF
 
   exit 1
 }
 
-[ "$1" == '--help' ] || [ "$1" == '-h' ] && cli_help_ps
+[ "$1" == '--help' ] || [ "$1" == '-h' ] && cli_help_stop
 
-if [ "$#" -gt 1 ]; then
-    fatal "Illegal number of arguments, see 'streampipes ${0##*/} --help'"
+if [ -z "$1" ]; then
+    fatal "Argument missing, see 'streampipes ${0##*/} --help'"
 fi
 
+while [[ "$#" -gt 0 ]]; do
+    case $1 in
+        -*|--*=) fatal "Unsupported flag $1, see 'streampipes ${0##*/} --help'" >&2 ;;
+        *) svc+=("$1"); shift ;;
+    esac
+done
+
 if is_streampipes_running; then
-  project_name=$(sed -n 's/^COMPOSE_PROJECT_NAME=//p' $STREAMPIPES_WORKDIR/.env)
-  docker ps --filter "name=${project_name}_*" --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'
+    info "Stopping ${svc[*]}"
+    concatenate_compose_files
+    run "$docker_compose_files stop ${svc[*]}"
 else
   info "No StreamPipes environment running"
 fi
diff --git a/cli/streampipes b/cli/streampipes
index bfa9b24..fd75255 100755
--- a/cli/streampipes
+++ b/cli/streampipes
@@ -36,7 +36,9 @@ Commands:
   logs        Get container logs for specific container
   ps          List all StreamPipes container for running environment
   pull        Download latest images from Dockerhub
-  restart     Restart StreamPipes environment
+  restart     Restart StreamPipes container
+  start       Start StreamPipes container
+  stop        Stop StreamPipes container
   up          Create and start StreamPipes container environment
 
 Run '$cli_name COMMAND --help' for more info on a command.
@@ -65,7 +67,7 @@ case "$1" in
   #   "$STREAMPIPES_WORKDIR/bin/commands/deploy" "$2"
   #   ;;
   ps)
-    "$STREAMPIPES_WORKDIR/bin/commands/ps" "$2"
+    "$STREAMPIPES_WORKDIR/bin/commands/ps" "${@:2}"
     ;;
   pull)
     "$STREAMPIPES_WORKDIR/bin/commands/pull" "$2"
@@ -73,6 +75,12 @@ case "$1" in
   restart)
     "$STREAMPIPES_WORKDIR/bin/commands/restart" "${@:2}"
     ;;
+  start)
+    "$STREAMPIPES_WORKDIR/bin/commands/start" "${@:2}"
+    ;;
+  stop)
+    "$STREAMPIPES_WORKDIR/bin/commands/stop" "${@:2}"
+    ;;
   up)
     "$STREAMPIPES_WORKDIR/bin/commands/up" "${@:2}"
     ;;