2021-11-05 13:36:33 -04:00
|
|
|
import logging
|
|
|
|
import signal
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import click
|
2022-12-24 13:53:06 -05:00
|
|
|
from oslo_config import cfg
|
2021-11-05 13:36:33 -04:00
|
|
|
|
|
|
|
import aprsd
|
2023-07-08 17:30:22 -04:00
|
|
|
from aprsd import cli_helper, client
|
|
|
|
from aprsd import main as aprsd_main
|
|
|
|
from aprsd import packets, plugin, threads, utils
|
|
|
|
from aprsd.main import cli
|
2022-12-31 16:31:40 -05:00
|
|
|
from aprsd.rpc import server as rpc_server
|
2024-02-26 18:28:52 -05:00
|
|
|
from aprsd.threads import registry, rx, tx
|
2021-11-05 13:36:33 -04:00
|
|
|
|
|
|
|
|
2022-12-24 13:53:06 -05:00
|
|
|
CONF = cfg.CONF
|
2021-11-05 13:36:33 -04:00
|
|
|
LOG = logging.getLogger("APRSD")
|
|
|
|
|
|
|
|
|
|
|
|
# main() ###
|
|
|
|
@cli.command()
|
2021-11-08 11:52:41 -05:00
|
|
|
@cli_helper.add_options(cli_helper.common_options)
|
2021-11-05 13:36:33 -04:00
|
|
|
@click.option(
|
|
|
|
"-f",
|
|
|
|
"--flush",
|
|
|
|
"flush",
|
|
|
|
is_flag=True,
|
|
|
|
show_default=True,
|
|
|
|
default=False,
|
|
|
|
help="Flush out all old aged messages on disk.",
|
|
|
|
)
|
|
|
|
@click.pass_context
|
2021-11-08 11:52:41 -05:00
|
|
|
@cli_helper.process_standard_options
|
2021-11-05 13:36:33 -04:00
|
|
|
def server(ctx, flush):
|
2021-11-05 14:05:24 -04:00
|
|
|
"""Start the aprsd server gateway process."""
|
2021-11-05 13:36:33 -04:00
|
|
|
signal.signal(signal.SIGINT, aprsd_main.signal_handler)
|
|
|
|
signal.signal(signal.SIGTERM, aprsd_main.signal_handler)
|
|
|
|
|
|
|
|
level, msg = utils._check_version()
|
|
|
|
if level:
|
|
|
|
LOG.warning(msg)
|
|
|
|
else:
|
|
|
|
LOG.info(msg)
|
|
|
|
LOG.info(f"APRSD Started version: {aprsd.__version__}")
|
|
|
|
|
|
|
|
# Initialize the client factory and create
|
|
|
|
# The correct client object ready for use
|
2022-12-24 13:53:06 -05:00
|
|
|
client.ClientFactory.setup()
|
2022-12-29 14:15:56 -05:00
|
|
|
|
|
|
|
# Create the initial PM singleton and Register plugins
|
|
|
|
# We register plugins first here so we can register each
|
|
|
|
# plugins config options, so we can dump them all in the
|
|
|
|
# log file output.
|
|
|
|
LOG.info("Loading Plugin Manager and registering plugins")
|
|
|
|
plugin_manager = plugin.PluginManager()
|
|
|
|
plugin_manager.setup_plugins()
|
|
|
|
|
|
|
|
# Dump all the config options now.
|
|
|
|
CONF.log_opt_values(LOG, logging.DEBUG)
|
2023-04-20 14:31:50 -04:00
|
|
|
message_plugins = plugin_manager.get_message_plugins()
|
|
|
|
watchlist_plugins = plugin_manager.get_watchlist_plugins()
|
|
|
|
LOG.info("Message Plugins enabled and running:")
|
|
|
|
for p in message_plugins:
|
|
|
|
LOG.info(p)
|
|
|
|
LOG.info("Watchlist Plugins enabled and running:")
|
|
|
|
for p in watchlist_plugins:
|
|
|
|
LOG.info(p)
|
2022-12-29 14:15:56 -05:00
|
|
|
|
2021-11-05 13:36:33 -04:00
|
|
|
# Make sure we have 1 client transport enabled
|
|
|
|
if not client.factory.is_client_enabled():
|
|
|
|
LOG.error("No Clients are enabled in config.")
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2022-02-21 16:04:33 -05:00
|
|
|
if not client.factory.is_client_configured():
|
|
|
|
LOG.error("APRS client is not properly configured in config file.")
|
|
|
|
sys.exit(-1)
|
|
|
|
|
2021-11-05 13:36:33 -04:00
|
|
|
# Creates the client object
|
2022-12-29 14:15:56 -05:00
|
|
|
# LOG.info("Creating client connection")
|
|
|
|
# client.factory.create().client
|
2021-11-05 13:36:33 -04:00
|
|
|
|
|
|
|
# Now load the msgTrack from disk if any
|
2022-12-24 13:53:06 -05:00
|
|
|
packets.PacketList()
|
2021-11-05 13:36:33 -04:00
|
|
|
if flush:
|
|
|
|
LOG.debug("Deleting saved MsgTrack.")
|
2022-12-24 13:53:06 -05:00
|
|
|
packets.PacketTrack().flush()
|
2022-12-29 14:15:56 -05:00
|
|
|
packets.WatchList().flush()
|
|
|
|
packets.SeenList().flush()
|
2021-11-05 13:36:33 -04:00
|
|
|
else:
|
|
|
|
# Try and load saved MsgTrack list
|
|
|
|
LOG.debug("Loading saved MsgTrack object.")
|
2022-12-24 13:53:06 -05:00
|
|
|
packets.PacketTrack().load()
|
|
|
|
packets.WatchList().load()
|
|
|
|
packets.SeenList().load()
|
2021-11-05 13:36:33 -04:00
|
|
|
|
2023-08-23 13:45:46 -04:00
|
|
|
keepalive = threads.KeepAliveThread()
|
|
|
|
keepalive.start()
|
|
|
|
|
2022-07-28 13:54:16 -04:00
|
|
|
rx_thread = rx.APRSDPluginRXThread(
|
2022-12-18 08:52:58 -05:00
|
|
|
packet_queue=threads.packet_queue,
|
2021-11-05 13:36:33 -04:00
|
|
|
)
|
2022-12-18 08:52:58 -05:00
|
|
|
process_thread = rx.APRSDPluginProcessPacketThread(
|
|
|
|
packet_queue=threads.packet_queue,
|
|
|
|
)
|
2021-11-05 13:36:33 -04:00
|
|
|
rx_thread.start()
|
2022-12-18 08:52:58 -05:00
|
|
|
process_thread.start()
|
2021-11-05 13:36:33 -04:00
|
|
|
|
2022-12-15 17:23:54 -05:00
|
|
|
packets.PacketTrack().restart()
|
2024-02-25 14:19:30 -05:00
|
|
|
if CONF.enable_beacon:
|
|
|
|
LOG.info("Beacon Enabled. Starting Beacon thread.")
|
|
|
|
bcn_thread = tx.BeaconSendThread()
|
|
|
|
bcn_thread.start()
|
2021-11-05 13:36:33 -04:00
|
|
|
|
2024-02-26 18:28:52 -05:00
|
|
|
if CONF.aprs_registry.enabled:
|
|
|
|
LOG.info("Registry Enabled. Starting Registry thread.")
|
|
|
|
registry_thread = registry.APRSRegistryThread()
|
|
|
|
registry_thread.start()
|
|
|
|
|
2022-12-28 15:44:49 -05:00
|
|
|
if CONF.rpc_settings.enabled:
|
|
|
|
rpc = rpc_server.APRSDRPCThread()
|
|
|
|
rpc.start()
|
|
|
|
log_monitor = threads.log_monitor.LogMonitorThread()
|
|
|
|
log_monitor.start()
|
2021-11-05 13:36:33 -04:00
|
|
|
|
2023-01-07 14:57:25 -05:00
|
|
|
rx_thread.join()
|
|
|
|
process_thread.join()
|
|
|
|
|
2021-11-05 13:36:33 -04:00
|
|
|
return 0
|