py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-06-25 10:35:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import signal
|
|
|
|
import subprocess
|
|
|
|
import re
|
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
2016-10-16 07:21:41 +02:00
|
|
|
from typing import IO, Text
|
2016-06-25 10:35:27 +02:00
|
|
|
|
2017-02-19 22:18:18 +01:00
|
|
|
# TODO: Convert this to use scripts/lib/queue_workers.py
|
2016-06-25 10:35:27 +02:00
|
|
|
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
2017-01-12 05:45:20 +01:00
|
|
|
successful_worker_launches = [
|
2018-01-01 07:38:28 +01:00
|
|
|
'[process_queue] 20 queue worker threads were launched',
|
2016-06-25 10:35:27 +02:00
|
|
|
]
|
|
|
|
|
2018-01-01 07:38:28 +01:00
|
|
|
def check_worker_launch(logfile_name):
|
|
|
|
# type: (str) -> bool
|
2017-12-13 19:38:15 +01:00
|
|
|
def check(content):
|
|
|
|
# type: (str) -> bool
|
2016-06-25 10:35:27 +02:00
|
|
|
flag = True
|
2017-01-12 05:45:20 +01:00
|
|
|
for entry in successful_worker_launches:
|
2016-06-25 10:35:27 +02:00
|
|
|
flag = flag and entry in content
|
|
|
|
return flag
|
|
|
|
|
|
|
|
failed = True
|
2018-01-01 07:38:28 +01:00
|
|
|
log_output = []
|
2016-06-25 10:35:27 +02:00
|
|
|
print("Polling logfile", end='')
|
2018-01-01 07:38:28 +01:00
|
|
|
logfile = open(logfile_name, 'rb', buffering=0)
|
2018-01-01 07:52:03 +01:00
|
|
|
# Attempt to poll the log file for 60 sec. to see if all worker threads are launched.
|
|
|
|
for i in range(200):
|
2016-07-21 19:21:14 +02:00
|
|
|
time.sleep(0.3)
|
2016-06-25 10:35:27 +02:00
|
|
|
sys.stdout.write('.')
|
|
|
|
sys.stdout.flush()
|
2018-01-01 07:38:28 +01:00
|
|
|
new_data = logfile.read().decode()
|
|
|
|
if new_data:
|
|
|
|
log_output.append(new_data)
|
|
|
|
|
|
|
|
if check(''.join(log_output)):
|
2016-06-25 10:35:27 +02:00
|
|
|
failed = False
|
|
|
|
break
|
|
|
|
sys.stdout.write('\n')
|
2018-01-01 07:38:28 +01:00
|
|
|
logfile.close()
|
2016-06-25 10:35:27 +02:00
|
|
|
|
|
|
|
if not failed:
|
2017-01-12 05:45:20 +01:00
|
|
|
print('Worker threads launched successfully')
|
2016-06-25 10:35:27 +02:00
|
|
|
else:
|
|
|
|
print('Error in server startup. Dumping logs')
|
2018-01-01 07:38:28 +01:00
|
|
|
print(''.join(log_output))
|
|
|
|
|
|
|
|
return failed
|
2016-06-25 10:35:27 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print('\nStarting Development Server')
|
2018-01-01 07:38:28 +01:00
|
|
|
logfile_name = '/tmp/run-dev-output'
|
|
|
|
logfile = open(logfile_name, 'wb', buffering=0)
|
2016-06-25 10:35:27 +02:00
|
|
|
args = ["{}/run-dev.py".format(TOOLS_DIR)]
|
2018-01-01 07:38:28 +01:00
|
|
|
run_dev = subprocess.Popen(args, stdout=logfile, stderr=subprocess.STDOUT)
|
2016-06-25 10:35:27 +02:00
|
|
|
|
2018-01-01 07:38:28 +01:00
|
|
|
failed = check_worker_launch(logfile_name)
|
|
|
|
if failed:
|
|
|
|
run_dev.send_signal(signal.SIGINT)
|
|
|
|
run_dev.wait()
|
|
|
|
logfile.close()
|
|
|
|
sys.exit(1)
|
|
|
|
|
2018-01-05 08:56:14 +01:00
|
|
|
# The autoreload code of Django works by looping over the files associated
|
|
|
|
# with all the loaded modules. This loop is run after every 1 second. If
|
|
|
|
# the file is found for the first time by the loop, it is assumed that the
|
|
|
|
# file is new and is not modified between the time it is loaded and is
|
|
|
|
# checked by the loop. This assumption is the source of a race condition.
|
|
|
|
|
|
|
|
# We can either implement a more sensitive version of the loop or we can
|
|
|
|
# just allow enough time to the Django loop to touch every file at least
|
|
|
|
# once.
|
|
|
|
time.sleep(1.1)
|
2018-01-01 07:38:28 +01:00
|
|
|
# Removing all data from the server log file.
|
2016-06-25 10:35:27 +02:00
|
|
|
logfile.truncate(0)
|
2018-01-01 07:38:28 +01:00
|
|
|
logfile.seek(0)
|
2016-06-25 10:35:27 +02:00
|
|
|
|
|
|
|
print("Attempting to modify a file")
|
|
|
|
subprocess.call(['touch', 'zerver/lib/actions.py'])
|
2018-01-01 07:38:28 +01:00
|
|
|
failed = check_worker_launch(logfile_name)
|
2016-06-25 10:35:27 +02:00
|
|
|
|
|
|
|
run_dev.send_signal(signal.SIGINT)
|
|
|
|
run_dev.wait()
|
|
|
|
logfile.close()
|
2018-01-01 07:38:28 +01:00
|
|
|
if failed:
|
|
|
|
sys.exit(1)
|