Skip to content

Instantly share code, notes, and snippets.

@ebeigarts
Last active September 14, 2017 22:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebeigarts/e3256021986f625acec62d9add04dfc3 to your computer and use it in GitHub Desktop.
Save ebeigarts/e3256021986f625acec62d9add04dfc3 to your computer and use it in GitHub Desktop.
Dokku redeploy fix

Rebuild dokku nginx configuration with correct container IP addresses after system reboot until #2736 is released.

sudo curl -L -o /etc/systemd/system/dokku-redeploy-fix.service https://gist.github.com/ebeigarts/e3256021986f625acec62d9add04dfc3/raw/d85afd4e8beba843e273f4c8b7237c375a7eabea/dokku-redeploy-fix.service &&
sudo curl -L -o /usr/bin/dokku-redeploy-fix https://gist.github.com/ebeigarts/e3256021986f625acec62d9add04dfc3/raw/b4b3be7f3fdf51ba4e7716ac8cf04f40b97a762b/dokku-redeploy-fix.sh &&
sudo chmod +x /usr/bin/dokku-redeploy-fix &&
sudo systemctl enable dokku-redeploy-fix

Reboot the system and you should see something like this in the log:

sudo journalctl -u dokku-redeploy-fix.service
-- Logs begin at Mon 2017-08-07 12:42:53 EEST, end at Mon 2017-08-07 09:53:21 EEST. --
Aug 07 09:45:00 dokku1 systemd[1]: Started Dokku app redeploy fix service.
Aug 07 09:45:00 dokku1 systemd[1]: Starting Dokku app redeploy fix service...
Aug 07 09:45:03 dokku1 dokku-redeploy-fix[3032]: ---> app1.web.1: 172.17.0.3
Aug 07 09:45:09 dokku1 dokku-redeploy-fix[3032]: -----> Overriding default nginx.conf with detected nginx.conf.sigil
Aug 07 09:45:29 dokku1 dokku-redeploy-fix[3032]: -----> Creating http nginx.conf
Aug 07 09:45:29 dokku1 dokku-redeploy-fix[3032]: -----> Running nginx-pre-reload
Aug 07 09:45:29 dokku1 dokku-redeploy-fix[3032]: Reloading nginx
Aug 07 09:45:30 dokku1 sudo[5822]:    dokku : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/sbin/nginx -t
Aug 07 09:45:30 dokku1 sudo[5824]:    dokku : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/usr/bin/systemctl reload nginx
[Unit]
Description=Dokku app redeploy fix service
Requires=dokku-redeploy.service
After=dokku-redeploy.service
[Service]
Type=simple
User=dokku
ExecStart=/usr/bin/dokku-redeploy-fix
[Install]
WantedBy=multi-user.target
#!/bin/bash
for APP_DIR in /home/dokku/*/; do
APP=$(basename $APP_DIR)
for CONTAINER_FILE in /home/dokku/$APP/CONTAINER.web.*; do
INDEX=$(awk -F '.' '{ print $3 }' <<< $CONTAINER_FILE)
CONTAINER_ID=$(< $CONTAINER_FILE)
CONTAINER_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONTAINER_ID)
if [ ! -z $CONTAINER_IP ]; then
echo " ---> $APP.web.$INDEX: $CONTAINER_IP"
echo $CONTAINER_IP > /home/dokku/$APP/IP.web.$INDEX
dokku nginx:build-config $APP
fi
done
done
@aleclarson
Copy link

aleclarson commented Sep 14, 2017

Could you include a guide for Ubuntu 14.04, which uses Upstart instead of Systemd?

edit: I figured it out. 😉

Instructions

  • Install the /usr/bin/dokku-redeploy-fix script
sudo curl -L -o /usr/bin/dokku-redeploy-fix https://gist.github.com/ebeigarts/e3256021986f625acec62d9add04dfc3/raw/b4b3be7f3fdf51ba4e7716ac8cf04f40b97a762b/dokku-redeploy-fix.sh &&
sudo chmod +x /usr/bin/dokku-redeploy-fix
  • Remove /etc/systemd/system/dokku-redeploy-fix.service if it exists
  • Add /etc/init/dokku-redeploy-fix.conf with the following contents:
description "Dokku app redeploy fix service"
start on started dokku-reploy
exec start-stop-daemon --start -c dokku --exec /usr/bin/dokku-redeploy-fix
  • Use initctl (instead of systemctl) to start the service:
initctl reload-configuration
  • To view the logs of the daemon:
cat /var/log/upstart/dokku-redeploy-fix.log

@aleclarson
Copy link

aleclarson commented Sep 14, 2017

Found a bug. If you have a Dokku app that hasn't been deployed yet, its CONTAINER.web.* file will not exist.

/usr/bin/dokku-redeploy-fix: line 8: /home/dokku/my-app/CONTAINER.web.*: No such file or directory

I suggest adding a [ -f ... ] conditional to avoid errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment