def shutdown(*args): for service in reversed(services): log.info("Stopping {0}".format(service)) system.service(service, "stop")
import util.system as system import util.remote as remote from util.log import log import sys kojidatabase_name = "kojidatabase" remote.require_container(kojidatabase_name) remote.wait_if_not_up(kojidatabase_name, 5432) services = ["httpd"] if not "nokojira" in sys.argv: services.append("kojira") def shutdown(*args): for service in reversed(services): log.info("Stopping {0}".format(service)) system.service(service, "stop") cleanup.register_excepthook(shutdown) cleanup.register_sig_handler(shutdown) for service in services: log.info("Starting {0}".format(service)) system.service(service, "start") log.info("Monitoring httpd log") tail.watch("/var/log/httpd/error_log")
#!/usr/bin/env python2 import util.cleanup as cleanup import util.tail as tail import util.system as system from util.log import log services = ["postgresql"] def shutdown(*args): for service in reversed(services): log.info("Stopping {0}".format(service)) system.service(service, "stop") cleanup.register_excepthook(shutdown) cleanup.register_sig_handler(shutdown) for service in services: log.info("Starting {0}".format(service)) system.service(service, "start") log.info("Monitoring postgresql log") log_files = [] for day in ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]: log_files.append("/var/lib/pgsql/data/pg_log/postgresql-{0}.log".format(day)) tail.watch(log_files)
# Postgre SQL # log.info("Install PostgreSQL Server") pkg.install("postgresql-server") sql.init_db() log.info("Modify PostgreSQL initscript") with cfg.mod_text("/etc/init.d/postgresql") as p: # Can't write to /proc/self/oom_adj in docker, causes error message on start, so disable index = p.index("PG_OOM_ADJ=-17\n") p[index] = "PG_OOM_ADJ=\n" log.info("Start PostgreSQL Server") postgresql_service = "postgresql" system.service(postgresql_service, "start") log.info("Create koji user") koji_user = "******" koji_db_name = "koji" system.add_system_user(koji_user) log.info("Setup PostgreSQL Koji DB") postgres_user = "******" system.run_as(postgres_user, ["createuser", "-SDR", koji_user]) system.run_as(postgres_user, ["createdb", "-O", koji_user, koji_db_name]) log.info("Download initial schema") # CentOS Docker image seems to sliently nuke docs, rpm cache, etc., so get schema.sql manually with pkg.fetch_rpm_file("koji", "usr/share/doc/koji-*/docs/schema.sql") as schema_sql: sql.exec_file(koji_user, koji_db_name, schema_sql)