@@ -87,18 +87,28 @@ pub struct Status {
8787pub struct Api {
8888 zinit : ZInit ,
8989 socket : PathBuf ,
90- // http_port removed as it's now in a separate binary
90+ config_dir : PathBuf , // Configuration directory path
9191}
9292
9393impl Api {
9494 pub fn new < P : AsRef < Path > > ( zinit : ZInit , socket : P , _http_port : Option < u16 > ) -> Api {
9595 // _http_port parameter kept for backward compatibility but not used
96+ // Default to /etc/zinit if not specified
97+ let config_dir = PathBuf :: from ( "/etc/zinit" ) ;
98+
9699 Api {
97100 zinit,
98101 socket : socket. as_ref ( ) . to_path_buf ( ) ,
102+ config_dir,
99103 }
100104 }
101105
106+ // Add a way to explicitly set the config directory
107+ pub fn with_config_dir < P : AsRef < Path > > ( mut self , config_dir : P ) -> Self {
108+ self . config_dir = config_dir. as_ref ( ) . to_path_buf ( ) ;
109+ self
110+ }
111+
102112 // HTTP proxy functionality has been moved to a separate binary (zinit-http)
103113
104114 pub async fn serve ( & self ) -> Result < ( ) > {
@@ -625,8 +635,11 @@ impl Api {
625635 }
626636
627637 async fn monitor < S : AsRef < str > > ( name : S , zinit : ZInit ) -> Result < Value > {
638+ // Use the existing working directory which should be set to the config dir
639+ // when Zinit is started with the -c flag (default /etc/zinit)
628640 let ( name, service) = config:: load ( format ! ( "{}.yaml" , name. as_ref( ) ) )
629641 . context ( "failed to load service config" ) ?;
642+
630643 zinit. monitor ( name, service) . await ?;
631644 Ok ( Value :: Null )
632645 }
@@ -712,11 +725,11 @@ impl Api {
712725 bail ! ( "Invalid service name: must not contain '/', '\\ ', or '.'" ) ;
713726 }
714727
715- // Construct the file path
716- let file_path = PathBuf :: from ( format ! ( "{}.yaml" , name) ) ;
728+ // Use the daemon's working directory which should be the config dir
729+ let file_path = format ! ( "{}.yaml" , name) ;
717730
718731 // Check if the service file already exists
719- if file_path. exists ( ) {
732+ if Path :: new ( & file_path) . exists ( ) {
720733 bail ! ( "Service '{}' already exists" , name) ;
721734 }
722735
@@ -745,11 +758,11 @@ impl Api {
745758 bail ! ( "Invalid service name: must not contain '/', '\\ ', or '.'" ) ;
746759 }
747760
748- // Construct the file path
749- let file_path = PathBuf :: from ( format ! ( "{}.yaml" , name) ) ;
761+ // Use the daemon's working directory which should be the config dir
762+ let file_path = format ! ( "{}.yaml" , name) ;
750763
751764 // Check if the service file exists
752- if !file_path. exists ( ) {
765+ if !Path :: new ( & file_path) . exists ( ) {
753766 bail ! ( "Service '{}' not found" , name) ;
754767 }
755768
@@ -772,11 +785,11 @@ impl Api {
772785 bail ! ( "Invalid service name: must not contain '/', '\\ ', or '.'" ) ;
773786 }
774787
775- // Construct the file path
776- let file_path = PathBuf :: from ( format ! ( "{}.yaml" , name) ) ;
788+ // Use the daemon's working directory which should be the config dir
789+ let file_path = format ! ( "{}.yaml" , name) ;
777790
778791 // Check if the service file exists
779- if !file_path. exists ( ) {
792+ if !Path :: new ( & file_path) . exists ( ) {
780793 bail ! ( "Service '{}' not found" , name) ;
781794 }
782795
0 commit comments