Use fabric to automatically launch small batches

Source: Internet
Author: User

During normal development, you should often encounter code online problems. Generally, there are several headaches:
<Ul>
<Li> a large number of hosts, but not many (1 ~ 100) </LI>
<Li> the launch process is cumbersome and error-prone </LI>
<Li> sudo may be required. You need to enter the sudo password multiple times. </LI>
</Ul>
Generally, you have two options:
<Ul>
<Li> <a href = "http://www.fabfile.org/" target = "_ blank"> fabric </a> written in python </LI>
<Li> <a href = "http://capistranorb.com/" target = "_ blank"> Capistrano </a> written in ruby </LI>
</Ul>
Then fabric is selected and the code is directly displayed.

<PRE class = "Lang: Python">
#-*-Coding = UTF-8 -*-

From fabric. API import *
From fabric. contrib. Project import rsync_project

Env. roledefs = {
'Liyun G': [# telecom data center
'[Email protected]',
'[Email protected]',
],
'Diance': [# Unicom data center
'[Email protected]',
'[Email protected]',
],
}

@ Roles ('lifecyg', 'diance') # This writer indicates that China Telecom and China Unicom must execute this function.
Def check ():
Run ('ps aux | grep uwsgi | grep-V grep ')
Run ('LS-L/home/system/service /')

Def initfiles ():
Execute (liantong_conf) # execute liantong_conf ()
Execute (dianxin_conf) # execute dianxin_conf ()

@ Roles ('diance') # China Telecom
Def dianxin_conf ():
Initfiles1 ()
Sudo ("CD/home/system/service & mv settings_online_dianxin.py settings. py ")
Initfiles2 ()

@ Roles ('liyung') # Unicom
Def liantong_conf ():
Initfiles1 ()
Sudo ("CD/home/system/service & mv settings_online_liw.g.py settings. py ")
Initfiles2 ()

@ Roles ('liyung', 'diance ')
Def initfiles1 ():
Sudo ("chmod 777/home/system/service ")
Sudo ("chmod 777/home/system/service/ORM ")
Sudo ("chown-r auxten: auxten/home/system/service ")

Rsync_project (# Call rsync
Remote_dir = '/home/system/service /',
Local_dir = '/users/auxten/codes/web/flow-Web /*',
Exclude = ['python2. 7 ','*. pyc ','*. log ','. SVN ','. idea ', 'logs',' * Pull. sh', '* Push. sh', 'settings. py']
)

@ Roles ('liyung', 'diance ')
Def initfiles2 ():
Sudo ("chown-r Apache: Apache/home/system/service ")

@ Roles ('liyung', 'diance ')
Def restart ():
Sudo ("sh/home/system/service/run. Sh ")
Run ('ps aux | grep uwsgi | grep-V grep ')

@ Roles ('liyung', 'diance ')
Def checklog ():
Sudo ('Tail-50/home/system/service/uwsgi. log ')
</PRE>


<PRE class = "Lang: Bash">
############
# Simply Execute
Fab-F webdeploy. py initfiles restart #. the login password and sudo password will only be asked once.
</PRE>

More functions are waiting for you to explore. I just used them. Please leave a message to share your experiences.

Use fabric to automatically launch small batches

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.