torrust-tracker
torrust-tracker copied to clipboard
Refactor: move service launchers to test code
Originated in: https://github.com/torrust/torrust-tracker/pull/268#issuecomment-1492269699
The API, UDP, and HTTP tracker use a similar strategy to run the service instances. There are two levels of logic:
- The
ServiceController - The
ServiceLauncher
ServiceController
The ServiceController is responsible for the following:
- Storing the configuration needed to start the service (contained from the
config.toml) file. - Starting and stopping the service
- Knowing the current state of the service:
runningorstopped.
It does not store the configuration changes. If you stop the service, the next time you start it it will use the initial configuration when the ServiceController was instantiated.
ServiceLauncher
The ServiceLauncher is responsible for the following:
- Starting the service instance.
- Starting the service instance with a graceful shutdown. It can receive a shutdown signal.
Current implementations
Tracker API:
torrust_tracker::servers::apis::server::ApiServer<S>(ServiceController)torrust_tracker::servers::apis::serverandtorrust_tracker::servers::apis::server::start_tlsfunctions (ServiceLauncher)
HTTP tracker:
torrust_tracker::servers::http::server::HttpServer(ServiceController)torrust_tracker::servers::http::v1::launcherstartandtorrust_tracker::servers::http::v1::launcherstart_tlsfunctions (ServiceLauncher)
UDP tracker:
torrust_tracker::servers::udp::server::UdpServer(ServiceController)torrust_tracker::servers::udp::server::Udp(ServiceLauncher)
Proposed changes
Some structs are only used for testing for the time being. We should move them to test modules until we needed in production code. For example, if we add a feature to check the state of a given service (we could show all the services and the ports they are using in an admin panel).
Structs only used for testing:
torrust_tracker::servers::apis::server::ApiServer<S>(ServiceController)torrust_tracker::servers::http::server::HttpServer(ServiceController)torrust_tracker::servers::udp::server::UdpServer(ServiceController)
Other dependencies are used only for testing too.
Future improvements
This is out of the scope of this issue, but maybe we could generalize a ServiceController for services that need a socket port, which is, I think, what they have in common.