@@ -86,22 +86,53 @@ const ENV_SYSTEMD_PID: &str = "LISTEN_PID";
8686const REBIND_SYSTEMD_PID : & str = "auto" ;
8787
8888/// Settings for graceful restarts
89+ #[ non_exhaustive]
8990pub struct RestartConfig {
9091 /// Enables the restart coordination socket for graceful restarts as an alternative to a Unix signal.
91- pub enabled : bool ,
92+ enabled : bool ,
9293 /// Socket path
93- pub coordination_socket_path : PathBuf ,
94+ coordination_socket_path : PathBuf ,
9495 /// Sets environment variables on the newly-started process
95- pub environment : Vec < ( OsString , OsString ) > ,
96+ environment : Vec < ( OsString , OsString ) > ,
9697 /// Receive fine-grained events on the lifecycle of the new process and support data transfer.
97- pub lifecycle_handler : Box < dyn LifecycleHandler > ,
98+ lifecycle_handler : Box < dyn LifecycleHandler > ,
9899 /// Exits early when child process fail to start
99- pub exit_on_error : bool ,
100+ exit_on_error : bool ,
100101 /// Sets the signal to listen to on restart. This defaults to SIGUSR1.
101- pub restart_signal : SignalKind ,
102+ restart_signal : SignalKind ,
102103}
103104
104105impl RestartConfig {
106+ pub fn new ( ) -> Self {
107+ Default :: default ( )
108+ }
109+
110+ pub fn coordination_socket < P : AsRef < Path > > ( & mut self , path : P ) -> & mut Self {
111+ self . enabled = true ;
112+ self . coordination_socket_path = path. as_ref ( ) . into ( ) ;
113+ self
114+ }
115+
116+ pub fn environment ( & mut self , vars : Vec < ( OsString , OsString ) > ) -> & mut Self {
117+ self . environment = vars;
118+ self
119+ }
120+
121+ pub fn lifecycle_handler < H : LifecycleHandler + ' static > ( & mut self , handler : H ) -> & mut Self {
122+ self . lifecycle_handler = Box :: new ( handler) ;
123+ self
124+ }
125+
126+ pub fn should_exit_on_error ( & mut self , exit : bool ) -> & mut Self {
127+ self . exit_on_error = exit;
128+ self
129+ }
130+
131+ pub fn restart_signal ( & mut self , signal : SignalKind ) -> & mut Self {
132+ self . restart_signal = signal;
133+ self
134+ }
135+
105136 /// Prepare the current process to handle restarts, if enabled.
106137 pub fn try_into_restart_task (
107138 self ,
0 commit comments