@@ -41,10 +41,10 @@ mod windows_service_glue {
4141 use std:: time:: Duration ;
4242
4343 use windows_service:: service:: {
44- ControlAccepted , ServiceExitCode , ServiceState , ServiceStatus , ServiceType ,
45- SimpleServiceControl , ServiceControlFlow ,
44+ ServiceControl , ServiceControlAccept , ServiceExitCode , ServiceState , ServiceStatus , ServiceType ,
45+ ServiceControlHandlerResult ,
4646 } ;
47- use windows_service:: { service_control_handler} ;
47+ use windows_service:: service_control_handler;
4848
4949 pub const SERVICE_NAME : & str = "SFCoreAIService" ;
5050 pub const SERVICE_DISPLAY_NAME : & str = "SFCore AI Inference Server" ;
@@ -58,14 +58,14 @@ mod windows_service_glue {
5858 let ( shutdown_tx, shutdown_rx) = mpsc:: channel :: < ( ) > ( ) ;
5959
6060 // Control handler: SCM kirim Stop → kita kirim shutdown signal
61- let control_handler = move |control : SimpleServiceControl | -> ServiceControlFlow {
61+ let control_handler = move |control : ServiceControl | -> ServiceControlHandlerResult {
6262 match control {
63- SimpleServiceControl :: Stop => {
63+ ServiceControl :: Stop => {
6464 log:: info!( "[WinService] Received STOP signal" ) ;
6565 let _ = shutdown_tx. send ( ( ) ) ;
66- ServiceControlFlow :: Continue
66+ ServiceControlHandlerResult :: NoError
6767 }
68- _ => ServiceControlFlow :: Continue ,
68+ _ => ServiceControlHandlerResult :: NoError ,
6969 }
7070 } ;
7171
@@ -78,7 +78,7 @@ mod windows_service_glue {
7878 . set_service_status ( ServiceStatus {
7979 service_type : ServiceType :: OWN_PROCESS ,
8080 current_state : ServiceState :: Running ,
81- controls_accepted : ControlAccepted :: STOP ,
81+ controls_accepted : ServiceControlAccept :: STOP ,
8282 exit_code : ServiceExitCode :: Win32 ( 0 ) ,
8383 checkpoint : 0 ,
8484 wait_hint : Duration :: from_secs ( 0 ) ,
@@ -105,7 +105,7 @@ mod windows_service_glue {
105105 let _ = status_handle. set_service_status ( ServiceStatus {
106106 service_type : ServiceType :: OWN_PROCESS ,
107107 current_state : ServiceState :: Stopped ,
108- controls_accepted : ControlAccepted :: empty ( ) ,
108+ controls_accepted : ServiceControlAccept :: empty ( ) ,
109109 exit_code : ServiceExitCode :: Win32 ( 0 ) ,
110110 checkpoint : 0 ,
111111 wait_hint : Duration :: from_secs ( 0 ) ,
@@ -218,8 +218,10 @@ struct Args {
218218// ============================================================
219219#[ cfg( windows) ]
220220fn handle_windows_service_commands ( args : & Args ) -> Result < bool > {
221- use windows_service:: service:: { ServiceAccess , ServiceConfig , ServiceErrorControl , ServiceStartType , ServiceType } ;
222- use windows_service:: service_manager:: { ManagerAccess , ServiceManager } ;
221+ use windows_service:: service:: {
222+ ServiceAccess , ServiceErrorControl , ServiceStartType , ServiceType , ServiceInfo ,
223+ } ;
224+ use windows_service:: service_manager:: { ServiceManager , ServiceManagerAccess } ;
223225 use windows_service_glue:: { SERVICE_DESCRIPTION , SERVICE_DISPLAY_NAME , SERVICE_NAME } ;
224226
225227 let is_service_cmd = args. install || args. remove || args. start || args. stop || args. service ;
@@ -231,21 +233,27 @@ fn handle_windows_service_commands(args: &Args) -> Result<bool> {
231233 if args. install {
232234 let exe_path = std:: env:: current_exe ( ) . context ( "Failed to get current exe path" ) ?;
233235
234- let manager = ServiceManager :: local_computer ( None :: < & str > , ManagerAccess :: CONNECT | ManagerAccess :: CREATE_SERVICE )
236+ let manager = ServiceManager :: local_computer ( None :: < & str > , ServiceManagerAccess :: CONNECT | ServiceManagerAccess :: CREATE_SERVICE )
235237 . context ( "Failed to connect to Service Manager" ) ?;
236238
239+ let service_info = ServiceInfo {
240+ name : SERVICE_NAME ,
241+ display_name : SERVICE_DISPLAY_NAME ,
242+ service_type : ServiceType :: OWN_PROCESS ,
243+ start_type : ServiceStartType :: AutoStart ,
244+ error_control : ServiceErrorControl :: Normal ,
245+ executable_path : & exe_path,
246+ launch_protected : windows_service:: service:: ServiceLaunchProtected :: None ,
247+ dependencies : vec ! [ ] ,
248+ load_order_group : None ,
249+ tag_id : None ,
250+ account_name : None ,
251+ password : None ,
252+ description : Some ( SERVICE_DESCRIPTION . into ( ) ) ,
253+ } ;
254+
237255 manager
238- . create_service ( ServiceConfig {
239- name : SERVICE_NAME . into ( ) ,
240- display_name : SERVICE_DISPLAY_NAME . into ( ) ,
241- service_type : ServiceType :: OWN_PROCESS ,
242- start_type : ServiceStartType :: Auto ,
243- error_control : ServiceErrorControl :: Normal ,
244- executable_path : exe_path. clone ( ) ,
245- dependencies : None ,
246- account : None ,
247- description : Some ( SERVICE_DESCRIPTION . into ( ) ) ,
248- } )
256+ . create_service ( service_info, ServiceAccess :: all ( ) )
249257 . context ( "Failed to create service" ) ?;
250258
251259 info ! ( "✅ Service '{}' installed" , SERVICE_NAME ) ;
@@ -257,7 +265,7 @@ fn handle_windows_service_commands(args: &Args) -> Result<bool> {
257265
258266 // ---- REMOVE ----
259267 if args. remove {
260- let manager = ServiceManager :: local_computer ( None :: < & str > , ManagerAccess :: CONNECT )
268+ let manager = ServiceManager :: local_computer ( None :: < & str > , ServiceManagerAccess :: CONNECT )
261269 . context ( "Failed to connect to Service Manager" ) ?;
262270
263271 let service = manager
@@ -271,21 +279,22 @@ fn handle_windows_service_commands(args: &Args) -> Result<bool> {
271279
272280 // ---- START ----
273281 if args. start {
274- let manager = ServiceManager :: local_computer ( None :: < & str > , ManagerAccess :: CONNECT )
282+ let manager = ServiceManager :: local_computer ( None :: < & str > , ServiceManagerAccess :: CONNECT )
275283 . context ( "Failed to connect to Service Manager" ) ?;
276284
277285 let service = manager
278286 . open_service ( SERVICE_NAME , ServiceAccess :: START )
279287 . context ( "Failed to open service" ) ?;
280288
281- service. start :: < Vec < & str > > ( & [ ] ) . context ( "Failed to start service" ) ?;
289+ let args: Vec < std:: ffi:: OsString > = Vec :: new ( ) ;
290+ service. start ( & args) . context ( "Failed to start service" ) ?;
282291 info ! ( "✅ Service '{}' started" , SERVICE_NAME ) ;
283292 return Ok ( true ) ;
284293 }
285294
286295 // ---- STOP ----
287296 if args. stop {
288- let manager = ServiceManager :: local_computer ( None :: < & str > , ManagerAccess :: CONNECT )
297+ let manager = ServiceManager :: local_computer ( None :: < & str > , ServiceManagerAccess :: CONNECT )
289298 . context ( "Failed to connect to Service Manager" ) ?;
290299
291300 let service = manager
0 commit comments