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