Exemplo n.º 1
0
def process(name, **kwargs):
    """
    Require a supervisor process
    """
    from fabtools import require
    require.deb.package('supervisor')
    require.service.started('supervisor')

    # Set default parameters
    params = {}
    params.update(kwargs)
    params.setdefault('autorestart', 'true')
    params.setdefault('redirect_stderr', 'true')

    # Build config file from parameters
    lines = []
    lines.append('[program:%(name)s]' % locals())
    for key, value in sorted(params.items()):
        lines.append("%s=%s" % (key, value))

    # Upload config file
    filename = '/etc/supervisor/conf.d/%(name)s.conf' % locals()
    with watch(filename, callback=update_config, use_sudo=True):
        require.file(filename, contents='\n'.join(lines), use_sudo=True)

    # Start the process if needed
    if process_status(name) == 'STOPPED':
        start_process(name)
Exemplo n.º 2
0
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'))
Exemplo n.º 3
0
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"))
Exemplo n.º 4
0
def enable_app_server(*args, **kwargs):
    # require directory env.scow.project_var_dir exists, owner www-data
    proc_name = env.scow.project_tagged
    with prefix('workon ' + env.scow.project_tagged):
        uwsgi_bin = run('echo $VIRTUAL_ENV/bin/uwsgi')
        uwsgi_logfile = run('echo `cat $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME`/var/log/uwsgi.log')
    web_user = '******'
    uwsgi_cmd=' '.join('''
        {uwsgi_bin}
        --socket {socket_path}
        --module {wsgi_app_module}
        --uid {web_user}
        --master
        --logto {uwsgi_logfile}
        '''.format(
            #process_name=env.scow.project_tagged,
            uwsgi_bin=uwsgi_bin,
            socket_path=path.join(env.scow.project_var_dir, 'uwsgi.sock'),
            wsgi_app_module=env.project.WSGI_APP_MODULE,
            web_user=web_user,
            uwsgi_logfile=uwsgi_logfile,
        ).split())

    require.directory(env.scow.project_var_dir, owner=web_user)
    require.supervisor.process(
        proc_name,
        command=uwsgi_cmd,
        user=web_user,
    )
    supervisor.start_process(proc_name)
Exemplo n.º 5
0
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"))
Exemplo n.º 6
0
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"))
Exemplo n.º 7
0
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'))
Exemplo n.º 8
0
def enable_app_server(*args, **kwargs):
    # require directory env.scow.project_var_dir exists, owner www-data
    proc_name = env.scow.project_tagged
    with prefix('workon ' + env.scow.project_tagged):
        uwsgi_bin = run('echo $VIRTUAL_ENV/bin/uwsgi')
        uwsgi_logfile = run(
            'echo `cat $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME`/var/log/uwsgi.log'
        )
    web_user = '******'
    uwsgi_cmd = ' '.join('''
        {uwsgi_bin}
        --socket {socket_path}
        --module {wsgi_app_module}
        --uid {web_user}
        --master
        --logto {uwsgi_logfile}
        '''.format(
        #process_name=env.scow.project_tagged,
        uwsgi_bin=uwsgi_bin,
        socket_path=path.join(env.scow.project_var_dir, 'uwsgi.sock'),
        wsgi_app_module=env.project.WSGI_APP_MODULE,
        web_user=web_user,
        uwsgi_logfile=uwsgi_logfile,
    ).split())

    require.directory(env.scow.project_var_dir, owner=web_user)
    require.supervisor.process(
        proc_name,
        command=uwsgi_cmd,
        user=web_user,
    )
    supervisor.start_process(proc_name)
Exemplo n.º 9
0
def process(name, **kwargs):
    """
    Require a supervisor process to be running.

    Keyword arguments will be used to build the program configuration
    file. Some useful arguments are:

    - ``command``: complete command including arguments (**required**)
    - ``directory``: absolute path to the working directory
    - ``user``: run the process as this user
    - ``stdout_logfile``: absolute path to the log file

    You should refer to the `supervisord documentation`_ for the
    complete list of allowed arguments.

    .. note:: the default values for the following arguments differs from
              the supervisord defaults:

              - ``autorestart``: defaults to ``true``
              - ``redirect_stderr``: defaults to ``true``

    Example::

        from fabtools import require

        require.supervisor.process('myapp',
            command='/path/to/venv/bin/myapp --config production.ini --someflag',
            directory='/path/to/working/dir',
            user='******',
            stdout_logfile='/path/to/logs/myapp.log',
            )

    .. _supervisord documentation: http://supervisord.org/configuration.html#program-x-section-values
    """
    from fabtools import require

    require.deb.package("supervisor")
    require.service.started("supervisor")

    # Set default parameters
    params = {}
    params.update(kwargs)
    params.setdefault("autorestart", "true")
    params.setdefault("redirect_stderr", "true")

    # Build config file from parameters
    lines = []
    lines.append("[program:%(name)s]" % locals())
    for key, value in sorted(params.items()):
        lines.append("%s=%s" % (key, value))

    # Upload config file
    filename = "/etc/supervisor/conf.d/%(name)s.conf" % locals()
    with watch(filename, callback=update_config, use_sudo=True):
        require.file(filename, contents="\n".join(lines), use_sudo=True)

    # Start the process if needed
    if process_status(name) == "STOPPED":
        start_process(name)
Exemplo n.º 10
0
def set_supervisord_config():
    """Configure Newebe runner for supervisord"""

    require.supervisor.process(newebe_process,
                               command='%s --configfile=%s' %
                               (newebe_exe, newebe_dir + "/config.yaml"),
                               user=newebe_user)
    supervisor.start_process(newebe_process)
Exemplo n.º 11
0
def process(name, **kwargs):
    """
    Require a supervisor process to be running.

    Keyword arguments will be used to build the program configuration
    file. Some useful arguments are:

    - ``command``: complete command including arguments (**required**)
    - ``directory``: absolute path to the working directory
    - ``user``: run the process as this user
    - ``stdout_logfile``: absolute path to the log file

    You should refer to the `supervisor documentation`_ for the
    complete list of allowed arguments.

    .. note:: the default values for the following arguments differs from
              the ``supervisor`` defaults:

              - ``autorestart``: defaults to ``true``
              - ``redirect_stderr``: defaults to ``true``

    Example::

        from fabtools import require

        require.supervisor.process('myapp',
            command='/path/to/venv/bin/myapp --config production.ini --someflag',
            directory='/path/to/working/dir',
            user='******',
            stdout_logfile='/path/to/logs/myapp.log',
            )

    .. _supervisor documentation: http://supervisord.org/configuration.html#program-x-section-values
    """
    from fabtools import require
    require.deb.package('supervisor')
    require.service.started('supervisor')

    # Set default parameters
    params = {}
    params.update(kwargs)
    params.setdefault('autorestart', 'true')
    params.setdefault('redirect_stderr', 'true')

    # Build config file from parameters
    lines = []
    lines.append('[program:%(name)s]' % locals())
    for key, value in sorted(params.items()):
        lines.append("%s=%s" % (key, value))

    # Upload config file
    filename = '/etc/supervisor/conf.d/%(name)s.conf' % locals()
    with watch(filename, callback=update_config, use_sudo=True):
        require.file(filename, contents='\n'.join(lines), use_sudo=True)

    # Start the process if needed
    if process_status(name) == 'STOPPED':
        start_process(name)
Exemplo n.º 12
0
def start(process_name):
    """starts supervisor process
    """
    fabric.api.require('site',
                       'available',
                       'hosts',
                       'site_environment',
                       provided_by=('dev', 'staging', 'prod', 'vagrant'))
    supervisor.start_process(process_name)
Exemplo n.º 13
0
def set_supervisord_config():
    """Configure Newebe runner for supervisord"""

    require.supervisor.process(newebe_process,
        command='%s --configfile=%s' %
            (newebe_exe, newebe_dir + "/config.yaml"),
        user=newebe_user
    )
    supervisor.start_process(newebe_process)
Exemplo n.º 14
0
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.'))
Exemplo n.º 15
0
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.'))
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
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)
Exemplo n.º 18
0
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)
Exemplo n.º 19
0
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'))
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
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'))
Exemplo n.º 22
0
def celeryd_start():
    supervisor.start_process(SUPERVISORD_CELERYD)
Exemplo n.º 23
0
def start(component):
    supervisor.start_process(component)
Exemplo n.º 24
0
def start(process_name):
    """starts supervisor process
    """
    supervisor.start_process(process_name)
Exemplo n.º 25
0
def run_process(process):
    """
    Start supervisor controlled process
    """
    start_process(process)
def start(process_name):
    """starts supervisor process
    """
    fabric.api.require('site', 'available', 'hosts', 'site_environment',
        provided_by=('dev', 'staging', 'prod', 'vagrant'))
    supervisor.start_process(process_name)
Exemplo n.º 27
0
def start(process_name):
    """starts supervisor process
    """
    supervisor.start_process(process_name)
Exemplo n.º 28
0
def start_hadroid(app_name=None):
    """Start the supervisor process."""
    supervisor.start_process(app_name or env.app_name)
Exemplo n.º 29
0
def uwsgi_start():
    supervisor.start_process(SUPERVISORD_UWSGI)
Exemplo n.º 30
0
def process(name, use_pip=False, **kwargs):
    """
    Require a supervisor process to be running. Installs supervisor
    from the default system package manager unless ``use_pip`` is
    truthy.

    Keyword arguments will be used to build the program configuration
    file. Some useful arguments are:

    - ``command``: complete command including arguments (**required**)
    - ``directory``: absolute path to the working directory
    - ``user``: run the process as this user
    - ``stdout_logfile``: absolute path to the log file

    You should refer to the `supervisor documentation`_ for the
    complete list of allowed arguments.

    .. note:: the default values for the following arguments differs from
              the ``supervisor`` defaults:

              - ``autorestart``: defaults to ``true``
              - ``redirect_stderr``: defaults to ``true``

    Example::

        from fabtools import require

        require.supervisor.process('myapp',
            command='/path/to/venv/bin/myapp --config production.ini --someflag',
            directory='/path/to/working/dir',
            user='******',
            stdout_logfile='/path/to/logs/myapp.log',
            )

    .. _supervisor documentation: http://supervisord.org/configuration.html#program-x-section-values

    """

    from fabtools.require import file as require_file
    from fabtools.require.python import package as require_python_package
    from fabtools.require.deb import package as require_deb_package
    from fabtools.require.rpm import package as require_rpm_package
    from fabtools.require.arch import package as require_arch_package
    from fabtools.require.service import started as require_started

    # configure installation. override default package installation w/ use_pip
    family = distrib_family()
    if family == 'debian':
        require_package = require_deb_package
        package_name = 'supervisor'
        daemon_name = 'supervisor'
        filename = '/etc/supervisor/conf.d/%(name)s.conf' % locals()
    elif family == 'redhat':
        require_package = require_rpm_package
        package_name = 'supervisor'
        daemon_name = 'supervisord'
        filename = '/etc/supervisord.d/%(name)s.ini' % locals()
    elif family == 'arch':
        require_package = require_arch_package
        package_name = 'supervisor'
        daemon_name = 'supervisord'
        filename = '/etc/supervisor.d/%(name)s.ini' % locals()
    else:
        raise UnsupportedFamily(supported=['debian', 'redhat', 'arch'])
    if use_pip:
        require_package = require_python_package
        package_name = 'supervisor'

    # install supervisor and make sure its started
    require_package(package_name)
    require_started(daemon_name)

    # Set default parameters
    params = {}
    params.update(kwargs)
    params.setdefault('autorestart', 'true')
    params.setdefault('redirect_stderr', 'true')

    # Build config file from parameters
    lines = []
    lines.append('[program:%(name)s]' % locals())
    for key, value in sorted(params.items()):
        lines.append("%s=%s" % (key, value))

    # Upload config file
    with watch(filename, callback=update_config, use_sudo=True):
        require_file(filename, contents='\n'.join(lines), use_sudo=True)

    # Start the process if needed
    if process_status(name) == 'STOPPED':
        start_process(name)
Exemplo n.º 31
0
def process(name, **kwargs):
    """
    Require a supervisor process to be running.

    Keyword arguments will be used to build the program configuration
    file. Some useful arguments are:

    - ``command``: complete command including arguments (**required**)
    - ``directory``: absolute path to the working directory
    - ``user``: run the process as this user
    - ``stdout_logfile``: absolute path to the log file

    You should refer to the `supervisor documentation`_ for the
    complete list of allowed arguments.

    .. note:: the default values for the following arguments differs from
              the ``supervisor`` defaults:

              - ``autorestart``: defaults to ``true``
              - ``redirect_stderr``: defaults to ``true``

    Example::

        from fabtools import require

        require.supervisor.process('myapp',
            command='/path/to/venv/bin/myapp --config production.ini --someflag',
            directory='/path/to/working/dir',
            user='******',
            stdout_logfile='/path/to/logs/myapp.log',
            )

    .. _supervisor documentation: http://supervisord.org/configuration.html#program-x-section-values
    """

    from fabtools.require import file as require_file
    from fabtools.require.deb import package as require_deb_package
    from fabtools.require.rpm import package as require_rpm_package
    from fabtools.require.arch import package as require_arch_package
    from fabtools.require.service import started as require_started

    family = distrib_family()

    if family == 'debian':
        require_deb_package('supervisor')
        require_started('supervisor')
    elif family == 'redhat':
        require_rpm_package('supervisor')
        require_started('supervisord')
    elif family == 'arch':
        require_arch_package('supervisor')
        require_started('supervisord')
    else:
        raise UnsupportedFamily(supported=['debian', 'redhat', 'arch'])

    # Set default parameters
    params = {}
    params.update(kwargs)
    params.setdefault('autorestart', 'true')
    params.setdefault('redirect_stderr', 'true')

    # Build config file from parameters
    lines = []
    lines.append('[program:%(name)s]' % locals())
    for key, value in sorted(params.items()):
        lines.append("%s=%s" % (key, value))

    # Upload config file
    if family == 'debian':
        filename = '/etc/supervisor/conf.d/%(name)s.conf' % locals()
    elif family == 'redhat':
        filename = '/etc/supervisord.d/%(name)s.ini' % locals()
    elif family == 'arch':
        filename = '/etc/supervisor.d/%(name)s.ini' % locals()

    with watch(filename, callback=update_config, use_sudo=True):
        require_file(filename, contents='\n'.join(lines), use_sudo=True)

    # Start the process if needed
    if process_status(name) == 'STOPPED':
        start_process(name)
Exemplo n.º 32
0
def start_hadroid(app_name=None):
    """Start the supervisor process."""
    supervisor.start_process(app_name or env.app_name)