def __setup_agent(self): availability_zone = self.ctx.availability_zone namespace = self.ctx.namespace ec2_keypair_globs = ' '.join( shell.quote(_) for _ in self.ec2_keypair_globs) accounts = ' '.join([self.admin_account()] + self.other_accounts()) admin_account = self.admin_account() run_dir = '/var/run/cgcloudagent' log_dir = '/var/log' install_dir = '/opt/cgcloudagent' # Lucid & CentOS 5 have an ancient pip pip('install --upgrade pip==1.5.2', use_sudo=True) pip('install --upgrade virtualenv', use_sudo=True) sudo(fmt('mkdir -p {install_dir}')) sudo(fmt('chown {admin_account}:{admin_account} {install_dir}')) # By default, virtualenv installs the latest version of pip. We want a specific # version, so we tell virtualenv not to install pip and then install that version of # pip using easy_install. run(fmt('virtualenv --no-pip {install_dir}')) run(fmt('{install_dir}/bin/easy_install pip==1.5.2')) with settings(forward_agent=True): venv_pip = install_dir + '/bin/pip' if self._enable_agent_metrics(): pip(path=venv_pip, args='install psutil==3.4.1') with self._project_artifacts('agent') as artifacts: pip( path=venv_pip, args=concat( 'install', '--allow-external', 'argparse', # needed on CentOS 5 and 6 artifacts)) sudo(fmt('mkdir {run_dir}')) script = self.__gunzip_base64_decode( run( fmt('{install_dir}/bin/cgcloudagent' ' --init-script' ' --zone {availability_zone}' ' --namespace {namespace}' ' --accounts {accounts}' ' --keypairs {ec2_keypair_globs}' ' --user root' ' --group root' ' --pid-file {run_dir}/cgcloudagent.pid' ' --log-spill {log_dir}/cgcloudagent.out' '| gzip -c | base64'))) self._register_init_script('cgcloudagent', script) self._run_init_script('cgcloudagent')
def __setup_agent( self ): availability_zone = self.ctx.availability_zone namespace = self.ctx.namespace ec2_keypair_globs = ' '.join( shell.quote( _ ) for _ in self.ec2_keypair_globs ) accounts = ' '.join( [ self.admin_account( ) ] + self.other_accounts( ) ) admin_account = self.admin_account( ) run_dir = '/var/run/cgcloudagent' log_dir = '/var/log' install_dir = '/opt/cgcloudagent' # Lucid & CentOS 5 have an ancient pip pip( 'install --upgrade pip==1.5.2', use_sudo=True ) pip( 'install --upgrade virtualenv', use_sudo=True ) sudo( fmt( 'mkdir -p {install_dir}' ) ) sudo( fmt( 'chown {admin_account}:{admin_account} {install_dir}' ) ) # By default, virtualenv installs the latest version of pip. We want a specific # version, so we tell virtualenv not to install pip and then install that version of # pip using easy_install. run( fmt( 'virtualenv --no-pip {install_dir}' ) ) run( fmt( '{install_dir}/bin/easy_install pip==1.5.2' ) ) with settings( forward_agent=True ): venv_pip = install_dir + '/bin/pip' if self._enable_agent_metrics( ): pip( path=venv_pip, args='install psutil==3.4.1' ) with self._project_artifacts( 'agent' ) as artifacts: pip( path=venv_pip, args=concat( 'install', '--allow-external', 'argparse', # needed on CentOS 5 and 6 artifacts ) ) sudo( fmt( 'mkdir {run_dir}' ) ) script = self.__gunzip_base64_decode( run( fmt( '{install_dir}/bin/cgcloudagent' ' --init-script' ' --zone {availability_zone}' ' --namespace {namespace}' ' --accounts {accounts}' ' --keypairs {ec2_keypair_globs}' ' --user root' ' --group root' ' --pid-file {run_dir}/cgcloudagent.pid' ' --log-spill {log_dir}/cgcloudagent.out' '| gzip -c | base64' ) ) ) self._register_init_script( 'cgcloudagent', script ) self._run_init_script( 'cgcloudagent' )
def __setup_agent( self ): kwargs = dict( availability_zone=self.ctx.availability_zone, namespace=self.ctx.namespace, ec2_keypair_globs=' '.join( shell.quote( _ ) for _ in self.ec2_keypair_globs ), accounts=' '.join( [ self.admin_account( ) ] + self.other_accounts( ) ), admin_account=self.admin_account( ), run_dir='/var/run/cgcloudagent', log_dir='/var/log', install_dir='/opt/cgcloudagent', agent_artifacts=' '.join( self._project_artifacts( 'agent' ) ) ) def fmt( s ): return s.format( **kwargs ) sudo( 'pip install --upgrade pip==1.5.2', pty=False ) # lucid & centos5 have an ancient pip sudo( 'pip install --upgrade virtualenv', pty=False ) sudo( fmt( 'mkdir -p {install_dir}' ) ) sudo( fmt( 'chown {admin_account}:{admin_account} {install_dir}' ) ) # By default, virtualenv installs the latest version of pip. We want a specific # version, so we tell virtualenv not to install pip and then install that version of # pip using easy_install. run( fmt( 'virtualenv --no-pip {install_dir}' ) ) run( fmt( '{install_dir}/bin/easy_install pip==1.5.2' ) ) with settings( forward_agent=True ): run( fmt( '{install_dir}/bin/pip install ' '--allow-external argparse ' # needed on CentOS 5 and 6 for some reason '{agent_artifacts}' ), pty=False ) sudo( fmt( 'mkdir {run_dir}' ) ) script = self.__gunzip_base64_decode( run( fmt( '{install_dir}/bin/cgcloudagent' ' --init-script' ' --zone {availability_zone}' ' --namespace {namespace}' ' --accounts {accounts}' ' --keypairs {ec2_keypair_globs}' ' --user root' ' --group root' ' --pid-file {run_dir}/cgcloudagent.pid' ' --log-spill {log_dir}/cgcloudagent.out' '| gzip -c | base64' ) ) ) self._register_init_script( 'cgcloudagent', script ) self._run_init_script( 'cgcloudagent' )
def generate_init_script(options): from pkg_resources import resource_string import cgcloud.agent import platform distro, version, codename = map(str.lower, platform.linux_distribution()) console = None if distro == 'ubuntu': quote_level = 1 if codename < 'vivid': script = 'init-script.upstart' # Lucid's version of upstart doesn't support "console log", Precise's does, don't know # about the versions in between console = 'output' if codename < 'precise' else 'log' else: script = 'init-script.systemd' else: script = 'init-script.lsb' quote_level = 2 init_script = resource_string(cgcloud.agent.__name__, script) args = [ '--namespace', options.namespace, '--zone', options.availability_zone, '--interval', str(options.interval), '--accounts' ] + options.accounts + ['--keypairs'] + options.ec2_keypair_names + [ '--user', options.user, '--group', options.group, '--pid-file', options.pid_file, '--log-level', options.log_level, '--log-spill', options.log_spill ] variables = vars(options).copy() variables.update( dict(args=' '.join( shell.quote(arg, level=quote_level) for arg in args), exec_path=exec_path, exec_name=exec_name, console=console, description=description)) print init_script % variables
def generate_init_script( options ): from pkg_resources import resource_string import cgcloud.agent import platform distro, version, codename = map( str.lower, platform.linux_distribution( ) ) console = None if distro == 'ubuntu': quote_level = 1 if codename < 'vivid': script = 'init-script.upstart' # Lucid's version of upstart doesn't support "console log", Precise's does, don't know # about the versions in between console = 'output' if codename < 'precise' else 'log' else: script = 'init-script.systemd' else: script = 'init-script.lsb' quote_level = 2 init_script = resource_string( cgcloud.agent.__name__, script ) args = [ '--namespace', options.namespace, '--zone', options.availability_zone, '--interval', str( options.interval ), '--accounts' ] + options.accounts + [ '--keypairs' ] + options.ec2_keypair_names + [ '--user', options.user, '--group', options.group, '--pid-file', options.pid_file, '--log-level', options.log_level, '--log-spill', options.log_spill ] variables = vars( options ).copy( ) variables.update( dict( args=' '.join( shell.quote( arg, level=quote_level ) for arg in args ), exec_path=exec_path, exec_name=exec_name, console=console, description=description ) ) print init_script % variables