- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
def serve_module(is_deployed=False, name="dummy", timeout=60):
env_name = "%s-env" % name
screen_log_file_name = "/screenlog.0"
if not booleanize(is_deployed):
run_tests(is_deployed, name)
with prefix(workon_prefix), prefix(source_prefix), \
cd(run("echo $WORKON_HOME") + "/" + env_name), \
prefix("workon " + env_name),\
prefix("export LANG=en_US.UTF-8"),\
prefix("export LLC=en_US.UTF-8"):
print("Serving module " + name)
if exists(".%s" % screen_log_file_name):
run("rm -f .%s" % screen_log_file_name)
run("screen -S %s-serve -X quit" % name, warn_only=True)
run("screen -wipe", warn_only=True)
run("screen -L -dmS %s-serve-screen sh -c 'echo $! > ./serve.pid; %s serve'" % (name, name), pty=False)
time.sleep(2)
log_file_path = run("pwd") + screen_log_file_name
time_with_timeout = time.time() + timeout
while True:
if contains(log_file_path, "Started"):
break
if time.time() > time_with_timeout:
run("cat ./screenlog.0")
sys.exit(1)
print('Looking for startup indicator in file: ' + log_file_path)
time.sleep(2)
print 'Module %s started' % name
Это часть скрипта для Continious Intergration одного из проектов.
Зачетный талант системного администратора пользовавшего
python fabric и "толковые" советы из StackOverflow.
Особенно впечатляет супервайзинг при помощи screen.