~lindsay/fabric-example

b7631914423feb3f35520006c33c27cf70991f75 — Lindsay 1 year, 10 months ago d125035 master
Add su-run and nohup-run task
1 files changed, 24 insertions(+), 0 deletions(-)

M submodule.py
M submodule.py => submodule.py +24 -0
@@ 1,5 1,7 @@
import getpass
from invoke import Collection
from fabric import task, Connection
from invoke.watchers import Responder
from log import logger

subc = Collection('subc')


@@ 9,7 11,29 @@ def sub_task(c):
    """task in submodule"""
    c.run('hostname')
    logger.info('sub-task done')

@task
def su_run(c):
    def root_responser():
        passwd = getpass.getpass("Root passwd:")
        passwd_responder = Responder(
            pattern=r".*Password: ",
            response=passwd+'\n'
        )
        return passwd_responder

    responser = root_responser()

    c.run('su -c "whoami"', pty=True, watchers=[responser])
    logger.info('Run su command with root')

@task
def nohup_run(c):
    c.run('cd /home/lindsay/Blog/Lindsay; (nohup hugo server -b 192.168.7.233 --bind 192.168.7.233 -D &> /dev/null </dev/null &) && /bin/true', pty=True)
    logger.info('Run hugo debug mode using nohup')
    
subc.add_task(sub_task, name='subt')
subc.add_task(su_run, name='su-run')
subc.add_task(nohup_run, name='nohup-run')