@@ -16,6 +16,7 @@ pub struct ProcessInstance {
1616 pub pid : Option < u32 > ,
1717 pub auto_restart : bool ,
1818 pub auto_start : bool ,
19+ pub working_dir : Option < String > ,
1920 pub start_time : Option < u64 > ,
2021 pub crash_count : u32 ,
2122 pub should_restart : Arc < AtomicBool > ,
@@ -33,6 +34,7 @@ impl ProcessInstance {
3334 pid : None ,
3435 auto_restart,
3536 auto_start,
37+ working_dir : None ,
3638 start_time : None ,
3739 crash_count : 0 ,
3840 should_restart : Arc :: new ( AtomicBool :: new ( false ) ) ,
@@ -50,6 +52,7 @@ impl ProcessInstance {
5052 pid : None ,
5153 auto_restart : config. auto_restart ,
5254 auto_start : config. auto_start ,
55+ working_dir : config. working_dir . clone ( ) ,
5356 start_time : None ,
5457 crash_count : 0 ,
5558 should_restart : Arc :: new ( AtomicBool :: new ( false ) ) ,
@@ -79,6 +82,7 @@ impl ProcessInstance {
7982 pid : self . pid ,
8083 auto_restart : self . auto_restart ,
8184 auto_start : self . auto_start ,
85+ working_dir : self . working_dir . clone ( ) ,
8286 uptime_ms : self . get_uptime_ms ( ) ,
8387 crash_count : self . crash_count ,
8488 }
@@ -92,6 +96,7 @@ impl ProcessInstance {
9296 args : self . args . clone ( ) ,
9397 auto_restart : self . auto_restart ,
9498 auto_start : self . auto_start ,
99+ working_dir : self . working_dir . clone ( ) ,
95100 env : None ,
96101 }
97102 }
@@ -108,8 +113,9 @@ impl ProcessManager {
108113 }
109114 }
110115
111- pub fn add_process ( & mut self , name : String , command : String , args : Vec < String > , auto_restart : bool ) -> String {
112- let process = ProcessInstance :: new ( name, command, args, auto_restart, false ) ;
116+ pub fn add_process ( & mut self , name : String , command : String , args : Vec < String > , working_dir : Option < String > , auto_restart : bool ) -> String {
117+ let mut process = ProcessInstance :: new ( name, command, args, auto_restart, false ) ;
118+ process. working_dir = working_dir;
113119 let id = process. id . clone ( ) ;
114120 self . processes . insert ( id. clone ( ) , process) ;
115121 id
@@ -145,6 +151,9 @@ impl ProcessManager {
145151 cmd. args ( & process. args )
146152 . stdout ( Stdio :: piped ( ) )
147153 . stderr ( Stdio :: piped ( ) ) ;
154+ if let Some ( ref dir) = process. working_dir {
155+ cmd. current_dir ( dir) ;
156+ }
148157
149158 match cmd. spawn ( ) {
150159 Ok ( mut child) => {
0 commit comments