#!${buildout:executable} -S
#
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Kill all the test services that may persist between test runs."""

# Initialize our paths.
${python-relative-path-setup}
import sys
sys.path.insert(0, ${scripts:parts-directory|path-repr})
import site

# Tell canonical.config to use the testrunner config instance, so that
# we don't kill the real services.
from canonical.config import config
config.setInstance('testrunner')
config.generate_overrides()

import sys

from canonical.testing.layers import MemcachedLayer
from canonical.librarian.testing.server import LibrarianTestSetup
from lp.services.osutils import kill_by_pidfile


def main(args):
    if '-h' in args or '--help' in args:
        print __doc__
        return 0
    print "Killing Memcached....",
    kill_by_pidfile(MemcachedLayer.getPidFile())
    print "done."
    print "Killing Librarian....",
    LibrarianTestSetup().tearDownRoot()
    print "done."
    return 0


if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))
