From 2cb52ff73c37341865ba0748ce1baa6a868c9c1a Mon Sep 17 00:00:00 2001 From: Clement Buisson Date: Mon, 20 Mar 2017 19:19:46 -0700 Subject: [PATCH] Ubuntu 16.04 LTS support --- CHANGELOG | 22 ++++++- README.md | 2 +- install | 2 +- kvm/chef_generate_scripts-floating.rb | 19 ------ kvm/chef_generate_scripts.rb | 4 +- kvm/generate_scripts-floating.rb | 3 +- kvm/generate_scripts.rb | 3 +- kvm/get_first_cloud_image.rb | 2 + kvm/templates/TEMPLATE-user-data-nat.erb | 1 + kvm/templates/TEMPLATE-user-data.erb | 1 + kvm/templates/chef-rundeck_jobs.xml.erb | 10 ++-- kvm/templates/rundeck_jobs.xml.erb | 4 +- scripts/create_rd_projects.sh | 44 ++++++++++++++ scripts/get_and_install.sh | 52 +++++++++++++++++ scripts/install_docker.sh | 9 +-- scripts/install_docker_chef-server.sh | 57 ++++++++++-------- scripts/install_kvm.sh | 22 +------ scripts/install_rundeck.sh | 60 +++++++++++++++---- scripts/menu_chef.rb | 25 ++++---- scripts/menu_main.rb | 67 ++++++++++++++-------- scripts/templates/chef-rundeck.conf.erb | 15 ----- scripts/templates/chef-rundeck.service.erb | 10 ++++ vars | 4 +- 23 files changed, 287 insertions(+), 151 deletions(-) delete mode 100644 kvm/chef_generate_scripts-floating.rb create mode 100755 scripts/create_rd_projects.sh create mode 100755 scripts/get_and_install.sh delete mode 100644 scripts/templates/chef-rundeck.conf.erb create mode 100644 scripts/templates/chef-rundeck.service.erb diff --git a/CHANGELOG b/CHANGELOG index 71c7443..802747f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,28 @@ CHANGELOG ========= +2.4: 2017-03-20 +--------------- +New Features: +- Using Rundeck will use MySQL has its backend database instead of the default flat file. +- Implementing RD CLI instead of rd-{projects,jobs} tool. +- Using Systemd to manage all services. +- Mission_Control installation is now idempotent. +- Rundeck projects and jobs are being handled by a single script. +- wget and installs are being handled by a single script. + +Updates: +- Mission_Control is now Ubuntu Xenial 16.04 LTS compatible. + => Ruby 2.3, Java 8, Rundeck 2.7, Mysql 5.7, PostgreSQL 9.5, Docker 1.9 and Chef 12 +- Using Ruby's 'ipaddr' library instead of 'ipaddress'. +- Rundeck and Chef-Rundeck will auto start. +- Using Validatorless Bootstraps for Chef clients. + +Removed: +- chef_generate_scripts-floating.rb + 2.3.1: 2017-02-10 ----------------- +----------------- Fixed: - chown /home/ubuntu to ubuntu user instead of root diff --git a/README.md b/README.md index 9d83c12..f3c5f1a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The install process will display a menu where you can choose to install any feat ##Environment -Mission_Control has been developed for **Ubuntu Trusty 14.04 LTS**. +Mission_Control has been developed for **Ubuntu Xenial 16.04 LTS**. #*kvm-control* diff --git a/install b/install index 9286171..fed3def 100755 --- a/install +++ b/install @@ -6,7 +6,7 @@ echo " |\/| | /__\` /__\` | / \\ |\\ | / \` / \\ |\\ | | |__) / \\ |" echo " | | | .__/ .__/ | \\__/ | \\| ___ \\__, \\__/ | \\| | | \\ \\__/ |___" echo -e "\n\nInstallation is progress...\n" sudo apt-get -q update -sudo apt-get -y install build-essential ruby1.9 +sudo apt-get -y install build-essential ruby2.3 ruby2.3-dev echo "Installing: bundler" sudo gem install bundler --no-ri --no-rdoc bundle install diff --git a/kvm/chef_generate_scripts-floating.rb b/kvm/chef_generate_scripts-floating.rb deleted file mode 100644 index 86bf16c..0000000 --- a/kvm/chef_generate_scripts-floating.rb +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/ruby -require 'erb' - -def chef_generate_scripts(backend, kvm_folder, floating, bind9) - dir=File.expand_path(File.dirname(__FILE__)) - - #Generate Rundeck xml - template = ERB.new(File.read("#{dir}/templates/chef-rundeck_jobs.xml.erb")) - xml_content = template.result(binding) - File.open("#{kvm_folder}/chef-rundeck_jobs.xml", "w") do |file| - file.puts xml_content - end - - system("sudo su rundeck -c 'rd-project -p kvm-control_with-Chef -a create --resources.source.2.config.url=http://localhost:9980 --resources.source.2.type=url --resources.source.2.config.timeout=60 --resources.source.2.config.cache=false'") - system("sudo su rundeck -c 'rd-jobs load -r -f #{kvm_folder}/chef-rundeck_jobs.xml -p kvm-control_with-Chef'") - - system("sudo chown -R rundeck. #{kvm_folder}") - -end diff --git a/kvm/chef_generate_scripts.rb b/kvm/chef_generate_scripts.rb index 86bf16c..ce6fea1 100644 --- a/kvm/chef_generate_scripts.rb +++ b/kvm/chef_generate_scripts.rb @@ -11,9 +11,7 @@ def chef_generate_scripts(backend, kvm_folder, floating, bind9) file.puts xml_content end - system("sudo su rundeck -c 'rd-project -p kvm-control_with-Chef -a create --resources.source.2.config.url=http://localhost:9980 --resources.source.2.type=url --resources.source.2.config.timeout=60 --resources.source.2.config.cache=false'") - system("sudo su rundeck -c 'rd-jobs load -r -f #{kvm_folder}/chef-rundeck_jobs.xml -p kvm-control_with-Chef'") - + system("#{dir}/../scripts/create_rd_projects.sh \"kvm-control_with-Chef\" #{kvm_folder}") system("sudo chown -R rundeck. #{kvm_folder}") end diff --git a/kvm/generate_scripts-floating.rb b/kvm/generate_scripts-floating.rb index c472070..a6c751b 100644 --- a/kvm/generate_scripts-floating.rb +++ b/kvm/generate_scripts-floating.rb @@ -31,8 +31,7 @@ def generate_scripts(backend, database_name, db_kvm_table, mysql_password, kvm_f end end - system("sudo su rundeck -c 'rd-project -p kvm-control -a create'") - system("sudo su rundeck -c 'rd-jobs load -r -f #{kvm_folder}/rundeck_jobs.xml -p kvm-control'") + system("#{dir}/../scripts/create_rd_projects.sh \"kvm-control\" #{kvm_folder}") #Generate user-data template files user_data_templates=["TEMPLATE-user-data", "TEMPLATE-user-data-nat"].each do |ud| diff --git a/kvm/generate_scripts.rb b/kvm/generate_scripts.rb index 1842655..6d42b6d 100644 --- a/kvm/generate_scripts.rb +++ b/kvm/generate_scripts.rb @@ -31,8 +31,7 @@ def generate_scripts(backend, database_name, db_kvm_table, mysql_password, kvm_f end end - system("sudo su rundeck -c 'rd-project -p kvm-control -a create'") - system("sudo su rundeck -c 'rd-jobs load -r -f #{kvm_folder}/rundeck_jobs.xml -p kvm-control'") + system("#{dir}/../scripts/create_rd_projects.sh \"kvm-control\" #{kvm_folder}") #Generate user-data template file var = "<%= ip %>" diff --git a/kvm/get_first_cloud_image.rb b/kvm/get_first_cloud_image.rb index bcfec36..4994967 100644 --- a/kvm/get_first_cloud_image.rb +++ b/kvm/get_first_cloud_image.rb @@ -4,6 +4,8 @@ def get_first_cloud_image(kvm_folder, first_image_source) filename = first_image_source.split(/\?/).first.split(/\//).last if File.exist?(kvm_folder+"/sources/cloud_images/"+filename) puts "#{filename} is already in #{kvm_folder}/sources/cloud_images/ skipping..." + elsif File.exist?(kvm_folder+"/sources/iso/"+filename) + puts "#{filename} is already in #{kvm_folder}/sources/iso/ skipping..." else system("sudo ruby #{kvm_folder}/get_images.rb #{first_image_source}") end diff --git a/kvm/templates/TEMPLATE-user-data-nat.erb b/kvm/templates/TEMPLATE-user-data-nat.erb index fc7d3ef..b8e155a 100644 --- a/kvm/templates/TEMPLATE-user-data-nat.erb +++ b/kvm/templates/TEMPLATE-user-data-nat.erb @@ -42,6 +42,7 @@ write_files: runcmd: - sudo /home/ubuntu/set_static_ip.sh - sudo chown ubuntu. -R /home/ubuntu + - echo "<%= ip_host %> chef-server" | sudo tee -a /etc/cloud/templates/hosts.debian.tmpl final_message: "The system is finally up, after $UPTIME seconds" power_state: mode: reboot diff --git a/kvm/templates/TEMPLATE-user-data.erb b/kvm/templates/TEMPLATE-user-data.erb index b55b507..304ebfe 100644 --- a/kvm/templates/TEMPLATE-user-data.erb +++ b/kvm/templates/TEMPLATE-user-data.erb @@ -42,6 +42,7 @@ write_files: runcmd: - sudo /home/ubuntu/set_static_ip.sh - sudo chown ubuntu. -R /home/ubuntu + - echo "<%= ip_host %> chef-server" | sudo tee -a /etc/cloud/templates/hosts.debian.tmpl final_message: "The system is finally up, after $UPTIME seconds" power_state: mode: reboot diff --git a/kvm/templates/chef-rundeck_jobs.xml.erb b/kvm/templates/chef-rundeck_jobs.xml.erb index 78fdc62..5acf328 100644 --- a/kvm/templates/chef-rundeck_jobs.xml.erb +++ b/kvm/templates/chef-rundeck_jobs.xml.erb @@ -205,7 +205,7 @@ File.open("/etc/bind/db.1XX", "w") do |file| file.puts xml_content end puts "Reloading Bind9..." -system("service bind9 reload")<% end %> +system("sudo systemctl reload bind9")<% end %> puts "\nNew XML file created at: " + XML.underline]]> @@ -316,8 +316,8 @@ puts "\nvirsh undefine #{guest.red.bold}" system("virsh undefine #{guest}") puts "\nClean up Chef server" -system("knife client -c /var/lib/rundeck/.chef/knife.rb delete -y #{guest}") -system("knife node -c /var/lib/rundeck/.chef/knife.rb delete -y #{guest}") +system("knife client -c /var/lib/rundeck/.chef/config.rb delete -y #{guest}") +system("knife node -c /var/lib/rundeck/.chef/config.rb delete -y #{guest}") puts "" if File.exist?("#{USER_DATA}/#{guest}-user-data.erb")<% if backend == "mysql" %> @@ -364,7 +364,7 @@ File.open("/etc/bind/db.1XX", "w") do |file| file.puts xml_content end puts "Reloading Bind9..." -system("service bind9 reload")<% end %> +system("sudo systemctl reload bind9")<% end %> puts "\nInstance destroyed and files removed" puts "Carry on..."]]> @@ -672,7 +672,7 @@ ip = guest_ip ENV['RD_OPTION_NAME'] puts "Sleeping 10 seconds for the guest to fully start." sleep 10 -system("knife bootstrap -c /var/lib/rundeck/.chef/knife.rb #{ip} --ssh-user ubuntu -i /var/lib/rundeck/.ssh/id_rsa --no-host-key-verify --node-name #{ENV['RD_OPTION_NAME']} --sudo") or raise "Couldn't bootstrap #{ENV['RD_OPTION_NAME']}...".red +system("knife bootstrap -c /var/lib/rundeck/.chef/config.rb #{ip} --ssh-user ubuntu -i /var/lib/rundeck/.ssh/id_rsa --no-host-key-verify --node-name #{ENV['RD_OPTION_NAME']} --sudo") or raise "Couldn't bootstrap #{ENV['RD_OPTION_NAME']}...".red puts "\n#{ENV['RD_OPTION_NAME']} is now bootstrapped to the Chef server!".cyan]]> diff --git a/kvm/templates/rundeck_jobs.xml.erb b/kvm/templates/rundeck_jobs.xml.erb index 098c5d1..b15f5c4 100644 --- a/kvm/templates/rundeck_jobs.xml.erb +++ b/kvm/templates/rundeck_jobs.xml.erb @@ -205,7 +205,7 @@ File.open("/etc/bind/db.1XX", "w") do |file| file.puts xml_content end puts "Reloading Bind9..." -system("service bind9 reload")<% end %> +system("sudo systemctl reload bind9")<% end %> puts "\nNew XML file created at: " + XML.underline]]> @@ -359,7 +359,7 @@ File.open("/etc/bind/db.1XX", "w") do |file| file.puts xml_content end puts "Reloading Bind9..." -system("service bind9 reload")<% end %> +system("sudo systemctl reload bind9")<% end %> puts "\nInstance destroyed and files removed" puts "Carry on..."]]> diff --git a/scripts/create_rd_projects.sh b/scripts/create_rd_projects.sh new file mode 100755 index 0000000..b14db42 --- /dev/null +++ b/scripts/create_rd_projects.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +case "$1" in + "kvm-control" ) + project=$(sudo su - rundeck -c "rd projects list |grep $1") + if [[ -z "$project" ]]; then + echo -e "Creating $1 project and jobs!\n" + sudo su rundeck -c "rd projects create -p kvm-control" + sudo su rundeck -c "rd jobs load -r -f $2/rundeck_jobs.xml -p kvm-control" + else + echo -e "$1 project and jobs already created!\n" + fi + ;; + "kvm-control_with-Chef" ) + project=$(sudo su - rundeck -c "rd projects list |grep $1") + if [[ -z "$project" ]]; then + echo -e "Creating $1 project and jobs!\n" + sudo su rundeck -c "rd projects create -p kvm-control_with-Chef -- --resources.source.2.config.url=http://localhost:9980 --resources.source.2.type=url --resources.source.2.config.timeout=60 --resources.source.2.config.cache=false" + sudo su rundeck -c "rd jobs load -r -f $2/chef-rundeck_jobs.xml -p kvm-control_with-Chef" + else + echo -e "$1 project and jobs already created!\n" + fi + ;; + "docker-control" ) + project=$(sudo su - rundeck -c "rd projects list |grep $1") + if [[ -z "$project" ]]; then + echo -e "Creating $1 project and jobs!\n" + sudo su rundeck -c "rd projects create -p docker-control" + sudo su rundeck -c "rd jobs load -r -f $2/rundeck_jobs.xml -p docker-control" + else + echo -e "$1 project and jobs already created!\n" + fi + ;; + "chef_server-control" ) + project=$(sudo su - rundeck -c "rd projects list |grep $1") + if [[ -z "$project" ]]; then + echo -e "Creating $1 project and jobs!\n" + sudo su rundeck -c "rd projects create -p chef_server-control" + sudo su rundeck -c "rd jobs load -r -f $2/rundeck_jobs-chef.xml -p chef_server-control" + else + echo -e "$1 project and jobs already created!\n" + fi + ;; +esac diff --git a/scripts/get_and_install.sh b/scripts/get_and_install.sh new file mode 100755 index 0000000..a47cd2e --- /dev/null +++ b/scripts/get_and_install.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +case "$1" in + "rundeck-cli" ) + file=$(ls /etc/apt/sources.list.d/ |grep rundeck-cli.list) + if [[ -z "$file" ]]; then + echo -e "Downloading $1!\n" + echo "deb https://dl.bintray.com/rundeck/rundeck-deb /" | sudo tee -a /etc/apt/sources.list.d/rundeck-cli.list + curl "https://bintray.com/user/downloadSubjectPublicKey?username=bintray" > /tmp/bintray.gpg.key + apt-key add - < /tmp/bintray.gpg.key + apt-get -y install apt-transport-https + apt-get -y update + else + echo -e "$1 is already on this server!\n" + fi + ;; + "rundeck" ) + file=$(ls |grep rundeck-$2-GA.deb) + if [[ -z "$file" ]]; then + echo -e "Downloading $1!\n" + wget http://download.rundeck.org/deb/rundeck-$2-GA.deb + dpkg -i rundeck-$2-GA.deb + rm -rf /tmp/rundeck/ + cp /etc/rundeck/rundeck-config.properties /etc/rundeck/rundeck-config.properties.backup + cp /etc/rundeck/framework.properties /etc/rundeck/framework.properties.backup + else + echo -e "$1 is already on this server!\n" + fi + ;; + "mysql-connector" ) + file=$(ls |grep mysql-connector-java-5.1.40.tar.gz) + if [[ -z "$file" ]]; then + echo -e "Downloading $1!\n" + wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.40.tar.gz + tar -zxf mysql-connector-java-5.1.40.tar.gz -C /tmp/ + cp /tmp/mysql-connector-java-5.1.40/mysql-connector-java-5.1.40-bin.jar /var/lib/rundeck/libext/ + else + echo -e "$1 is already on this server!\n" + fi + ;; + "chef-rundeck" ) + file=$(ls |grep ruby-ffi) + if [[ -z "$file" ]]; then + echo -e "Downloading ffy dependencies and chef-rundeck gem!\n" + wget http://mirrors.kernel.org/ubuntu/pool/universe/r/ruby-ffi/ruby-ffi_1.9.10debian-1build2_amd64.deb http://security.ubuntu.com/ubuntu/pool/universe/r/ruby-ffi-yajl/ruby-ffi-yajl_2.2.3-2_amd64.deb + sudo dpkg -i ruby-ffi* + sudo gem install chef-rundeck + else + echo -e "$1 and its dependencies are already installed on this server!\n" + fi + ;; +esac diff --git a/scripts/install_docker.sh b/scripts/install_docker.sh index bd4ecde..8ecb6da 100755 --- a/scripts/install_docker.sh +++ b/scripts/install_docker.sh @@ -1,15 +1,8 @@ #!/bin/bash +echo -e "Installing Docker...\n" sudo apt-get -y install docker.io -sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker -sudo docker pull ubuntu:14.04 sudo adduser rundeck docker sudo mkdir -p $1 cp docker/rundeck_jobs.xml $1 sudo chown rundeck. -R $1 -containers_running=`sudo docker ps |grep -v CONTAINER` -if [[ -z "$containers_running" ]]; then - sudo service docker.io restart - echo -e "Restarting Docker service...\nWaiting 5 seconds for Docker to start..." - sleep 5 -fi diff --git a/scripts/install_docker_chef-server.sh b/scripts/install_docker_chef-server.sh index eb64b56..6446f82 100755 --- a/scripts/install_docker_chef-server.sh +++ b/scripts/install_docker_chef-server.sh @@ -1,32 +1,41 @@ #!/bin/bash -sudo mkdir -p $3/$1/logs -chef_up=`sudo docker ps -a |grep -v CONTAINER |grep $1` +chef_present=$(sudo docker ps -a |grep $1) +chef_up=$(sudo docker ps |grep $1) set -e -if [[ -z "$chef_up" ]]; then - sudo docker run --privileged -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 -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 -sudo scripts/check_url.sh https://$4:$2/knife_admin_key.tar.gz 300 -sudo curl -o $3/$1/knife_admin_key.tar.gz -Ok https://$4:$2/knife_admin_key.tar.gz -sudo DEBIAN_FRONTEND=noninteractive apt-get install -q -y ruby1.9.1-dev chef -knife_keys=( /var/lib/rundeck ~ ) -for i in "${knife_keys[@]}" - do - mkdir -p $i/.chef - cat > $i/.chef/knife.rb << EOL +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 + sudo DEBIAN_FRONTEND=noninteractive apt-get install -q -y chef + knife_keys=( /var/lib/rundeck ~ ) + for i in "${knife_keys[@]}" + do + 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' -validation_client_name 'chef-validator' -validation_key '$i/.chef/chef-validator.pem' -chef_server_url 'https://$4:$2' +chef_server_url 'https://$1:$2/organizations/my_org' EOL - sudo tar -zxf $3/$1/knife_admin_key.tar.gz -C $i/.chef/ -done -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 /var/lib/rundeck/.chef/ -sudo chown $SUDO_USER. -R ~/.chef/ + sudo tar -zxf $3/$1/knife_admin_key.tar.gz -C $i/.chef/ + done + 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 /var/lib/rundeck/.chef/ + sudo chown $SUDO_USER. -R ~/.chef/ +elif [[ -z "$chef_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 diff --git a/scripts/install_kvm.sh b/scripts/install_kvm.sh index d46750e..259ee04 100755 --- a/scripts/install_kvm.sh +++ b/scripts/install_kvm.sh @@ -7,28 +7,10 @@ sudo adduser rundeck libvirtd && sudo adduser rundeck kvm kvm_guests=`sudo virsh list` if [[ -z "$kvm_guests" ]]; then echo "Restart libvirtd..." - sudo service libvirt-bin restart + sudo systemctl restart libvirt-bin fi -if [[ $2 == "mysql" ]]; then - echo "mysql-server-5.5 mysql-server/root_password password $3 - mysql-server-5.5 mysql-server/root_password seen true - mysql-server-5.5 mysql-server/root_password_again password $3 - mysql-server-5.5 mysql-server/root_password_again seen true - " | sudo debconf-set-selections - export DEBIAN_FRONTEND=noninteractive - sudo apt-get install -q -y mysql-server mysql-client libmysqlclient-dev -elif [[ $2 == "postgres" ]]; then - sudo apt-get -y install postgresql libpq-dev - sudo su - postgres -c "createuser pguser -s" - echo -e "local all postgres peer\nlocal all pguser trust\nlocal all all peer\nhost all all 127.0.0.1/32 md5" | sudo tee /etc/postgresql/9.3/main/pg_hba.conf - sudo service postgresql restart -else - echo "Backend: $2 not supported!" - exit 1 -fi - -if [[ $4 == "yes" ]];then +if [[ $2 == "yes" ]];then domain=$(cat /etc/resolvconf/resolv.conf.d/{head,base} |grep -w "search local") localhost=$(cat /etc/resolvconf/resolv.conf.d/{head,base} |grep -w "nameserver 127.0.0.1") if [[ -z "$domain" ]];then diff --git a/scripts/install_rundeck.sh b/scripts/install_rundeck.sh index 8dc6701..2fdaaf1 100755 --- a/scripts/install_rundeck.sh +++ b/scripts/install_rundeck.sh @@ -1,13 +1,53 @@ #!/bin/bash -wget http://download.rundeck.org/deb/rundeck-$2-GA.deb -P /tmp -sudo apt-get -y install openjdk-6-jre -sudo dpkg -i /tmp/rundeck-$2-GA.deb -sudo rm -rf /tmp/rundeck/ -sudo sed -i s,localhost,$1,g /etc/rundeck/framework.properties -sudo sed -i s,localhost,$1,g /etc/rundeck/rundeck-config.properties +# Get source for Rundeck-CLI +scripts/get_and_install.sh rundeck-cli + +# Get Rundeck deb and install +apt-get -y install openjdk-8-jre rundeck-cli +scripts/get_and_install.sh rundeck $2 +cp /etc/rundeck/rundeck-config.properties.backup /etc/rundeck/rundeck-config.properties +cp /etc/rundeck/framework.properties.backup /etc/rundeck/framework.properties + +# Install database +if [[ $3 == "mysql" ]]; then + echo "mysql-server-5.7 mysql-server/root_password password $4 + mysql-server-5.7 mysql-server/root_password seen true + mysql-server-5.7 mysql-server/root_password_again password $4 + mysql-server-5.7 mysql-server/root_password_again seen true + " | sudo debconf-set-selections + export DEBIAN_FRONTEND=noninteractive + apt-get install -q -y mysql-server mysql-client libmysqlclient-dev + # Setup rundeckdb + scripts/get_and_install.sh "mysql-connector" + mysql -u root -p$4 -e "create database rundeckdb" + mysql -u root -p$4 -e "grant ALL on rundeckdb.* to 'rduser'@'localhost' identified by 'rdpasswd';" + sed -i "s,jdbc:h2:file:/var/lib/rundeck/data/rundeckdb;MVCC=true,jdbc:mysql://localhost/rundeckdb?autoReconnect=true,g" /etc/rundeck/rundeck-config.properties + echo -e "dataSource.username=rduser\ndataSource.password=rdpasswd" >> /etc/rundeck/rundeck-config.properties +elif [[ $3 == "postgres" ]]; then + apt-get -y install postgresql libpq-dev + su - postgres -c "createuser pguser -s" + echo -e "local all postgres peer\nlocal all pguser trust\nlocal all all peer\nhost all all 127.0.0.1/32 md5" | sudo tee /etc/postgresql/9.5/main/pg_hba.conf + systemctl restart postgresql +else + echo "Backend: $3 not supported!" + exit 1 +fi + +# Configure Rundeck +sed -i s,localhost,$1,g /etc/rundeck/framework.properties +sed -i "s,grails.serverURL=http://localhost:4440,grails.serverURL=http://$1:4440,g" /etc/rundeck/rundeck-config.properties hostname=`hostname` -sudo echo "$1 $hostname" | sudo tee -a /etc/hosts -sudo sed -i s,"/var/lib/rundeck:/bin/false","/var/lib/rundeck:/bin/bash",g /etc/passwd -sudo su rundeck -c "echo -e \"\n\" | ssh-keygen -t rsa -N \"\"" -sudo chown rundeck. /var/lib/rundeck +grep -q "$1 $hostname" /etc/hosts || echo "$1 $hostname" | sudo tee -a /etc/hosts +sed -i s,"/var/lib/rundeck:/bin/false","/var/lib/rundeck:/bin/bash",g /etc/passwd +chown rundeck. /var/lib/rundeck +ls /var/lib/rundeck/.ssh || sudo su rundeck -c "echo -e \"\n\" | ssh-keygen -t rsa -N \"\"" +mkdir /var/lib/rundeck/.rd +echo -e "export RD_URL=http://$1:4440\nexport RD_USER=admin\nexport RD_PASSWORD=admin" > /var/lib/rundeck/.rd/rd.conf +chown -R rundeck. /var/lib/rundeck/.rd +echo "rundeck ALL=NOPASSWD: /bin/systemctl reload bind9" > /etc/sudoers.d/rundeck +chmod 440 /etc/sudoers.d/rundeck +rundeck_url=`sudo cat /etc/rundeck/framework.properties |grep framework.server.url |awk '{print $3}'`.chomp +systemctl enable rundeckd +systemctl restart rundeckd +scripts/check_url.sh http://$1:4440 60 diff --git a/scripts/menu_chef.rb b/scripts/menu_chef.rb index 81a3bab..b3b7af5 100644 --- a/scripts/menu_chef.rb +++ b/scripts/menu_chef.rb @@ -11,11 +11,9 @@ def chef_menu "docker_folder" => DOCKER_FOLDER } vars=check_vars(vars) - puts "Installing Docker...".bold system("sudo scripts/install_docker.sh #{DOCKER_FOLDER}") get_ip_host - puts "\nDownloading container and start #{CHEF_SERVER_CONTAINER_NAME}".bold - system("scripts/install_docker_chef-server.sh #{CHEF_SERVER_CONTAINER_NAME} #{CHEF_PORT} #{DOCKER_FOLDER} #{Installer::IP_HOST}") + system("scripts/install_docker_chef-server.sh #{CHEF_SERVER_CONTAINER_NAME} #{CHEF_PORT} #{DOCKER_FOLDER}") generate_rundeck_job chef_rundeck self.class.const_set(:INSTALL_CHEF, "yes") @@ -33,20 +31,25 @@ def generate_rundeck_job File.open("#{DOCKER_FOLDER}/rundeck_jobs-chef.xml", "w") do |file| file.puts xml_content end - system("sudo su rundeck -c 'rd-project -p chef_server-control -a create'") - system("sudo su rundeck -c 'rd-jobs load -r -f #{DOCKER_FOLDER}/rundeck_jobs-chef.xml -p chef_server-control'") + dir=File.expand_path(File.dirname(__FILE__)) + system("#{dir}/../scripts/create_rd_projects.sh \"chef_server-control\" #{DOCKER_FOLDER}") end def chef_rundeck - bundle_install "chef-rundeck" - unless `ps aux |grep -v grep |grep chef-rundeck`.nil? - template = ERB.new(File.read("scripts/templates/chef-rundeck.conf.erb")) + unless `ps aux |grep -v grep |grep chef-rundeck` != "" + puts "Setting up chef-rundeck".bold + dir=File.expand_path(File.dirname(__FILE__)) + system("#{dir}/../scripts/get_and_install.sh \"chef-rundeck\"") + template = ERB.new(File.read("scripts/templates/chef-rundeck.service.erb")) xml_content = template.result(binding) - File.open("/etc/init/chef-rundeck.conf", "w") do |file| + File.open("/etc/systemd/system/chef-rundeck.service", "w") do |file| file.puts xml_content end - system("sudo initctl reload-configuration") + system("sudo systemctl daemon-reload") + system("sudo systemctl enable chef-rundeck") puts "\nStarting chef-rundeck...".bold - system("service chef-rundeck restart") + system("sudo systemctl start chef-rundeck") + else + puts "Chef-Rundeck already installed/configured and running. Skipping...".bold end end diff --git a/scripts/menu_main.rb b/scripts/menu_main.rb index 9c9d9ec..efe8370 100644 --- a/scripts/menu_main.rb +++ b/scripts/menu_main.rb @@ -1,6 +1,7 @@ #!/usr/bin/ruby require 'colorize' +require 'ipaddr' vars=File.expand_path("../../vars", __FILE__) eval File.read(vars) @@ -13,31 +14,28 @@ def initialize end def rundeck_menu - puts "\nDo you want to install Rundeck?".bold - puts " 1: Yes\n 2: No".green + puts "\nDo you want to install or update Rundeck?".bold + puts " 1: Yes\n 2: No (Rundeck already installed)".green + puts " 3: Exit..." case gets.strip when "1", "y" puts "Installing Rundeck...".bold - vars= {"rundeck_version" => RUNDECK_VERSION} + vars= {"rundeck_version" => RUNDECK_VERSION, + "backend" => BACKEND, + "mysql_password" => MYSQL_PASSWORD + } vars=check_vars(vars) get_ip_host - system("sudo scripts/install_rundeck.sh #{IP_HOST} #{RUNDECK_VERSION}") + system("sudo scripts/install_rundeck.sh #{IP_HOST} #{RUNDECK_VERSION} #{BACKEND} #{MYSQL_PASSWORD}") when "2", "n" puts "Moving on..." + when "3" + stop_install else rundeck_menu end end - def restart_rundeck - puts "\nRestart Rundeck to apply new groups to the rundeck user...".bold - rundeck_url=`sudo cat /etc/rundeck/framework.properties |grep framework.server.url |awk '{print $3}'`.chomp - self.class.const_set(:RUNDECK_URL, rundeck_url) - system("sudo service rundeckd restart") - system("sudo scripts/check_url.sh #{RUNDECK_URL} 60") - puts "\n" - end - def main_menu puts "\nWhat would you like to install?".bold puts " 1: kvm-control".green + " - Nat only".bold @@ -60,7 +58,7 @@ def main_menu "bind9" => BIND9} vars=check_vars(vars) self.class.const_set(:FLOATING, "no") - system("sudo scripts/install_kvm.sh #{KVM_FOLDER} #{BACKEND} #{MYSQL_PASSWORD} #{BIND9}") + system("sudo scripts/install_kvm.sh #{KVM_FOLDER} #{BIND9}") get_rundeck_key get_ip_host generate_scripts BACKEND, DATABASE_NAME, DB_KVM_TABLE, MYSQL_PASSWORD, KVM_FOLDER, SSH_KEYS, FLOATING, RUNDECK_KEY, BIND9, IP_HOST @@ -73,7 +71,7 @@ def main_menu end system("sudo chown -R rundeck. #{KVM_FOLDER}") when "2" - files=["generate_scripts-floating.rb", "chef_generate_scripts-floating.rb", "setup_db.rb", "get_first_cloud_image.rb"] + files=["generate_scripts-floating.rb", "chef_generate_scripts.rb", "setup_db.rb", "get_first_cloud_image.rb"] files.each do |file| require_relative "../kvm/#{file}" end @@ -89,6 +87,21 @@ def main_menu "ssh_keys" => SSH_KEYS, "bind9" => BIND9} vars=check_vars(vars) + ips = [START_IP, END_IP, GATEWAY_IP] + ips.each do |ip| + begin + ipaddress=IPAddr.new ip.to_s + rescue + puts "IP (#{ip}) is not valid or nil!\nStopping now...".red + exit 1 + end + end + ip_start = IPAddr.new START_IP + ip_end = IPAddr.new END_IP + if ip_start >= ip_end + puts "START_IP (#{ip_start}) should start before END_IP (#{ip_end})! Please fix!" + exit 1 + end self.class.const_set(:FLOATING, "yes") system("sudo scripts/install_kvm.sh #{KVM_FOLDER} #{BACKEND} #{MYSQL_PASSWORD} #{BIND9}") get_rundeck_key @@ -107,10 +120,9 @@ def main_menu vars= {"docker_folder" => DOCKER_FOLDER} vars=check_vars(vars) system("sudo scripts/install_docker.sh #{DOCKER_FOLDER}") - system("sudo su rundeck -c 'rd-project -p docker-control -a create'") - system("sudo su rundeck -c 'rd-jobs load -r -f #{DOCKER_FOLDER}/rundeck_jobs.xml -p docker-control'") + dir=File.expand_path(File.dirname(__FILE__)) + system("#{dir}/../scripts/create_rd_projects.sh \"docker-control\" #{DOCKER_FOLDER}") when "4" - restart_rundeck bye exit 0 else @@ -120,12 +132,12 @@ def main_menu end def get_ip_host - require 'ipaddress' ip_host=`sudo scripts/get_interface_ip.rb #{CLOUD_SERVER} #{INTERFACE_OUT}`.chomp - if IPAddress.valid? ip_host + begin + ip_local=IPAddr.new ip_host self.class.const_set(:IP_HOST, ip_host) - else - puts "Host IP is not valid or nil!\nStopping now...".red + rescue + puts "Host IP (#{ip_host}) is not valid or nil!\nStopping now...".red exit 1 end end @@ -184,7 +196,8 @@ def install_bind9(install, floating) end system("sudo adduser rundeck bind") system("sudo chmod 775 /etc/bind/") - system("sudo service bind9 restart") + system("sudo chown rundeck:bind /etc/bind/db.local") + system("sudo systemctl restart bind9") end end @@ -195,7 +208,6 @@ def install_done when "1", "y" main_menu when "2", "n" - restart_rundeck bye exit 0 else @@ -203,8 +215,13 @@ def install_done end end + def stop_install + puts "\nStopping Mission_Control install!" + exit 0 + end + def bye - rundeck_url_full=`sudo cat /etc/rundeck/framework.properties |grep framework.server.url |awk '{print $3}'`.chomp.bold+"/menu/home".bold + rundeck_url_full=`sudo cat /etc/rundeck/framework.properties |grep framework.server.url |awk '{print $3}'`.chomp.bold puts " _ ,' '. diff --git a/scripts/templates/chef-rundeck.conf.erb b/scripts/templates/chef-rundeck.conf.erb deleted file mode 100644 index b6923c5..0000000 --- a/scripts/templates/chef-rundeck.conf.erb +++ /dev/null @@ -1,15 +0,0 @@ -# chef-rundeck init - -description "Chef Rundeck Sinatra App" - -start on filesystem or runlevel [2345] -stop on runlevel [!2345] - -respawn -respawn limit 10 5 - -console log -setuid rundeck -env HOME=/var/lib/rundeck - -exec chef-rundeck -c /var/lib/rundeck/.chef/knife.rb -e development -u ubuntu -P /tmp/chef-rundeck.pid -w https://<%= Installer::IP_HOST %>:<%= CHEF_PORT %> diff --git a/scripts/templates/chef-rundeck.service.erb b/scripts/templates/chef-rundeck.service.erb new file mode 100644 index 0000000..afdd68c --- /dev/null +++ b/scripts/templates/chef-rundeck.service.erb @@ -0,0 +1,10 @@ +[Unit] +Description=Chef Rundeck Sinatra App +After=syslog.target + +[Service] +ExecStart=/usr/local/bin/chef-rundeck -c /var/lib/rundeck/.chef/config.rb -e development -u ubuntu -P /tmp/chef-rundeck.pid -w https://<%= Installer::IP_HOST %>:<%= CHEF_PORT %> +User=rundeck + +[Install] +WantedBy=default.target diff --git a/vars b/vars index 9d3818a..4c597e4 100644 --- a/vars +++ b/vars @@ -8,13 +8,13 @@ DATA_FOLDER="/srv/mission_control" KVM_FOLDER=DATA_FOLDER + "/kvm-control" DOCKER_FOLDER=DATA_FOLDER + "/docker-control" -RUNDECK_VERSION="2.3.1-1" +RUNDECK_VERSION="2.7.3-1" DATABASE_NAME="mission_control" MYSQL_PASSWORD="mcpasswd" DB_KVM_TABLE="kvm_guests" # Is this server running in a public cloud? (i.e Is this server reachable directly from the Internet? AWS/GoogleCloud/Rackspace) # yes OR no -CLOUD_SERVER="" +CLOUD_SERVER="no" # Which interface will be used to reach Rundeck? # NOTE: must be br0 is you are going to assign static Floating IPs to KVM guests! INTERFACE_OUT="eth0"