def reboot_server(name): """ Simply reboot a server by name. The trick here is to change the env vars to that of the server to be rebooted. Perform the reboot and change env vars back to their original value. Usage: fab reboot_server:name """ __shared_setup() try: server = [s for s in env.bootmachine_servers if s.name == name][0] except IndexError: abort("The server '{0}' was not found.".format(name)) original_user = env.user original_host_string = env.host_string try: env.port = 22 telnetlib.Telnet(server.public_ip, env.port) env.user = "******" except IOError: env.port = int(settings.SSH_PORT) env.user = getpass.getuser() telnetlib.Telnet(server.public_ip, env.port) env.host_string = "{0}:{1}".format(server.public_ip, env.port) env.keepalive = 30 # keep the ssh key active, see fabric issue #402 with fabric_settings(warn_only=True): reboot() env.user = original_user env.host_string = original_host_string
def degflasher(): """ Information about how to flash your cards in order to improve performance at http://flasher.degconnect.com. :return: """ reboot(wait=45) run('degflasher')
def install_dokku(self): """ https://github.com/progrium/dokku """ log('info', 'Installing dokku', show_header=True) run('curl -sL https://raw.github.com/progrium/dokku/v0.2.3/bootstrap.sh > ~/dokku-install.sh' ) sudo( 'DOKKU_TAG=v0.2.3 bash ~/dokku-install.sh; rm -f ~/dokku-install.sh' ) put('~/.ssh/id_rsa.pub', '~', mirror_local_mode=True) run('cat ~/id_rsa.pub | sudo sshcommand acl-add {} ubuntu'.format( config['deploy_user'])) run('rm ~/id_rsa.pub') reboot(wait=5 * 60) sudo( 'git clone https://github.com/statianzo/dokku-supervisord.git /var/lib/dokku/plugins/dokku-supervisord' ) sudo( 'git clone https://github.com/neam/dokku-custom-domains.git /var/lib/dokku/plugins/custom-domains' ) sudo( 'git clone https://github.com/musicglue/dokku-user-env-compile.git /var/lib/dokku/plugins/user-env-compile' ) sudo('dokku plugins-install')
def debian_upgrade_reboot(): """ debian_upgrade() + reboot for first time/kernel installs. """ debian_upgrade() if exists('/var/run/reboot-required', True): reboot(REBOOT_TIME)
def deploy(): sudo('yum update -y') sudo('yum install -y docker') sudo('service docker start') sudo('usermod -a -G docker ec2-user') print('rebooting to register new user...') reboot(wait=60) print('okay we back') # run('docker pull segfaults/gcmt_viewer') sudo( 'curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > docker-compose' ) sudo('chown root docker-compose') sudo('mv docker-compose /usr/local/bin') sudo('chmod +x /usr/local/bin/docker-compose') # run('exit') sudo('yum install -y git') run('git clone https://github.com/Seg-Faults/gcmt_viewer.git') run('cd gcmt_viewer') print("***CHECKING OUT VERSION1.0***") run('git checkout version1.0') run('docker-compose up')
def init_daemon_install(): """ Switch from upstart to systemd """ ret = sudo('stat /proc/1/exe') if 'upstart' in ret: sudo('apt-get -y install systemd-sysv ubuntu-standard') sudo('update-initramfs -u') reboot(REBOOT_TIME)
def server_reboot(): """ Reboot host """ check_sudo() check_os() if not confirm('Do you want to reboot server?'): return reboot(wait=180)
def install_os_dependencies(): packages = [ 'build-essential', 'mysql-server', 'libmysqlclient-dev', 'apache2', 'php5-mysql', 'libapache2-mod-php5', 'php5-mcrypt', 'php5-gd', 'php5-curl' ] sudo('apt-get update') sudo('apt-get -y upgrade') reboot(120) sudo('apt-get -y install %s' % ' '.join(packages))
def upgrade(packages=[]): wait = 600 if isinstance(packages, dict): packages = packages[env.host_string] if not packages: return puppet.run_agent() apt.run_upgrade(packages) puts('Rebooting machine (going to wait %s seconds)' % wait) reboot(wait=wait)
def store_server_image(image_name): reboot(5) image = rackspace.images.create(image_name, current_server.id) while image.status != u"ACTIVE": time.sleep(5) image = rackspace.images.get(image.id) print "status: " + image.status if image.status in [u"ACTIVE", u"SAVING"]: print "progress: " + str(image.progress) current_server.delete()
def _unload_nouveau(): lines = [] lines.append("blacklist vga16fb") lines.append("blacklist nouveau") lines.append("blacklist rivafb") lines.append("blacklist nvidiafb") lines.append("blacklist rivatv") append("/etc/modprobe.d/blacklist.conf", lines, use_sudo=True) sudo("update-initramfs -u") reboot()
def reboot(self, server_ip): i = socket.gethostbyaddr(server_ip)[0] print "rebooting %s" % i if server_ip in self.host_data.keys(): username = self.host_data[server_ip]['username'] password = self.host_data[server_ip]['password'] with hide('everything'): with settings( host_string='%s@%s' % (username, server_ip), password=password, warn_only=True, abort_on_prompts=False): reboot(wait=300) run('date')
def _install_cuda(): _unload_nouveau() with cd("/mnt"): if not exists("/mnt/cuda_7.5.18_linux.run"): sudo("wget http://developer.download.nvidia.com/compute/cuda/7.5/Prod/local_installers/cuda_7.5.18_linux.run") sudo("chmod 755 cuda_7.5.18_linux.run") sudo("./cuda_7.5.18_linux.run -silent --driver --toolkit --samples") reboot() with cd("/usr/local/cuda-7.5/samples/1_Utilities/deviceQuery"): sudo("make")
def _install_depends(): sudo("apt-get update") sudo("apt-get upgrade -y") sudo("apt-get install -y linux-generic") sudo("apt-get install -y linux-image-generic-lts-trusty") reboot() sudo("apt-get install -y linux-headers-`uname -r`") sudo("apt-get install -y build-essential") sudo("apt-get install -y git") sudo("apt-get install -y wget curl")
def install_dokku(self): """ https://github.com/progrium/dokku """ log('info', 'Installing dokku', show_header=True) run('curl -sL https://raw.github.com/progrium/dokku/v0.3.15/bootstrap.sh > ~/dokku-install.sh') sudo('DOKKU_TAG=v0.3.15 bash ~/dokku-install.sh; rm -f ~/dokku-install.sh') reboot(wait=5*60) sudo('git clone https://github.com/statianzo/dokku-supervisord.git /var/lib/dokku/plugins/dokku-supervisord') sudo('git clone https://github.com/neam/dokku-custom-domains.git /var/lib/dokku/plugins/custom-domains') sudo('git clone https://github.com/musicglue/dokku-user-env-compile.git /var/lib/dokku/plugins/user-env-compile') sudo('dokku plugins-install')
def reboot_system(): """ Reboot system for the next step """ print("Please wait and do the next step: ") print("""From you physical computer # after reboot select "Boot existing OS" loadkeys fr dhcpcd systemctl start sshd """) print("fab -f fabrecipes/archlinux/autoinstall.py -H root@%s computer_sample configure" % env.host) reboot(1)
def _reboot(instance_id, force=False): """ Reboot current instance if required. Reboot can be forced by setting the method's 'force' parameter to True. :rtype: bool :return: If instance was rebooted, return True. Note that this primarily indicates if the instance was rebooted and does not guarantee that the instance is accessible. False, otherwise. """ if (force or exists("/var/run/reboot-required")) and instance_id: answer = False if not force: answer = confirm("Before rebundling, instance '%s' needs to be rebooted. Reboot instance?" % instance_id) if force or answer: wait_time = 60 print "Rebooting instance with ID '%s' and waiting %s seconds" % (instance_id, wait_time) try: reboot(wait_time) return True # ec2_conn.reboot_instances([instance_id]) - to enable this back up, will need to change method signature # print "Instance '%s' with IP '%s' rebooted. Waiting (%s sec) for it to come back up." % (instance_id, env.hosts[0], str(wait_time)) # time.sleep(wait_time) # for i in range(30): # ssh = None # with settings(warn_only=True): # print "Checking ssh connectivity to instance '%s'" % env.hosts[0] # ssh = local('ssh -o StrictHostKeyChecking=no -i %s %s@%s "exit"' % (env.key_filename[0], env.user, env.hosts[0])) # if ssh.return_code == 0: # print(green("\n--------------------------")) # print(green("Machine '%s' is alive" % env.hosts[0])) # print(green("This script will exit now. Invoke it again while passing method name 'rebundle' as the last argument to the fab script.")) # print(green("--------------------------\n")) # return True # else: # print "Still waiting..." # time.sleep(3) # if i == 29: # print(red("Machine '%s' did not respond for while now, aborting" % env.hosts[0])) # return True # except EC2ResponseError, e: # print(red("Error rebooting instance '%s' with IP '%s': %s" % (instance_id, env.hosts[0], e))) # return False except Exception, e: print(red("Error rebooting instance '%s' with IP '%s': %s" % (instance_id, env.hosts[0], e))) print(red("Try running this script again with 'rebundle' as the last argument.")) return False else: print(red("Cannot rebundle without instance reboot. Aborting rebundling.")) return False
def bootstrap(): """ Bootstrap Ubuntu for use with the configuration manager of choice. Only the bare essentials, the configuration manager will take care of the rest. """ run("/usr/sbin/locale-gen en_US.UTF-8 && /usr/sbin/update-locale LANG=en_US.UTF-8") run("aptitude update") append("/etc/hosts", "{0} saltmaster-private".format(env.master_server.private_ip)) with fabric_settings(warn_only=True): reboot() run("aptitude install -y build-essential") # allow users in the wheel group to sudo without a password uncomment("/etc/sudoers", "wheel.*NOPASSWD")
def full_deploy(): update_apt() install_python3_prereqs() install_python3() fetch_get_pip_script() install_pip3() install_pip2() render_templates() upload_project(remote_dir=config.remote_dir) install_requirements() install_supervisor() update_boot_file() reboot() update_iptables()
def deploy(): update_debian_package_lists() remove_unneeded_debian_packages() for package in DEBIAN_PACKAGES_TO_INSTALL: install_debian_package(package) install_python_modules() install_rascal_software() install_config_files() allow_uwsgi_to_control_supervisor() allow_uwsgi_to_access_usb_port() install_oh_my_zsh() autoremove_debian_package_remnants() print(green('Rascal 2 deployment complete. Rebooting . . .')) reboot()
def prepare(): """ Script that prepare the system: Set hostname, /etc/hosts, disable selinux, copy authorized_keys (ssh credentials) and reboot the system """ if not exists('/root/.fabric.prepared'): write_hosts() write_hostname() disable_selinux() ssh_keys() append('/root/.fabric.prepared', '') reboot() else: print(yellow("Skipped system %s " % env.host))
def bootstrap(): """ Bootstrap Ubuntu for use with the configuration manager of choice. Only the bare essentials, the configuration manager will take care of the rest. """ run("/usr/sbin/locale-gen en_US.UTF-8 && /usr/sbin/update-locale LANG=en_US.UTF-8") with fabric_settings(warn_only=True): run("aptitude update && aptitude -y dist-upgrade") append("/etc/hosts", "{0} saltmaster-private".format(env.master_server.private_ip)) with fabric_settings(warn_only=True): reboot() run("aptitude install -y build-essential rsync sudo") append("/etc/sudoers", "## allow members of group wheel to execute any command\n%wheel ALL=(ALL) ALL")
def install_dokku(self): """ https://github.com/progrium/dokku """ log('info', 'Installing dokku', show_header=True) run('curl -sL https://raw.github.com/progrium/dokku/v0.2.3/bootstrap.sh > ~/dokku-install.sh') sudo('DOKKU_TAG=v0.2.3 bash ~/dokku-install.sh; rm -f ~/dokku-install.sh') put('~/.ssh/id_rsa.pub', '~', mirror_local_mode=True) run('cat ~/id_rsa.pub | sudo sshcommand acl-add {} ubuntu'.format(config['deploy_user'])) run('rm ~/id_rsa.pub') reboot(wait=5*60) sudo('git clone https://github.com/statianzo/dokku-supervisord.git /var/lib/dokku/plugins/dokku-supervisord') sudo('git clone https://github.com/neam/dokku-custom-domains.git /var/lib/dokku/plugins/custom-domains') sudo('git clone https://github.com/musicglue/dokku-user-env-compile.git /var/lib/dokku/plugins/user-env-compile') sudo('dokku plugins-install')
def _install_depends(): sudo("apt-get update") sudo("apt-get upgrade -y") sudo("apt-get install -y linux-generic") reboot() sudo("apt-get install -y linux-headers-`uname -r`") sudo("apt-get install -y build-essential") sudo("apt-get install -y git") sudo("apt-get install -y wget") sudo("apt-get install -y libjpeg-dev libblas-dev libatlas-dev libatlas-base-dev liblapack-dev gfortran") sudo("apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev") sudo("apt-get install -y libhdf5-serial-dev bc libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler") sudo("apt-get install -y python-pip")
def prepare(privateip=None, privatemask='255.255.168.0'): """ Script that prepare the system: Set hostname, /etc/hosts, disable selinux, copy authorized_keys (ssh credentials) and reboot the system Ex: fab -H moooc.example.com -u root prepare:privateip='198.168.0.1',privatemask='255.255.168.0' """ if not exists('/root/.fabric.prepared'): write_hosts() write_hostname() disable_selinux() add_private_ip(privateip, privatemask) ssh_keys() append('/root/.fabric.prepared', '') reboot() else: print(yellow("Skipped system %s " % env.host))
def _handle_special(name, check=True): from importlib import import_module module_name = _special_map.get(name, None) if module_name: mod = import_module(module_name) return (True, mod.tool_check() if check else mod.tool_install()) if name == "reboot": if check: return (True, False) else: start_msg("----- Rebooting instance (may take a few minutes):") reboot() succeed_msg("Rebooted successfully.") return (True, None) return (False, None)
def emerge(version='3.0.6'): run("echo 'sys-kernel/gentoo-sources symlink' \ > /etc/portage/package.use/gentoo-sources") run("emerge -q -uDN '=sys-kernel/gentoo-sources-%s'" % version) with cd("/usr/src/linux"): run("cp -vf /boot/config-`uname -r` .config") run("make oldconfig < /dev/null") run("make prepare") run("make -j 9") kernel_suffix = run("make modules_install \ | grep DEPMOD \ | awk '{print $2}'") run("cp -vf arch/x86_64/boot/bzImage \ /boot/kernel-%s" % kernel_suffix) run("cp -vf System.map /boot/System.map-%s" % kernel_suffix) run("cp -vf .config /boot/config-%s" % kernel_suffix) with cd("/boot/"): kernels = run('ls kernel-*').split() new_kernel_idx = kernels.index("kernel-%s" % kernel_suffix) menulst = [ "default %d" % new_kernel_idx, "timeout 10", ] for kernel in kernels: menulst += [ "", "title %s" % kernel, "root (hd0,5)", "kernel /boot/%s root=/dev/sda6" % kernel, ] menulst = ''.join([line + '\n' for line in menulst]) with cd("/boot/grub"): run("cat > menu.lst.new << EOF\n" + menulst + "\nEOF\n") run("mv -vf menu.lst menu.lst.old") run("mv -vf menu.lst.new menu.lst") run("cat menu.lst") reboot(180) run("uname -r")
def _install_depends(): sudo("apt-get update") sudo("apt-get upgrade -y") sudo("apt-get install -y linux-generic") reboot() sudo("apt-get install -y linux-headers-`uname -r`") sudo("apt-get install -y build-essential") sudo("apt-get install -y git") sudo("apt-get install -y wget") sudo( "apt-get install -y libjpeg-dev libblas-dev libatlas-dev libatlas-base-dev liblapack-dev gfortran" ) sudo( "apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev" ) sudo( "apt-get install -y libhdf5-serial-dev bc libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler" ) sudo("apt-get install -y python-pip")
def prepareInstance(username, sshId): """Prepare an instance updating the packages and creating a new user. @param username: The name of the new user. @param sshId: Path to SSH public key (usually ~/.ssh/id_rsa.pub) """ print os.environ['EC2_KEYPAIR_PATH'] with settings(user='******', key_filename=os.environ['EC2_KEYPAIR_PATH']): password = getpass('Enter a new password for user %s:' % username) password2 = getpass('Enter the password a again:') if password != password2: raise RuntimeError("Passwords don't match") sudo('adduser --disabled-password --gecos ",,," %s' % username) cryptedPassword = _hashPassword(password) sudo('usermod --password %s %s' % (cryptedPassword, username)) sudo('gpasswd --add %s admin' % username) authorizeSshKey(username, sshId) sudo('apt-get update') sudo('DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y') if exists('/var/run/reboot-required'): reboot()
def deploy(): sudo('yum update -y') sudo('yum install -y docker') sudo('service docker start') sudo('usermod -a -G docker ec2-user') print('rebooting to register new user...') reboot(wait=60) print('okay we back') # run('docker pull segfaults/gcmt_viewer') sudo('curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > docker-compose') sudo('chown root docker-compose') sudo('mv docker-compose /usr/local/bin') sudo('chmod +x /usr/local/bin/docker-compose') # run('exit') sudo('yum install -y git') run('git clone https://github.com/Seg-Faults/gcmt_viewer.git') run('cd gcmt_viewer') print("***CHECKING OUT VERSION1.0***") run('git checkout version1.0') run('docker-compose up')
def bootstrap(): """ Bootstrap Fedora. Only the bare essentials, salt takes care of the rest. """ base_packages = [ "curl", "git", "rsync", ] run("/usr/bin/localedef -i en_US -f UTF-8 en_US.UTF-8") run("export LC_ALL=en_US.UTF-8 && export LANG=en_US.UTF-8") append("/etc/sysconfig/i18n", 'LC_ALL="en_US.UTF-8"') run("yum update --assumeyes") run("yum groupinstall --assumeyes 'Development Tools'") run("yum install --assumeyes {pkgs}".format(pkgs=" ".join(base_packages))) append("/etc/hosts", "{0} saltmaster-private".format(env.master_server.private_ip)) # allow users in the wheel group to sudo without a password uncomment("/etc/sudoers", "wheel.*NOPASSWD") with fabric_settings(warn_only=True): reboot()
host_password = HOST_PASSWORD ROOT_URI = "https://" + host_ip + ":9090" env.host_string = host_user + '@' + host_ip env.password = host_password he_vm_fqdn = HE_VM_FQDN he_vm_ip = HE_VM_IP he_vm_password = HE_VM_PASSWORD engine_password = ENGINE_PASSWORD he_data_nfs = HE_DATA_NFS second_vm_fqdn = SECOND_VM_FQDN # Reboot the host before test with settings(warn_only=True): reboot(wait=600) time.sleep(300) @pytest.fixture(scope="session", autouse=True) def _environment(request): with settings(warn_only=True): cmd = "rpm -qa|grep cockpit-ovirt" cockpit_ovirt_version = run(cmd) cmd = "rpm -q imgbased" result = run(cmd) if result.failed: cmd = "cat /etc/redhat-release" redhat_release = run(cmd) request.config._environment.append(
def set_hostname(): prompt('Enter new hostname: ', 'hostname', default='rascal2') print(green('Setting hostname to: ' + env.hostname)) run('echo ' + env.hostname + ' > /etc/hostname') print(green('Rebooting . . .')) reboot()
def restart_machines(): try: reboot(1) except: print "couldn't restart machine %s" % env.host_string
def _install_docker(): sudo("curl -sSL https://get.docker.com/ | sh") sudo("usermod -G docker ubuntu") reboot()
def reboot_stage2(): metadata = Config(os.environ["CONFIGFILE"]) puts(red("rebooting %s" % env.host_string)) reboot()
def update_system(): cuisine.package_upgrade() reboot(command='shutdown -r +0')
def upgrade(): sudo('apt-get update -qq && apt-get upgrade -yqq') if exists('/var/run/reboot-required') and confirm( 'Needs reboot, do it now?'): print(red('Rebooting now', True)) reboot()
def setup(): if not is_checkin(): install_requirements() update_cron() reboot() print 'end'
def cleanup(): """ Reboots Instance """ reboot()
def reboot_pi(): """ Reboots the target host. """ reboot(wait=5)
def server_reboot(): """ Reboot Ubuntu """ reboot()
def launch(dbtemplate="template_postgis"): """ Launches all nodes in the given env: ./contrib/fab.py Usage: fab loadbalancer launch fab dbserver launch:template_postgis fab appnode launch fab cachenode launch fab appbalancer launch """ raise NotImplementedError() if exists("{0}.launched".format(settings.DEPLOY_HOME)): print(green("``{0}`` has already been launched, skipping".format(env.host))) return # These Python packages are essential for bootstrapping. BASE_PYTHON_PACKAGES = [ "Mercurial==2.0", "virtualenv==1.6.4", "Jinja2==2.6", ] if hasattr(settings, "EXTRA_BASE_PYTHON_PACKAGES"): BASE_PYTHON_PACKAGES.append(settings.EXTRA_BASE_PYTHON_PACKAGES) # python/pip setup # run("wget http://python-distribute.org/distribute_setup.py && python distribute_setup.py") # run("easy_install pip") # run("pip install {0}".format(" ".join(BASE_PYTHON_PACKAGES))) # run("pip install meld3==0.6.7") # https://bugs.launchpad.net/ubuntu/+source/supervisor/+bug/777862 # server type specifics if "broker" or "cachenode" in env.server_types: pass if "loadbalancer" in env.server_types: sudo("ls -hal") nginx.dissite(site="default") for site in settings.SITES: nginx.ensite(site=site["name"]) if "dbserver" in env.server_types: reboot(10) # Kokki changed the `shhmax` kernel settings, reboot required. if dbtemplate == "template_postgis": # http://proft.me/2011/08/31/ustanovka-geodjango-postgresql-9-postgis-pod-ubunt/ with cd("/tmp/"): run("wget http://postgis.refractions.net/download/postgis-1.5.3.tar.gz") run("tar zxvf postgis-1.5.3.tar.gz") with cd("/tmp/postgis-1.5.3/"): sudo("./configure && make && checkinstall --pkgname postgis-1.5.3 --pkgversion 1.5.3-src --default") run("wget http://docs.djangoproject.com/en/dev/_downloads/create_template_postgis-1.5.sh -O /tmp/create_template_postgis-1.5.sh") run("chmod 777 /tmp/create_template_postgis-1.5.sh") sudo("/tmp/create_template_postgis-1.5.sh", user="******") sudo("rm -rf /tmp/*postgis*") else: raise NotImplementedError() for dbname, password in settings.DATABASES.iteritems(): postgresql.pg_dblaunch(dbname, password, dbtemplate) if "appnode" in env.server_types: sudo("mkdir --parents /var/log/gunicorn/ /var/log/supervisor/ && chown -R deploy:www-data /var/log/gunicorn/") # move to recipies sudo("ln -sf /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/") sudo("ln -sf /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/") sudo("ln -sf /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/") if not exists(settings.LIB_ROOT): run("mkdir --parents {0}".format(settings.LIB_ROOT)) with cd(settings.LIB_ROOT): run("git clone [email protected]:{0}/deploymachine.git && git checkout master".format(settings.GITHUB_USERNAME)) with cd(settings.LIB_ROOT): # TODO move these into a contrib_local list or call an extra checkouts signal? run("git clone [email protected]:{0}/scenemachine.git scenemachine && git checkout master".format(settings.GITHUB_USERNAME)) run("git submodule init && git submodule update") run("git clone git://github.com/pinax/pinax.git") with cd(settings.PINAX_ROOT): run("git checkout {0}".format(settings.PINAX_VERSION)) launch_apps() print(green("sucessfully launched!")) run("touch {0}.launched".format(settings.DEPLOY_HOME))
def _reboot_instance(): reboot(command="shutdown -r +0")
def post_install(): """ Post install operations on a Fedora system """ reboot()