You've already forked oncall
mirror of
https://github.com/linkedin/oncall.git
synced 2025-11-27 23:18:38 +02:00
* Py3 migration * Update to Python 3 for CircleCI * Fix auth bugs for python 3 Also fix notifier bug to check for active users * Update notifier exception handling Ignore role:target lookup failures from Iris, since these don't represent problems with the underlying system, just that people have inactive users on-call in the future. * Add get_id param option (#246) * add get_id param option * removed superfluous select and simplified logic * Flake8 typo (#247) * Hide confusing team settings in an advanced dropdown * Fix test fixtures * Add "allow duplicate" scheduler in UI Already in backend, so enable in FE too * Add Dockerfile to run oncall in a container * Move deps into a virtualenv. Run app not as super user. Mimick prod setup by using uwsgi * Fix issue with Dockerfile not having MANIFEST.in and wrong passwords in (#257) config * Update to ubuntu:18.04 and python3 packages and executables * Open config file as utf8 The default configuration file has utf8 characters, and python3 attempts to open the file as ASCII unless an alternate encoding is specified * Switch to the python3 uwsgi plugin * Update print and os.execv statements for python3 Python3 throws an exception when the first argument to os.execv is empty: ValueError: execv() arg 2 first element cannot be empty The module documentation suggests that the first element should be the name of the executed program: https://docs.python.org/3.7/library/os.html#os.execv * Map config.docker.yaml in to the container as a volume ./ops/entrypoint.py has the start of environment variable support to specify a configuration file, but it is incomplete until we update ./ops/daemons/uwsgi-docker.yaml or add environment support to oncall-notifier and oncall-scheduler. This commit allows users to map a specific configuration file in to their container and have it used by all oncall programs. * Convert line endings to match the rest of the project. * Add mysql port to docker configuration * Assume localhost mysql for default config.yaml * Update python-dev package and MySQL root password * Use password when configuring mysql The project has started using a password on the mysql instance. Once password auth is consistently working we can consider extracting the hardcoded password into an env file that is optionally randomly generated on initial startup. * Fix preview for round-robin (#269) * #275 fix for Python3 and Gunicorn load config * Fixed E303 flake8 * Change encoding & collation + test unicode name Co-authored-by: Daniel Wang <dwang159@gmail.com> Co-authored-by: ahm3djafri <42748963+ahm3djafri@users.noreply.github.com> Co-authored-by: TK <tkahnoski+github@gmail.com> Co-authored-by: Tim Freund <tim@freunds.net> Co-authored-by: Rafał Zawadzki <bluszcz@bluszcz.net>
96 lines
3.0 KiB
Python
96 lines
3.0 KiB
Python
# Copyright (c) LinkedIn Corporation. All rights reserved. Licensed under the BSD-2 Clause license.
|
|
# See LICENSE in the project root for license information.
|
|
|
|
import subprocess
|
|
import os
|
|
import socket
|
|
import time
|
|
import sys
|
|
from glob import glob
|
|
from oncall.utils import read_config
|
|
|
|
dbpath = '/home/oncall/db'
|
|
initializedfile = '/home/oncall/db_initialized'
|
|
|
|
|
|
def load_sqldump(config, sqlfile, one_db=True):
|
|
print('Importing %s...' % sqlfile)
|
|
with open(sqlfile) as h:
|
|
cmd = ['/usr/bin/mysql', '-h', config['host'], '-u',
|
|
config['user'], '-p' + config['password']]
|
|
if one_db:
|
|
cmd += ['-o', config['database']]
|
|
proc = subprocess.Popen(cmd, stdin=h)
|
|
proc.communicate()
|
|
|
|
if proc.returncode == 0:
|
|
print('DB successfully loaded ' + sqlfile)
|
|
return True
|
|
else:
|
|
print(('Ran into problems during DB bootstrap. '
|
|
'oncall will likely not function correctly. '
|
|
'mysql exit code: %s for %s') % (proc.returncode, sqlfile))
|
|
return False
|
|
|
|
|
|
def wait_for_mysql(config):
|
|
print('Checking MySQL liveness on %s...' % config['host'])
|
|
db_address = (config['host'], config['port'])
|
|
tries = 0
|
|
while True:
|
|
try:
|
|
sock = socket.socket()
|
|
sock.connect(db_address)
|
|
sock.close()
|
|
break
|
|
except socket.error:
|
|
if tries > 20:
|
|
print('Waited too long for DB to come up. Bailing.')
|
|
sys.exit(1)
|
|
|
|
print('DB not up yet. Waiting a few seconds..')
|
|
time.sleep(2)
|
|
tries += 1
|
|
continue
|
|
|
|
|
|
def initialize_mysql_schema(config):
|
|
print('Initializing oncall database')
|
|
# disable one_db to let schema.v0.sql create the database
|
|
re = load_sqldump(config, os.path.join(dbpath, 'schema.v0.sql'), one_db=False)
|
|
if not re:
|
|
sys.exit('Failed to load schema into DB.')
|
|
|
|
for f in glob(os.path.join(dbpath, 'patches', '*.sql')):
|
|
re = load_sqldump(config, f)
|
|
if not re:
|
|
sys.exit('Failed to load DB patche: %s.' % f)
|
|
|
|
re = load_sqldump(config, os.path.join(dbpath, 'dummy_data.sql'))
|
|
if not re:
|
|
sys.stderr.write('Failed to load dummy data.')
|
|
|
|
with open(initializedfile, 'w'):
|
|
print('Wrote %s so we don\'t bootstrap db again' % initializedfile)
|
|
|
|
|
|
def main():
|
|
oncall_config = read_config(
|
|
os.environ.get('ONCALL_CFG_PATH', '/home/oncall/config/config.yaml'))
|
|
mysql_config = oncall_config['db']['conn']['kwargs']
|
|
|
|
# It often takes several seconds for MySQL to start up. oncall dies upon start
|
|
# if it can't immediately connect to MySQL, so we have to wait for it.
|
|
wait_for_mysql(mysql_config)
|
|
|
|
if 'DOCKER_DB_BOOTSTRAP' in os.environ:
|
|
if not os.path.exists(initializedfile):
|
|
initialize_mysql_schema(mysql_config)
|
|
|
|
os.execv('/usr/bin/uwsgi',
|
|
['/usr/bin/uwsgi', '--yaml', '/home/oncall/daemons/uwsgi.yaml:prod'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|