jjethwa / rundeck

GNU General Public License v3.0
123 stars 137 forks source link

Remove need for user input when starting container #82

Closed dandunckelman closed 5 years ago

dandunckelman commented 7 years ago

Summary

Currently, when a container is run, it displays this message at the end:

Starting Supervisor. You can safely CTRL-C and the container will continue to run with or without the -d (daemon) option

I'd prefer to not need to hit CTRL-C since I'm trying to make an automated backup restore process.

My workaround

I run the container daemonized (with -d), then loop over the container's logs until it hits the above message.

Questions

P.S. Thanks for putting this together. Dead simple.

dandunckelman commented 7 years ago

Just some notes:

Like I said, these are just notes. It would be nice if the service were completely ready to handle requests once the container setup is complete, but I could see how that's not your responsibility.

dandunckelman commented 7 years ago

For anyone else's benefit, this is what I ended up writing as a test to ensure daily backups are working.

#!/bin/bash -e
FILE="rundeck_backup.tar.gz"
BACKUP_DIR="/backups/rundeck/production"
TODAY=`date +"%Y-%m-%d"`
TMPDIR="/tmp/$TODAY"
RD_URL="http://0.0.0.0:4440"
RD_USER="admin"
RD_PASS="admin"
RD_DIR="/var/lib/rundeck"

echo "Getting backup..."
mkdir -p $TMPDIR
cd $TMPDIR
cp $BACKUP_DIR/$TODAY/$FILE .
echo "Expanding backup archive..."
tar -xzf $FILE
echo "Backup archive expanded"

echo "Running container..."
docker run -d \
    -p 4440:4440 \
    -e SERVER_URL=$RD_URL \
    -e RUNDECK_ADMIN_PASSWORD=$RD_PASS \
    -v logs:$RD_DIR/logs \
    -v data:$RD_DIR/data \
    --name rundeck \
    jordan/rundeck:latest
echo "Container is now running"

echo "Waiting until container setup is complete..."
END_OF_LINE=false

while [ $END_OF_LINE == false ]; do
  echo "Getting container logs..."
  OUTPUT=`docker logs --tail 1 rundeck`
  echo "LOG OUTPUT:"
  echo $OUTPUT

  if [[ `echo $OUTPUT | grep -i "you can safely ctrl-c"` ]]; then
    echo "Container is now ready"
    END_OF_LINE=true
  else
    echo "Sleeping for 5s..."
    sleep 5
  fi
done

echo "Waiting until the Rundeck service is ready to handle requests..."
IS_READY=false

while [ $IS_READY == false ]; do
  echo "Getting rundeck service logs..."
  OUTPUT=`docker exec rundeck bash -c "tail /var/log/rundeck/service.log"`
  echo "LOG OUTPUT:"
  echo $OUTPUT

  if [[ `echo $OUTPUT | grep -i "Started ServerConnector"` ]]; then
    echo "Container is now ready"
    IS_READY=true
  else
    echo "Sleeping for 5s..."
    sleep 5
  fi
done
echo "The Rundeck service is now ready to handle requests"

for i in $(echo `ls projects/`); do
  PROJECT_NAME=`echo ${i^} | sed "s/.yaml//"`
  EXPORTS="export RD_URL=$RD_URL; export RD_USER=$RD_USER; export RD_PASSWORD=$RD_PASS"

  echo "Creating the $PROJECT_NAME project..."
  docker exec rundeck bash -c "$EXPORTS; rd projects create -p $PROJECT_NAME"
  echo "Created the $PROJECT_NAME project"

  echo "Importing the $PROJECT_NAME project's jobs..."
  docker cp projects/$i rundeck:/tmp/
  docker exec rundeck bash -c "$EXPORTS; rd jobs load -f /tmp/$i -p $PROJECT_NAME -F yaml"
  echo "Import of the $PROJECT_NAME project's jobs complete"
done

echo "Removing container..."
docker rm -f rundeck
echo "Container removed"

echo "Removing backup files..."
cd
rm -rf $TMPDIR
echo "Backup files removed"
jjethwa commented 7 years ago

Hi @dandunckelman

Just to clarify, the CTRL-C message is not needed and there is no need for user input when starting the container. The message was added for users that might have started the container without the -d option as it was causing some confusion in the earlier days of Docker 😛

I was thinking about adding a loop to check and make sure the Rundeck server is up before outputting the CTRL-C message as it takes a bit of time for the server to start up. You already took care of it in your script, but it might be useful for others? Let me know what you think and thanks for the backup script, it'll come in handy 😄

dandunckelman commented 5 years ago

Closing.

Rundeck has an official image, and this just isn't important anymore.