这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/development/plugin-creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ A few notes:
the last command to exit with a non-zero status,
or zero if no command exited with a non-zero status
```
- As some plugins require access to set app config settings and do not want/require the default Heroku-style behavior of a restart, we have the following "internal" commands that provide this functionality :

```shell
dokku config:set-norestart APP KEY1=VALUE1 [KEY2=VALUE2 ...]
dokku config:unset-norestart APP KEY1 [KEY2 ...]
```
39 changes: 36 additions & 3 deletions plugins/config/commands
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ config_write() {
if ! cmp -s $ENV_FILE $ENV_FILE_TEMP; then
cp -f $ENV_FILE_TEMP $ENV_FILE
chmod 600 $ENV_FILE
dokku ps:restart $APP
fi
rm -f $ENV_FILE_TEMP
}
Expand Down Expand Up @@ -101,6 +100,23 @@ case "$1" in
exit 1
fi

shift 2
dokku config:set-norestart $APP "$@"
dokku_log_info1 "Restarting app $APP"
dokku ps:restart $APP
;;

config:set-norestart)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"

if [[ -z "${*:3}" ]]; then
echo "Usage: dokku config:set APP KEY1=VALUE1 [KEY2=VALUE2 ...]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong usage

echo "Must specify KEY and VALUE to set."
exit 1
fi

config_create
ENV_ADD=""
ENV_TEMP=$(cat "${ENV_FILE}")
Expand Down Expand Up @@ -131,7 +147,7 @@ ${var}"
ENV_ADD=$(echo "$ENV_ADD" | tail -n +2) #remove first empty line

if [ $RESTART_APP ]; then
dokku_log_info1 "Setting config vars and restarting $APP"
dokku_log_info1 "Setting config vars"
config_styled_hash "$ENV_ADD" " "

config_write "$ENV_TEMP"
Expand All @@ -149,12 +165,29 @@ ${var}"
exit 1
fi

shift 2
dokku config:unset-norestart $APP "$@"
dokku_log_info1 "Restarting app $APP"
dokku ps:restart $APP
;;

config:unset-norestart)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"

if [[ -z $3 ]]; then
echo "Usage: dokku config:unset APP KEY1 [KEY2 ...]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong usage

echo "Must specify KEY to unset."
exit 1
fi

config_create
ENV_TEMP=$(cat "${ENV_FILE}")
VARS="${*:3}"

for var in $VARS; do
dokku_log_info1 "Unsetting $var and restarting $APP"
dokku_log_info1 "Unsetting $var"
ENV_TEMP=$(echo -e "${ENV_TEMP}" | sed "/^export $var=/ d")

config_write "$ENV_TEMP"
Expand Down