-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Better management of the Docker containers * New version of chef-server * chef-rundeck is now running in a container
- Loading branch information
Showing
14 changed files
with
183 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,57 @@ | ||
#!/bin/bash | ||
|
||
URL=$1 | ||
CODE=1 | ||
OPTION=$1 | ||
URL=$2 | ||
SECONDS=0 | ||
TIMEOUT=$2 | ||
|
||
echo -e "Blocking until <${URL}> responds...\nTimeout: ${TIMEOUT} seconds." | ||
|
||
while [ $CODE -ne 0 ]; do | ||
curl -sfk \ | ||
--connect-timeout 3 \ | ||
--max-time 5 \ | ||
--fail \ | ||
--silent \ | ||
${URL} >/dev/null | ||
|
||
CODE=$? | ||
|
||
sleep 2 | ||
echo -n "." | ||
|
||
if [ $SECONDS -ge $TIMEOUT ]; then | ||
echo "$URL is not available after $SECONDS seconds...stopping the install!" | ||
exit 1 | ||
fi | ||
|
||
done; | ||
|
||
echo -e "\n\e[1m$URL\e[0m is accessible!" | ||
txtred=$(tput setaf 1) | ||
txtbold=$(tput bold) | ||
txtreset=$(tput sgr0) | ||
|
||
if [ "$OPTION" == "url" ]; then | ||
TIMEOUT=$3 | ||
CODE=1 | ||
echo -e "Blocking until <${URL}> responds...\nTimeout: ${TIMEOUT} seconds." | ||
|
||
while [ "$CODE" -ne 0 ]; do | ||
curl -sfk \ | ||
--connect-timeout 3 \ | ||
--max-time 5 \ | ||
--fail \ | ||
--silent \ | ||
"${URL}" >/dev/null | ||
|
||
CODE=$? | ||
|
||
sleep 2 | ||
echo -n "." | ||
|
||
if [ "$SECONDS" -ge "$TIMEOUT" ]; then | ||
echo "$txtred$URL is not available after $SECONDS seconds...stopping the install!" | ||
exit 1 | ||
fi | ||
done; | ||
|
||
elif [ "$OPTION" == "file" ]; then | ||
TARGET_SIZE=$3 | ||
TIMEOUT=$4 | ||
SIZE=0 | ||
echo -e "Blocking until $URL is accessible...\nTimeout: $TIMEOUT seconds." | ||
|
||
while [ $SIZE -lt $TARGET_SIZE ]; do | ||
SIZE=$(curl -Isk $URL | grep Content-Length | awk '{print $2}' | tr -d '\r\n') | ||
|
||
sleep 2 | ||
echo -n "." | ||
|
||
if [ "$SECONDS" -ge "$TIMEOUT" ]; then | ||
echo "$txtred$URL is not available after $SECONDS seconds...stopping the install!" | ||
exit 1 | ||
fi | ||
done; | ||
|
||
else | ||
echo "$txtred$OPTION is not a valid choice. Please use 'url' or 'file'!" | ||
exit 1 | ||
fi | ||
|
||
echo -e "\n$txtbold$URL$txtreset is accessible!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
#!/bin/bash | ||
|
||
echo -e "Installing Docker...\n" | ||
txtbold=$(tput bold) | ||
|
||
echo -e "$txtboldInstalling Docker...\n" | ||
sudo apt-get -y install docker.io | ||
sudo adduser rundeck docker | ||
sudo mkdir -p $1 | ||
cp docker/rundeck_jobs.xml $1 | ||
sudo chown rundeck. -R $1 | ||
sudo mkdir -p "$1" | ||
cp docker/rundeck_jobs.xml "$1" | ||
sudo chown rundeck. -R "$1" | ||
sudo docker network create --subnet=172.18.0.0/16 mc_net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
txtbold=$(tput bold) | ||
chef_rundeck_present=$(sudo docker ps -a |grep "$1") | ||
chef_rundeck_up=$(sudo docker ps |grep "$1") | ||
chef_rundeck_docker_ip=$2 | ||
chef_server_docker_ip=$3 | ||
set -e | ||
if [[ -z "$chef_rundeck_present" ]]; then | ||
echo -e "$txtboldCreating image, launching container and start $1\n" | ||
# Create the chef-rundeck Docker image and run it | ||
tar -zxf docker/docker_chef_rundeck.tar.gz | ||
sed -i "s,CHEF_SERVER_CONTAINER_IP,$3,g" chef-rundeck/Dockerfile | ||
sed -i "s,CHEF_SERVER_CONTAINER_IP,$3,g" chef-rundeck/config.rb | ||
cp ~/.chef/admin.pem chef-rundeck/ | ||
sudo docker build -t c_rundeck_image chef-rundeck/ | ||
sudo docker run --net mc_net --ip $chef_rundeck_docker_ip -d --name $1 -e 'USER=ubuntu' -p 9980:9980 c_rundeck_image | ||
# Get the container's IP and add it to /etc/hosts | ||
grep -q "$chef_rundeck_docker_ip $1" /etc/hosts || echo "$chef_rundeck_docker_ip $1" | sudo tee -a /etc/hosts | ||
elif [[ -z "$chef_rundeck_up" ]]; then | ||
echo -e "Starting $1 container\n" | ||
sudo docker start "$1" | ||
else | ||
echo -e "\nThere is already a Docker container named: $1\nRemove it first and re-run that script if you want a new container!\n" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,49 @@ | ||
#!/bin/bash | ||
chef_present=$(sudo docker ps -a |grep $1) | ||
chef_up=$(sudo docker ps |grep $1) | ||
txtbold=$(tput bold) | ||
chef_present=$(sudo docker ps -a |grep "$1") | ||
chef_up=$(sudo docker ps |grep "$1") | ||
chef_docker_ip=$4 | ||
set -e | ||
if [[ -z "$chef_present" ]]; then | ||
echo -e "Downloading container and start $1\n" | ||
sudo mkdir -p $3/$1/logs | ||
docker pull cbuisson/chef-server:v2.2 | ||
sudo docker run --privileged -e CONTAINER_NAME=$1 -e CHEF_PORT=$2 --name $1 -d -v $3/$1/logs/chef-logs:/var/log -v $3/$1/logs/install-chef-out:/root -p $2:$2 cbuisson/chef-server:v2.2 | ||
docker_ip=$(sudo docker inspect -f '{{.NetworkSettings.IPAddress }}' $1) | ||
grep -q "$docker_ip $1" /etc/hosts || echo "$docker_ip $1" | sudo tee -a /etc/hosts | ||
sudo scripts/check_url.sh https://$1:$2/knife_admin_key.tar.gz 600 | ||
sudo curl -o $3/$1/knife_admin_key.tar.gz -Ok https://$1:$2/knife_admin_key.tar.gz | ||
echo -e "$txtboldDownloading container and start $1\n" | ||
sudo mkdir -p "$3"/"$1"/logs | ||
# Get the chef-server Docker image and run it | ||
docker pull cbuisson/chef-server:v2.3 | ||
sudo docker run --net mc_net --ip $chef_docker_ip --privileged -e CONTAINER_NAME="$1" -e SSL_PORT="$2" --name "$1" -d -v "$3"/"$1"/logs/chef-logs:/var/log -v "$3"/"$1"/logs/install-chef-out:/root -p "$2":"$2" cbuisson/chef-server:v2.3 | ||
# Get the container's IP and add it to /etc/hosts | ||
grep -q "$chef_docker_ip $1" /etc/hosts || echo "$chef_docker_ip $1" | sudo tee -a /etc/hosts | ||
# Check the Chef is running | ||
sudo scripts/check_url.sh url https://"$1":"$2" 900 | ||
# Check if the archive containg the knife key is accessible and then download it | ||
sudo scripts/check_url.sh file https://"$1":"$2"/knife_admin_key.tar.gz 2500 900 | ||
sudo curl -o "$3"/"$1"/knife_admin_key.tar.gz -Ok https://"$1":"$2"/knife_admin_key.tar.gz | ||
sudo DEBIAN_FRONTEND=noninteractive apt-get install -q -y chef | ||
# Create two .chef folders, one for the current user and one for the rundeck user | ||
knife_keys=( /var/lib/rundeck ~ ) | ||
for i in "${knife_keys[@]}" | ||
do | ||
mkdir -p $i/.chef | ||
cat > $i/.chef/config.rb << EOL | ||
mkdir -p "$i"/.chef | ||
cat > "$i"/.chef/config.rb << EOL | ||
log_level :info | ||
log_location STDOUT | ||
cache_type 'BasicFile' | ||
node_name 'admin' | ||
client_key '$i/.chef/admin.pem' | ||
chef_server_url 'https://$1:$2/organizations/my_org' | ||
EOL | ||
sudo tar -zxf $3/$1/knife_admin_key.tar.gz -C $i/.chef/ | ||
sudo tar -zxf "$3"/"$1"/knife_admin_key.tar.gz -C "$i"/.chef/ | ||
done | ||
sudo chown -R rundeck. /var/lib/rundeck/.chef/ | ||
knife ssl fetch | ||
knife user list | ||
sudo su - rundeck -c "knife ssl fetch && knife user list" | ||
sudo chown rundeck. -R $3/$1 | ||
echo -e "\n\e[1mCreating knife keys for rundeck and $SUDO_USER users!\e[0m" | ||
sudo chown rundeck. -R "$3"/"$1" | ||
echo -e "\n\eCreating knife keys for rundeck and $SUDO_USER users!\e" | ||
sudo chown rundeck. -R /var/lib/rundeck/.chef/ | ||
sudo chown $SUDO_USER. -R ~/.chef/ | ||
sudo chown "$SUDO_USER". -R ~/.chef/ | ||
elif [[ -z "$chef_up" ]]; then | ||
echo -e "Starting $1 container\n" | ||
sudo docker start $1 | ||
sudo docker start "$1" | ||
else | ||
echo -e "\nThere is already a Docker container named: $1\nRemove it first and re-run that script if you want a new container!\n" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.