This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_cmd.py
executable file
·83 lines (72 loc) · 2.61 KB
/
docker_cmd.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# Copyright 2017 Scality
#
# This file is part of Eve.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
from __future__ import print_function
import os
import subprocess
import sys
import time
import requests
import sqlalchemy
def _print(string):
"""Print and flush for immediate display."""
print(string)
sys.stdout.flush()
wamp_router_url = os.environ.get('WAMP_ROUTER_URL', '')
if wamp_router_url:
_print("pinging crossbar...")
for i in range(120):
try:
requests.get(wamp_router_url.replace('ws://', 'http://'))
break
except requests.exceptions.ConnectionError:
_print('Waiting for the wamp queue to wake up {} ...'.format(
wamp_router_url))
time.sleep(1)
else:
raise Exception('wamp server never responded')
_print("pinging database...")
db_url = os.environ['DB_URL']
sa = sqlalchemy.create_engine(db_url.split('?')[0])
for i in range(120):
try:
sa.execute('select 1;')
break
except sqlalchemy.exc.OperationalError:
_print('Waiting for the database to wake up {} ...'.format(db_url))
time.sleep(1)
else:
raise Exception('database never responded')
if os.environ.get('DEBUG_MODE', '0') in ['true', 'True', '1', 'y', 'yes']:
_print("starting in debug mode...")
_print("-> to start buildbot manually, connect to container then type:")
_print(" $ twistd -ny ./buildbot.tac")
_print("-> to connect to interactive session, type:")
_print(" $ telnet 127.0.0.1 12345")
_print("-> to resume normal startup sequence, type:")
_print(" $ pkill -f tail")
try:
subprocess.check_call('tail -f /dev/null', shell=True)
except:
pass
_print("resuming startup sequence")
if os.environ.get('MASTER_MODE', 'standalone') in ['frontend', 'standalone']:
_print("upgrading master...")
subprocess.check_call('buildbot upgrade-master .', shell=True)
_print("starting master...")
subprocess.check_call('twistd -ny ./buildbot.tac', shell=True)