Macã§ã®éçºå¹çãã¢ããããããã¦ã³ãããã«ãã¼ã«ã«ã®ã½ã¼ã¹ã³ã¼ãããµã¼ãã¼ã¨åæããã¹ã¯ãªããæ¸ããã
ããã ãã
å¤æ´ããã£ããã¼ã«ã«ã®ã½ã¼ã¹ã³ã¼ãããµã¼ãã¼ã®ã½ã¼ã¹ã³ã¼ãã¨åæããªããwebã¢ããªãéçºã§ããã¹ã¯ãªãããä½ãã¾ããã
shikajiro/eventsync.py
2012/07/10 追è¨
ä¸ã§èª¬æããã½ã¼ã¹ã³ã¼ãã¯å¤ãã®ã§ãshikajiro/eventsync.pyã®æ¹ãè¦ã¦ãã ãããã
webã¢ããªéçºã®åé¡ç¹
- ãã¦ã³ããããsshã§ãµã¼ãã¼ã«æ¥ç¶ãã¦webã¢ããªãéçºãã¦ãã¨ãåç·ãé ãã¦ç»é¢ãåºã¾ããã¨ããããã¹ãã¬ã¹ãã«ãªã³ã¼ãã£ã³ã°ãå¼·ãããã¦ããã
- ãã¼ã«ã«ã®ã½ã¼ã¹ãgitã§pushãã¦ãµã¼ãã¼ã«åæ ããã®ã¯è¤æ°äººã®å ´åã¯ãããã©ãä¸äººç¨ã®å ´åã¯æ¯åadd commit push ãããã©ãã
ããã°ã©ãã¼ã楽ããããã°ã©ãã³ã°ã§ããªãã®ã¯ç½ªã§ããç´ã¡ã«æºæããã解決ãã¾ãããã
éçºä¸ã®webã¢ããªãåããå ´æãæ¯è¼æ¤è¨
å®è¡å ´æ | å ¬éç¯å² | åå¿ã¹ãã¼ã | PCè² è· | æè»æ§ |
---|---|---|---|---|
ãã¼ã«ã«ã®mac | à | ⯠| â³ | à |
vmwareã®Linux | à | â³ | à | ⯠|
ã¬ã³ã¿ã«ãµã¼ãã¼ | ⯠| à | ⯠| â³ |
- ãã¼ã«ã«ã§webã¢ããªãåããã¨ã¬ã¹ãã³ã¹ã¨ãéããã ãã©ãè¤æ°ç°å¢ãªã©ã§æè»æ§ã«æ¬ ããã
- vmwareã ã¨æè»æ§é«ããã ãã©ãã¡ã¢ãªã¨CPUæ¶è²»ãæ¿ããã¦é ãã
- ä¸è¨ï¼ã¤ã¯ããã«ãããã«å ¬éããã¦ããªãã®ã§ãã¹ããã«ããã
- ã¬ã³ãµãã¯å ¬éããã¦ã¦æ±ãæããã©ãç´æ¥ã³ã¼ãã£ã³ã°ããã«ã¯ã¬ã¹ãã³ã¹ãé ãã
ä»ãã®ç¬éä½ã£ã¦ãããã®ãã¹ãã¬ã¹ç¡ããµã¼ãã¼ã§ç¢ºèªãããã®ã§ãï¼
ã¨ããããã§ãããµã¼ãã¼ã«å¸¸ææ¥ç¶ãããããã¼ã«ã«ã§éçºã§ãã¦ããã½ã¼ã¹ã³ã¼ãã«å¤æ´ããã£ãããµã¼ãã¼ãæ´æ°ãããæ¹æ³ãæ¢ãã¾ããã
ã½ã¼ã¹ã³ã¼ãã®åæã¯rsyncã§
ã³ã¼ãã®åæã¯rsyncã§ã§ãã¾ãããåé¡ã¯ãã½ã¼ã¹ã³ã¼ãã®è¿½å ã»å¤æ´ã»åé¤ããã©ããã£ã¦æ¤ç¥ãããã§ãã
lsync
Linuxãã£ã¹ããªãã¥ã¼ã·ã§ã³ãªãlsyncã使ãã¨ãã¡ã¤ã«ã®å¤æ´æ¤ç¥ãã§ããã¿ããã§ãããMac OS X ã¯BSDãªã®ã§ãããã¯ä½¿ãã¾ããã§ããã
ãã©ã«ãã¢ã¯ã·ã§ã³
Mac OS X ã«ã¯ãã©ã«ãã¢ã¯ã·ã§ã³ã¨ãããã©ã«ãç£è¦ã®ä»çµã¿ãããã¾ãããã©ã«ãã«å¤æ´ãããã¨automatorãå®è¡åºæ¥ãããã¾ãããããããã¯ããã©ã«ãã¸ã®ãã¡ã¤ã«ã®è¿½å ãã®ã¿æ¤ç¥å¯è½ã ã£ãããæ念ãã¾ããã
kevent kqueue
BSDã¯Linuxã¨ã¯å¥ã®æ¹æ³ã§ãã¡ã¤ã«ãç£è¦ããäºãå¯è½ã§ãããããã kevent kqueueã§ãã
*BSD で kqueue・kevent を使ってみよう
pythonã¹ã¯ãªãã
ãã§ãè²ããªãµã¤ãã®ã½ã¼ã¹ã³ã¼ããåèã«ãã¦ã§ãã¾ããã
shikajiro/eventsync.py
import select import os import sys def kevent(file): ke = select.kevent(file, filter=select.KQ_FILTER_VNODE, flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE | select.KQ_EV_CLEAR, fflags=select.KQ_NOTE_DELETE | select.KQ_NOTE_WRITE ) return ke argvs = sys.argv argc = len(argvs) if(argc != 3): print 'Usage: python {} filename.'.format(argvs[0]) quit() folder = argvs[1] ssh = argvs[2] print '{} to {}'.format(folder, ssh) print 'file update watching...' dirs = os.walk(folder) l = [] for root, dirs, files in dirs: f = os.open(root, os.O_RDONLY) l.append(kevent(f)) for a in files: f = os.open(root + '/' + a, os.O_RDONLY) l.append(kevent(f)) kq = select.kqueue() events = kq.control(l, 0, None) while True: r_events = kq.control(l, 1, None) for event in r_events: print event if event.fflags & select.KQ_NOTE_DELETE or event.fflags & select.KQ_NOTE_WRITE: print "file was updated!" command = 'rsync -av --delete -e ssh {} {}'.format(os.path.join(os.getcwd(), folder), ssh) print command os.system(command)
python eventsync.py watchdir/ shikajiro@hostname:/dir/
第ä¸å¼æ°ã«ç£è¦ãããã£ã¬ã¯ããªåã第äºå¼æ°ã«åæããsshãµã¼ãã¼ã¨ãã®ãã©ã«ããæå®ãã¾ãã
èµ·åããã¨ãããªæãã
hogehoge/ to [email protected]:/root/hogehoge/
file update watching...
ãã¡ã¤ã«ã«å¤æ´ãªã©ãããã¨
building file list ... done
deleting urls.pyc
deleting settings.pyc
deleting middleware.pyc
deleting __init__.pyc
deleting api/urls.pyc
deleting api/handlers.pyc
deleting api/__init__.pyc
deleting app/models.pyc
deleting app/admin.pyc
deleting app/__init__.pyc
./
sqlite
test
api/
app/sent 7501 bytes received 1876 bytes 6251.33 bytes/sec
total size is 3252109 speedup is 346.82
.....
ãããªæãã§ã©ãã©ãåæããã¦ããã¾ãã
ããã§ãã£ã¨ã¹ãã¬ã¹ããªã¼ãªéçºãã§ããï¼ã¯ãï¼ã§ãã