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 = [
|
2016-06-25 10:35:27 +02:00
|
|
|
'launching queue worker thread error_reports',
|
|
|
|
'launching queue worker thread user_presence',
|
2017-11-13 21:24:51 +01:00
|
|
|
'launching queue worker thread deferred_work',
|
2016-06-25 10:35:27 +02:00
|
|
|
'launching queue worker thread digest_emails',
|
|
|
|
'launching queue worker thread slow_queries',
|
|
|
|
'launching queue worker thread missedmessage_mobile_notifications',
|
|
|
|
'launching queue worker thread feedback_messages',
|
|
|
|
'launching queue worker thread signups',
|
|
|
|
'launching queue worker thread test',
|
|
|
|
'launching queue worker thread message_sender',
|
|
|
|
'launching queue worker thread missedmessage_emails',
|
2017-11-29 08:25:57 +01:00
|
|
|
'launching queue worker thread email_senders',
|
2017-03-06 08:45:59 +01:00
|
|
|
'launching queue worker thread missedmessage_email_senders',
|
2016-06-25 10:35:27 +02:00
|
|
|
'launching queue worker thread email_mirror',
|
|
|
|
'launching queue worker thread user_activity_interval',
|
|
|
|
'launching queue worker thread invites',
|
|
|
|
'launching queue worker thread user_activity'
|
|
|
|
]
|
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def check_worker_launch(logfile):
|
|
|
|
# type: (IO[str]) -> Text
|
|
|
|
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
|
|
|
|
log_output = u''
|
|
|
|
print("Polling logfile", end='')
|
|
|
|
# Attempt to poll the log file for 10 sec. to see if all worker threads are launched.
|
2016-07-21 19:21:14 +02:00
|
|
|
for i in range(100):
|
|
|
|
time.sleep(0.3)
|
2016-06-25 10:35:27 +02:00
|
|
|
sys.stdout.write('.')
|
|
|
|
sys.stdout.flush()
|
|
|
|
logfile.seek(0)
|
|
|
|
content = logfile.read()
|
|
|
|
log_output = content
|
|
|
|
if check(content):
|
|
|
|
failed = False
|
|
|
|
break
|
|
|
|
sys.stdout.write('\n')
|
|
|
|
|
|
|
|
if not failed:
|
2017-01-12 05:45:20 +01:00
|
|
|
print('Worker threads launched successfully')
|
2016-06-25 10:35:27 +02:00
|
|
|
return log_output
|
|
|
|
else:
|
|
|
|
print('Error in server startup. Dumping logs')
|
|
|
|
print(log_output)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print('\nStarting Development Server')
|
|
|
|
logfile = open('/tmp/run-dev-output', 'w+')
|
|
|
|
args = ["{}/run-dev.py".format(TOOLS_DIR)]
|
|
|
|
run_dev = subprocess.Popen(args, stdout=logfile, stderr=logfile)
|
|
|
|
|
|
|
|
check_worker_launch(logfile)
|
|
|
|
logfile.truncate(0)
|
|
|
|
|
|
|
|
print("Attempting to modify a file")
|
|
|
|
subprocess.call(['touch', 'zerver/lib/actions.py'])
|
2016-08-09 14:12:27 +02:00
|
|
|
check_worker_launch(logfile)
|
2016-06-25 10:35:27 +02:00
|
|
|
|
|
|
|
run_dev.send_signal(signal.SIGINT)
|
|
|
|
run_dev.wait()
|
|
|
|
logfile.close()
|