@@ -8,26 +8,18 @@ use clap::Parser;
8
8
#[ cfg( feature = "sentry" ) ]
9
9
use cli:: configure_sentry;
10
10
use miette:: { Context , IntoDiagnostic , Result } ;
11
- use spfs:: Error ;
12
11
use spfs_cli_common as cli;
13
12
use spfs_cli_common:: CommandName ;
14
13
use tokio:: io:: AsyncReadExt ;
15
- #[ cfg( unix) ]
16
- use tokio:: signal:: unix:: { signal, SignalKind } ;
17
- #[ cfg( windows) ]
18
- use tokio:: signal:: windows:: ctrl_c;
19
14
use tokio:: time:: timeout;
20
15
21
16
mod signal;
22
17
#[ cfg( unix) ]
23
18
use signal:: unix_signal_handler:: UnixSignalHandler as SignalHandlerImpl ;
19
+ use signal:: SignalHandler ;
24
20
#[ cfg( windows) ]
25
21
use windows_signal_handler:: WindowsSignalHandler as SignalHandlerImpl ;
26
22
27
- use signal:: SignalHandler ;
28
-
29
-
30
-
31
23
fn main ( ) -> Result < ( ) > {
32
24
// because this function exits right away it does not
33
25
// properly handle destruction of data, so we put the actual
@@ -155,15 +147,15 @@ impl CmdMonitor {
155
147
156
148
pub async fn run_async ( & mut self , config : & spfs:: Config ) -> Result < i32 > {
157
149
let signal_future = SignalHandlerImpl :: build_signal_future ( ) ;
158
-
150
+
159
151
let repo = spfs:: open_repository ( & self . runtime_storage ) . await ?;
160
152
let storage = spfs:: runtime:: Storage :: new ( repo) ?;
161
153
let runtime = storage. read_runtime ( & self . runtime ) . await ?;
162
154
tracing:: trace!( "read runtime from storage repo" ) ;
163
-
155
+
164
156
let mut owned = spfs:: runtime:: OwnedRuntime :: upgrade_as_monitor ( runtime) . await ?;
165
157
tracing:: trace!( "upgraded to owned runtime, waiting for empty runtime" ) ;
166
-
158
+
167
159
let fut = spfs:: monitor:: wait_for_empty_runtime ( & owned, config) ;
168
160
let res = tokio:: select! {
169
161
res = fut => {
@@ -175,13 +167,13 @@ impl CmdMonitor {
175
167
_ = signal_future => Err ( spfs:: Error :: String ( "Signal received, cleaning up runtime early" . to_string( ) ) ) ,
176
168
} ;
177
169
tracing:: trace!( "runtime empty of processes " ) ;
178
-
170
+
179
171
// need to reload the runtime here to get any changes made to
180
172
// the runtime while it was running so we don't blast them the
181
173
// next time this process saves the runtime state.
182
174
tracing:: trace!( "reloading runtime data before cleanup" ) ;
183
175
owned. reload_state_from_storage ( ) . await ?;
184
-
176
+
185
177
// try to set the running to false to make this
186
178
// runtime easier to identify as safe to delete
187
179
// if the automatic cleanup fails. Any error
@@ -190,12 +182,12 @@ impl CmdMonitor {
190
182
if let Err ( err) = owned. save_state_to_storage ( ) . await {
191
183
tracing:: error!( "failed to save runtime: {err:?}" ) ;
192
184
}
193
-
185
+
194
186
tracing:: trace!( "tearing down and exiting" ) ;
195
187
if let Err ( err) = spfs:: exit_runtime ( & owned) . await {
196
188
tracing:: error!( "failed to tear down runtime: {err:?}" ) ;
197
189
}
198
-
190
+
199
191
tracing:: trace!(
200
192
"{} runtime data" ,
201
193
if owned. is_durable( ) {
@@ -216,7 +208,7 @@ impl CmdMonitor {
216
208
} else if let Err ( err) = owned. delete ( ) . await {
217
209
tracing:: error!( "failed to clean up runtime data: {err:?}" )
218
210
}
219
-
211
+
220
212
res?;
221
213
Ok ( 0 )
222
214
}
0 commit comments