|
1 | 1 | #!/usr/bin/env bash |
2 | | -set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x |
| 2 | + |
| 3 | +source "$(dirname $0)/../dokku_common" |
3 | 4 |
|
4 | 5 | case "$1" in |
5 | 6 | apps) |
6 | 7 | echo "=== My Apps" |
7 | 8 | find $DOKKU_ROOT -maxdepth 1 -type d \( ! -iname ".*" \) -not -path $DOKKU_ROOT/tls | sed 's|^\./||g' | sed 's|'$DOKKU_ROOT'\/||' | tail -n +2 | sort |
8 | 9 | ;; |
9 | 10 |
|
10 | | - apps:create) |
11 | | - [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 |
12 | | - [[ -d "$DOKKU_ROOT/$APP" ]] && echo " ! Name is already taken" && exit 1 |
13 | | - APP="$2" |
14 | | - |
15 | | - mkdir -p "$DOKKU_ROOT/$APP" |
16 | | - echo "Creating $APP... done" |
| 11 | + apps:list|list) |
| 12 | + verify_max_args 1 "$@" |
| 13 | + for app in $(ls -d $DOKKU_ROOT/*/ 2>/dev/null); do |
| 14 | + if [[ -f "$app/refs/heads/master" ]]; then |
| 15 | + basename "$app" |
| 16 | + fi |
| 17 | + done |
17 | 18 | ;; |
18 | 19 |
|
19 | | - apps:destroy) |
20 | | - [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 |
21 | | - [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1 |
22 | | - [[ "$2" == "tls" ]] && echo "Unable to destroy tls directory" && exit 1 |
23 | | - APP="$2"; IMAGE="dokku/$APP"; |
24 | | - |
25 | | - echo " ! WARNING: Potentially Destructive Action" |
26 | | - echo " ! This command will destroy $APP (including all add-ons)." |
27 | | - echo " ! To proceed, type \"$APP\"" |
28 | | - echo "" |
29 | | - |
30 | | - read -p "> " app_name |
31 | | - if [[ "$app_name" != "$APP" ]]; then |
32 | | - echo " ! Confirmation did not match $APP. Aborted." |
33 | | - exit 1 |
| 20 | + apps:status|status) |
| 21 | + verify_app_name "$2" |
| 22 | + verify_max_args 2 "$@" |
| 23 | + |
| 24 | + if docker port "$APP_NAME" "$APP_PORT" 1>/dev/null 2>/dev/null |
| 25 | + then |
| 26 | + echo "$APP is running." |
| 27 | + else |
| 28 | + echo "$APP is stopped." |
| 29 | + fi |
| 30 | + ;; |
| 31 | + |
| 32 | + apps:start|start) |
| 33 | + verify_app_name "$2" |
| 34 | + verify_max_args 2 "$@" |
| 35 | + |
| 36 | + docker start "$APP_NAME" |
| 37 | + ;; |
| 38 | + |
| 39 | + apps:stop|stop) |
| 40 | + verify_app_name "$2" |
| 41 | + verify_max_args 2 "$@" |
| 42 | + |
| 43 | + docker stop "$APP_NAME" |
| 44 | + ;; |
| 45 | + |
| 46 | + apps:disable|disable) |
| 47 | + verify_app_name "$2" |
| 48 | + verify_max_args 2 "$@" |
| 49 | + if [[ ! -f "$APP_DIR/DISABLED" ]]; then |
| 50 | + touch "$APP_DIR/DISABLED" |
| 51 | + deploy_app "$APP" |
| 52 | + else |
| 53 | + echo "$APP: Application is already disabled" |
34 | 54 | fi |
| 55 | + ;; |
35 | 56 |
|
36 | | - echo "Destroying $APP (including all add-ons)" |
| 57 | + apps:enable|enable) |
| 58 | + verify_app_name "$2" |
| 59 | + verify_max_args 2 "$@" |
| 60 | + if [[ -f "$APP_DIR/DISABLED" ]]; then |
| 61 | + rm -f "$APP_DIR/DISABLED" |
| 62 | + deploy_app "$APP" |
| 63 | + else |
| 64 | + echo "$APP: Application is already enabled" |
| 65 | + fi |
| 66 | + ;; |
37 | 67 |
|
38 | | - pluginhook pre-delete $APP |
39 | | - if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then |
40 | | - ID=$(< "$DOKKU_ROOT/$APP/CONTAINER") |
| 68 | + apps:restart|restart) |
| 69 | + verify_app_name "$2" |
| 70 | + verify_max_args 2 "$@" |
| 71 | + docker restart "$APP_NAME" |
| 72 | + ;; |
41 | 73 |
|
42 | | - docker stop $ID > /dev/null || true |
43 | | - docker rm $ID > /dev/null || true |
| 74 | + apps:top|top) |
| 75 | + verify_app_name "$2" |
| 76 | + verify_max_args 2 "$@" |
| 77 | + |
| 78 | + shift 2 |
| 79 | + docker top "$APP_NAME" |
| 80 | + ;; |
| 81 | + |
| 82 | + apps:destroy|delete) |
| 83 | + verify_app_name "$2" |
| 84 | + |
| 85 | + if [[ ! -d "$APP_DIR" ]]; then |
| 86 | + echo "App does not exist" |
| 87 | + exit 1 |
44 | 88 | fi |
45 | 89 |
|
46 | | - docker images | grep $IMAGE | awk '{print $3}' | xargs docker rmi &> /dev/null & |
| 90 | + [[ "$APP" == "tls" ]] && fail "Unable to destroy tls directory" |
| 91 | + [[ "$APP" == "ssl" ]] && fail "Unable to destroy tls directory" |
| 92 | + |
| 93 | + info "Deleting application $APP..." |
| 94 | + pluginhook pre-delete $APP |
| 95 | + |
| 96 | + stop_and_remove_app_containers |
| 97 | + stop_and_remove_container $APP_PERSISTENT_NAMES |
| 98 | + remove_image "$IMAGE" |
47 | 99 |
|
48 | 100 | pluginhook post-delete $APP |
| 101 | + info "Application deleted: $APP" |
49 | 102 | ;; |
50 | 103 |
|
51 | | - help | apps:help) |
| 104 | + apps:create) |
| 105 | + |
| 106 | + |
| 107 | + help) |
52 | 108 | cat && cat<<EOF |
53 | | - apps List your apps |
54 | | - apps:create <app> Create a new app |
55 | | - apps:destroy <app> Permanently destroy an app |
| 109 | + list List app |
| 110 | + status <app> Status of specific app |
| 111 | + start <app> Stop specific app |
| 112 | + stop <app> Stop specific app |
| 113 | + restart <app> Restart specific app (not-redeploy) |
| 114 | + enable <app> Re-enable specific app |
| 115 | + disable <app> Disable specific app |
| 116 | + top <app> [args...] Show running processes |
56 | 117 | EOF |
57 | 118 | ;; |
58 | 119 |
|
59 | 120 | *) |
60 | 121 | exit $DOKKU_NOT_IMPLEMENTED_EXIT |
61 | 122 | ;; |
62 | | - |
63 | 123 | esac |
0 commit comments