#!/usr/bin/python3
import subprocess
import os
import os.path
import argparse


def parse_arguments():
    parser = argparse.ArgumentParser(description="sigterm test")
    parser.add_argument(
        "--sigterm-all",
        default=False,
        help="indicate 'sigterm-all' variant of the test",
        action="store_true",
    )

    return parser.parse_args()


def main(opts) -> None:
    print("start-refresh-mode-sigkill")
    print("running a process")
    # This actual sleep process is (ahem) actually needed because the test is
    # looking for it. In addition this actually checks how children are (or
    # are not) killed by systemd.
    proc = subprocess.Popen(["sleep", "3133731337"])
    # write ready marker file
    name = "ready-all" if opts.sigterm_all else "ready"
    with open(os.path.join(os.getenv("SNAP_COMMON", ""), name), "w"):
        pass

    proc.wait()


if __name__ == "__main__":
    main(parse_arguments())
