-
Notifications
You must be signed in to change notification settings - Fork 4
/
deploy.py
59 lines (45 loc) · 1.12 KB
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
import pexpect
import sys
import os
import datetime
time=datetime.datetime.now().strftime('%Y%m%d%H%M%S')
localPath = os.getcwd()
pathSp = localPath.split('/')
localDir = pathSp[len(pathSp)-1]
remote = '[email protected]'
remotePath = '/data/www'
remoteDir = 'z.wilddog.com'
tgz = localDir+".tar.gz"
pexpect.run('tar -cvf %s %s '%(tgz,localDir),cwd='..')
pexpect.run('scp %s %s:%s'%(tgz,remote,remotePath),cwd="..")
#ssh
ssh = pexpect.spawn('ssh',[remote])
ssh.logfile = sys.stdout
ssh.expect('#')
# cd to /data/www
ssh.sendline("cd %s"%(remotePath))
ssh.expect('#')
#backupfile
ssh.sendline("mv %s %s"%(remoteDir,"backup/"+remoteDir+"."+time))
ssh.expect('#')
#unzip file
ssh.sendline('tar -xvf %s'%(tgz))
ssh.expect('#')
#cleanup
ssh.sendline('rm -f %s'%(tgz))
ssh.expect('#')
#replece z.wilddog.com
ssh.sendline('mv %s %s'%(localDir,remoteDir))
ssh.expect('#')
#cd to z.wilddog.com
ssh.sendline('cd %s'%(remoteDir))
ssh.expect('#')
# stop
ssh.sendline('forever stop ./bin/www')
ssh.expect('#')
# start
ssh.sendline('forever start ./bin/www')
ssh.expect('#')
# cleanup
pexpect.run('rm -f %s'%(tgz),cwd='..')