service testing
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
blackbeard420 2023-12-30 23:55:04 -05:00
parent d13b6c9bb6
commit ee30646449
Signed by: blackbeard420
GPG Key ID: 88C719E09CDDA4A5

View File

@ -6,17 +6,56 @@ extern crate windows_service;
use irc_rpc::start_loop;
use std::ffi::OsString;
use windows_service::service_dispatcher;
use std::time::Duration;
use windows_service::{
define_windows_service,
service::{
ServiceControl, ServiceControlAccept, ServiceExitCode, ServiceState, ServiceStatus,
ServiceType,
},
service_control_handler::{self, ServiceControlHandlerResult},
service_dispatcher, Result,
};
const SERVICE_TYPE: ServiceType = ServiceType::OWN_PROCESS;
define_windows_service!(ffi_service_main, my_service_main);
fn my_service_main(arguments: Vec<OsString>) {
// The entry point where execution will start on a background thread after a call to
// `service_dispatcher::start` from `main`.
let event_handler = move |control_event| -> ServiceControlHandlerResult {
match control_event {
// Notifies a service to report its current status information to the service
// control manager. Always return NoError even if not implemented.
ServiceControl::Interrogate => ServiceControlHandlerResult::NoError,
// Handle stop
ServiceControl::Stop => {
ServiceControlHandlerResult::NoError
}
_ => ServiceControlHandlerResult::NotImplemented,
}
};
let status_handle = service_control_handler::register("irc-rpc", event_handler).unwrap();
status_handle.set_service_status(ServiceStatus {
service_type: SERVICE_TYPE,
current_state: ServiceState::Running,
controls_accepted: ServiceControlAccept::STOP,
exit_code: ServiceExitCode::Win32(0),
checkpoint: 0,
wait_hint: Duration::default(),
process_id: None,
}).unwrap();
start_loop();
}
fn main() -> Result<(), windows_service::Error> {
fn main() -> windows_service::Result<()> {
// Register generated `ffi_service_main` with the system and start the service, blocking
// this thread until the service is stopped.
service_dispatcher::start("irc-rpc", ffi_service_main)?;