def install_controller(): """ Install Cozy Controller Application Manager. Daemonize with supervisor. """ require.nodejs.package('cozy-controller') sudo('mkdir -p /etc/cozy') sudo('mkdir -p /etc/cozy/pids') require.files.file(path='/etc/cozy/controller.token', mode='700', contents=token, use_sudo=True, owner='cozy-home') path = "/usr/local/lib/node_modules/cozy-controller/bin/cozy-controller" require.supervisor.process( 'cozy-controller', command="/usr/bin/pidproxy /etc/cozy/pids/controller.pid " + "%s -u --auth --per 755" % path, environment='NODE_ENV="production"', user='******') supervisor.stop_process('cozy-controller') ## In case where two cozy-controllers are started with settings(warn_only=True): sudo('pkill -9 node') supervisor.start_process('cozy-controller') import time time.sleep(5) with hide('running', 'stdout'): result = run( 'curl -X GET http://127.0.0.1:9002/ -H "x-auth-token: %s"' % token) if result != '{"message":"No drones specified"}': print_failed("cozy-controller") print(green("Cozy Controller successfully started"))
def install_controller(): ''' Install Cozy Controller Application Manager. Daemonize with supervisor. ''' require.nodejs.package('cozy-controller') sudo('mkdir -p /etc/cozy') sudo('mkdir -p /etc/cozy/pids') require.files.file( path='/etc/cozy/controller.token', mode='700', contents=TOKEN, use_sudo=True, owner='cozy-home' ) path = '/usr/local/lib/node_modules/cozy-controller/bin/cozy-controller' require.supervisor.process( 'cozy-controller', command="%s -u --auth --per 755" % path, environment='NODE_ENV="production"', user='******' ) supervisor.stop_process('cozy-controller') ## In case where two cozy-controllers are started with settings(warn_only=True): sudo('pkill -9 node') supervisor.start_process('cozy-controller') if is_arm(): time.sleep(20) else: time.sleep(10) with hide('running', 'stdout'): result = run('curl -X GET http://127.0.0.1:9002/') if result != '{"error":"Wrong auth token"}': print_failed('cozy-controller') print(green('Cozy Controller successfully started'))
def install_controller(): """ Install Cozy Controller Application Manager. Daemonize with supervisor. """ require.nodejs.package('cozy-controller') sudo('mkdir -p /etc/cozy') sudo('mkdir -p /etc/cozy/pids') require.files.file(path='/etc/cozy/controller.token', mode='700', contents=token, use_sudo=True, owner='cozy-home' ) path = "/usr/local/lib/node_modules/cozy-controller/bin/cozy-controller" require.supervisor.process('cozy-controller', command="/usr/bin/pidproxy /etc/cozy/pids/controller.pid " + "%s -u --auth --per 755" % path, environment='NODE_ENV="production"', user='******' ) supervisor.stop_process('cozy-controller') ## In case where two cozy-controllers are started with settings(warn_only=True): sudo('pkill -9 node') supervisor.start_process('cozy-controller') import time time.sleep(5) with hide('running', 'stdout'): result = run('curl -X GET http://127.0.0.1:9002/ -H "x-auth-token: %s"' % token) if result != '{"message":"No drones specified"}': print_failed("cozy-controller") print(green("Cozy Controller successfully started"))
def install_controller(): """ Install Cozy Controller Application Manager. Daemonize with supervisor. """ sudo("npm install -g git+https://github.com/roblabla/cozy-controller.git") sudo("mkdir -p /etc/cozy") sudo("mkdir -p /etc/cozy/pids") require.files.file(path="/etc/cozy/controller.token", mode="700", contents=TOKEN, use_sudo=True, owner="cozy-home") # TODO : lib or lib64 ? path = "/usr/lib64/node_modules/cozy-controller/bin/cozy-controller" require.supervisor.process( "cozy-controller", command="%s -u --auth --per 755" % path, environment='NODE_ENV="production"', user="******" ) supervisor.stop_process("cozy-controller") ## In case where two cozy-controllers are started with settings(warn_only=True): sudo("pkill -9 node") supervisor.start_process("cozy-controller") print("Waiting for cozy-controller to be launched...") program = "curl -X GET http://127.0.0.1:9002/" def comparator(result): return result == '{"error":"Wrong auth token"}' # Run curl until we get the MATCH_STR or a timeout if not try_delayed_run(program, comparator): print_failed("cozy-controller") print(green("Cozy Controller successfully started"))
def stop(process_name): """stops supervisor process """ fabric.api.require('site', 'available', 'hosts', 'site_environment', provided_by=('dev', 'staging', 'prod', 'vagrant')) supervisor.stop_process(process_name)
def stop_queues(process): #Request' status is failure after 15 secs in received #So even if queue is not empty we can shutdown the process for i in range(1, 17): res = run('python manage.py active_tasks {}'.format(process)) if res == '': break time.sleep(1) supervisor.stop_process(process)
def uninstall_cozy(): ''' Uninstall postfix. ''' supervisor.stop_process('cozy-controller') supervisor.stop_process('cozy-indexer') su_delete('/usr/local/var/cozy-indexer') su_delete('/etc/supervisor/conf.d/cozy-controller.conf') su_delete('/etc/supervisor/conf.d/cozy-indexer.conf') supervisor.update_config() print(green('Cozy successfully uninstalled'))
def stop_old_processes(now): l = run('for i in /etc/supervisor/conf.d/uwsgi_*; do echo $i; done').split("\n") for f in l: if f == env.deployment_dir: continue m = re.search(r'([^/]*).conf$', f) if not m: continue process = m.group(1) supervisor.stop_process(process) files.remove(f, use_sudo=True)
def uninstall_cozy(): """ Uninstall postfix. """ supervisor.stop_process("cozy-controller") supervisor.stop_process("cozy-indexer") su_delete("/usr/local/var/cozy-indexer") su_delete('/etc/supervisor/conf.d/cozy-controller.conf') su_delete('/etc/supervisor/conf.d/cozy-indexer.conf') supervisor.update_config() print(green("Cozy successfully uninstalled"))
def update_stack(): ''' Update applications ''' supervisor.stop_process('cozy-controller') nodejs.update_package('cozy-controller') supervisor.start_process('cozy-controller') nodejs.update_package('cozy-monitor') sudo('cozy-monitor install data-system') sudo('cozy-monitor install home') sudo('cozy-monitor install proxy') print(green('Stack updated successfully.'))
def restart_controller(): if is_pi(): sudo('/etc/init.d/cozy-controller stop') with settings(warn_only=True): sudo('pkill node') sudo('/etc/init.d/cozy-controller start') else: supervisor.stop_process('cozy-controller') with settings(warn_only=True): sudo('pkill node') supervisor.start_process('cozy-controller') time.sleep(10)
def restart_controller(): """ Restart the Cozy controller """ if is_pi(): sudo("/etc/init.d/cozy-controller stop") with settings(warn_only=True): sudo("pkill node") sudo("/etc/init.d/cozy-controller start") else: supervisor.stop_process("cozy-controller") with settings(warn_only=True): sudo("pkill node") supervisor.start_process("cozy-controller") time.sleep(10)
def install_controller(): ''' Install Cozy Controller Application Manager. Daemonize with supervisor. ''' # Check if controller is already installed, . with settings(warn_only=True): result = run('curl -X GET http://127.0.0.1:9002/') is_installed = result.find('{"error":"Wrong auth token"}') if is_installed != -1: print(green("Cozy Controller already installed")) return True sudo('npm install -g cozy-controller') require.directory('/etc/cozy', owner='root', use_sudo=True) require.directory('/etc/cozy/pids', owner='root', use_sudo=True) require.files.file( path='/etc/cozy/controller.token', mode='700', contents=TOKEN, use_sudo=True, owner='cozy-home' ) path = '/usr/local/lib/node_modules/cozy-controller/bin/cozy-controller' require.supervisor.process( 'cozy-controller', command="%s -u --auth --per 755" % path, environment='NODE_ENV="production"', user='******' ) supervisor.stop_process('cozy-controller') ## In case where two cozy-controllers are started with settings(warn_only=True): sudo('pkill -9 node') supervisor.start_process('cozy-controller') print('Waiting for cozy-controller to be launched...') program = 'curl -X GET http://127.0.0.1:9002/' def comparator(result): return result == '{"error":"Wrong auth token"}' # Run curl until we get the MATCH_STR or a timeout if not try_delayed_run(program, comparator): print_failed('cozy-controller') print(green('Cozy Controller successfully started'))
def stop_old_processes(now): def stop_process(name, visitor): l = run('for i in /etc/supervisor/conf.d/{}_*; do echo $i; done'.format(name)).split("\n") for f in [f.replace('\r', '') for f in l]: print 'To remove: {}'.format(f) if str(now) in f: continue file_ = f.split('/')[-1] process = file_[:-len('.conf')] visitor(process) files.remove(f, use_sudo=True) stop_process('uwsgi', lambda p:supervisor.stop_process(p)) def stop_queues(process): #Request' status is failure after 15 secs in received #So even if queue is not empty we can shutdown the process for i in range(1, 17): res = run('python manage.py active_tasks {}'.format(process)) if res == '': break time.sleep(1) supervisor.stop_process(process) with cd(env.apitaxi_dir(now)): with python.virtualenv(env.apitaxi_venv_path(now)),\ shell_env(APITAXI_CONFIG_FILE=env.apitaxi_config_path(now)): stop_process('send_hail', stop_queues)
def uninstall_cozy(): """ Uninstall postfix. """ # TODO : modify for arch supervisor.stop_process("cozy-controller") supervisor.stop_process("cozy-indexer") su_delete("/usr/local/var/cozy-indexer") su_delete("/usr/local/cozy-indexer") su_delete("/usr/local/cozy") su_delete("/home/cozy*") su_delete("/etc/cozy") su_delete("/etc/nginx/conf.d/cozy.conf") su_delete("/etc/supervisor/conf.d/cozy-controller.conf") su_delete("/etc/supervisor/conf.d/cozy-indexer.conf") supervisor.update_config() print(green("Cozy successfully uninstalled"))
def deploy(version_tag=None): """deploys a new version of the site version_tag: a git tag, defaults to HEAD """ fabric.api.require('site', 'available', 'hosts', 'site_environment', provided_by=('dev', 'prod', 'vagrant')) supervisor.stop_process(SITE_NAME) new_env = virtualenv_name(commit=version_tag) virtualenv = 'veyepar' mkvirtualenv(new_env) deploy_www_root() checkout_repo(commit=version_tag) install_site_requirements(virtualenv) collectstatic() supervisor.start_process(SITE_NAME)
def install_controller(): ''' Install Cozy Controller Application Manager. Daemonize with supervisor. ''' # Check if controller is already installed, . with settings(warn_only=True): result = run('curl -X GET http://127.0.0.1:9002/') is_installed = result.find('{"error":"Wrong auth token"}') if is_installed != -1: print(green("Cozy Controller already installed")) return True sudo('npm install -g cozy-controller') require.directory('/etc/cozy', owner='root', use_sudo=True) require.directory('/etc/cozy/pids', owner='root', use_sudo=True) require.files.file(path='/etc/cozy/controller.token', mode='700', contents=TOKEN, use_sudo=True, owner='cozy-home') path = '/usr/local/lib/node_modules/cozy-controller/bin/cozy-controller' require.supervisor.process('cozy-controller', command="%s -u --auth --per 755" % path, environment='NODE_ENV="production"', user='******') supervisor.stop_process('cozy-controller') ## In case where two cozy-controllers are started with settings(warn_only=True): sudo('pkill -9 node') supervisor.start_process('cozy-controller') print('Waiting for cozy-controller to be launched...') program = 'curl -X GET http://127.0.0.1:9002/' def comparator(result): return result == '{"error":"Wrong auth token"}' # Run curl until we get the MATCH_STR or a timeout if not try_delayed_run(program, comparator): print_failed('cozy-controller') print(green('Cozy Controller successfully started'))
def stop_hadroid(app_name=None): """Stop the supervisor process.""" supervisor.stop_process(app_name or env.app_name)
def stop(process_name): """stops supervisor process """ supervisor.stop_process(process_name)
def uwsgi_stop(): supervisor.stop_process(SUPERVISORD_UWSGI)
def stop(component): supervisor.stop_process(component)
def celeryd_stop(): supervisor.stop_process(SUPERVISORD_CELERYD)
def end_process(process): """ End supervisor controlled process. """ stop_process(process)