subiquity/system_setup/cmd/server.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
4.0 KiB
Python
Raw Normal View History

2021-07-02 08:26:21 +00:00
# Copyright 2020-2021 Canonical, Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import asyncio
2021-07-02 08:26:21 +00:00
import logging
import os
import sys
from subiquity.cmd.common import LOGDIR, setup_environment
from subiquitycore.log import setup_logger
def make_server_args_parser():
parser = argparse.ArgumentParser(
description="System Setup - Initial Boot Setup", prog="system_setup"
)
parser.add_argument(
"--dry-run",
action="store_true",
dest="dry_run",
help="menu-only, do not call installer function",
)
parser.add_argument("--socket")
parser.add_argument("--autoinstall", action="store")
parser.add_argument(
"--prefill",
dest="prefill",
2021-10-28 18:54:07 +00:00
help=(
"Prefills UI models with data provided in"
" a prefill.yaml file yet allowing overrides."
),
)
parser.add_argument(
"--output-base",
action="store",
dest="output_base",
default=".subiquity",
help="in dryrun, control basedir of files",
)
parser.add_argument(
"--tcp-port",
dest="tcp_port",
type=int,
choices=range(49152, 60999),
2022-06-16 19:15:16 +00:00
metavar="[49152 to 60999]",
help=(
"The TCP port Subiquity must listen to. It means "
"TCP will be used instead of Unix domain sockets. "
"Only localhost connections are accepted."
),
)
2021-07-02 08:26:21 +00:00
return parser
def main():
2021-07-02 08:26:21 +00:00
print("starting server")
setup_environment()
# setup_environment sets $APPORT_DATA_DIR which must be set before
# apport is imported, which is done by this import:
from subiquity.server.server import NOPROBERARG
from system_setup.server.server import SystemSetupServer
2023-07-25 21:26:25 +00:00
2021-07-02 08:26:21 +00:00
parser = make_server_args_parser()
opts = parser.parse_args(sys.argv[1:])
logdir = LOGDIR
opts.snaps_from_examples = False
opts.kernel_cmdline = {}
2021-07-02 08:26:21 +00:00
opts.machine_config = NOPROBERARG
if opts.dry_run:
logdir = opts.output_base
2021-07-02 08:26:21 +00:00
if opts.socket is None:
if opts.dry_run:
opts.socket = opts.output_base + "/socket"
2021-07-02 08:26:21 +00:00
else:
opts.socket = "/run/subiquity/socket"
os.makedirs(os.path.dirname(opts.socket), exist_ok=True)
block_log_dir = os.path.join(logdir, "block")
os.makedirs(block_log_dir, exist_ok=True)
handler = logging.FileHandler(os.path.join(block_log_dir, "discover.log"))
handler.setLevel("DEBUG")
handler.setFormatter(
logging.Formatter("%(asctime)s %(name)s:%(lineno)d %(message)s")
2023-07-25 21:26:25 +00:00
)
2021-07-02 08:26:21 +00:00
logfiles = setup_logger(dir=logdir, base="systemsetup-server")
2021-08-06 17:14:26 +00:00
logger = logging.getLogger("systemsetup-server")
2021-07-02 08:26:21 +00:00
version = "unknown"
logger.info("Starting System Setup server revision {}".format(version))
logger.info("Arguments passed: {}".format(sys.argv))
prefillFile = opts.prefill
if prefillFile:
if not os.path.isfile(prefillFile):
logger.error(
'"File {}" is invalid. Option will be ignored.'.format(prefillFile)
)
opts.prefill = None
async def run_with_loop():
server = SystemSetupServer(opts, block_log_dir)
server.note_file_for_apport("InstallerServerLog", logfiles["debug"])
server.note_file_for_apport("InstallerServerLogInfo", logfiles["info"])
await server.run()
2021-07-02 08:26:21 +00:00
asyncio.run(run_with_loop())
2021-07-02 08:26:21 +00:00
if __name__ == "__main__":
sys.exit(main())