@@ -9,13 +9,12 @@ use std::{
9
9
env,
10
10
net:: TcpListener ,
11
11
path:: { Path , PathBuf } ,
12
- process:: exit,
13
12
str:: FromStr ,
14
13
thread,
15
14
} ;
16
15
use zenith_utils:: { auth:: JwtAuth , logging, postgres_backend:: AuthType } ;
17
16
18
- use anyhow:: { bail, ensure, Result } ;
17
+ use anyhow:: { bail, ensure, Context , Result } ;
19
18
use clap:: { App , Arg , ArgMatches } ;
20
19
use daemonize:: Daemonize ;
21
20
@@ -349,7 +348,10 @@ fn main() -> Result<()> {
349
348
. get_matches ( ) ;
350
349
351
350
let workdir = Path :: new ( arg_matches. value_of ( "workdir" ) . unwrap_or ( ".zenith" ) ) ;
352
- let cfg_file_path = workdir. canonicalize ( ) ?. join ( "pageserver.toml" ) ;
351
+ let cfg_file_path = workdir
352
+ . canonicalize ( )
353
+ . with_context ( || format ! ( "Error opening workdir '{}'" , workdir. display( ) ) ) ?
354
+ . join ( "pageserver.toml" ) ;
353
355
354
356
let args_params = CfgFileParams :: from_args ( & arg_matches) ;
355
357
@@ -361,22 +363,37 @@ fn main() -> Result<()> {
361
363
args_params
362
364
} else {
363
365
// Supplement the CLI arguments with the config file
364
- let cfg_file_contents = std:: fs:: read_to_string ( & cfg_file_path) ?;
365
- let file_params: CfgFileParams = toml:: from_str ( & cfg_file_contents) ?;
366
+ let cfg_file_contents = std:: fs:: read_to_string ( & cfg_file_path)
367
+ . with_context ( || format ! ( "No pageserver config at '{}'" , cfg_file_path. display( ) ) ) ?;
368
+ let file_params: CfgFileParams = toml:: from_str ( & cfg_file_contents) . with_context ( || {
369
+ format ! (
370
+ "Failed to read '{}' as pageserver config" ,
371
+ cfg_file_path. display( )
372
+ )
373
+ } ) ?;
366
374
args_params. or ( file_params)
367
375
} ;
368
376
369
377
// Set CWD to workdir for non-daemon modes
370
- env:: set_current_dir ( & workdir) ?;
378
+ env:: set_current_dir ( & workdir) . with_context ( || {
379
+ format ! (
380
+ "Failed to set application's current dir to '{}'" ,
381
+ workdir. display( )
382
+ )
383
+ } ) ?;
371
384
372
385
// Ensure the config is valid, even if just init-ing
373
- let mut conf = params. try_into_config ( ) ?;
386
+ let mut conf = params. try_into_config ( ) . with_context ( || {
387
+ format ! (
388
+ "Pageserver config at '{}' is not valid" ,
389
+ cfg_file_path. display( )
390
+ )
391
+ } ) ?;
374
392
375
393
conf. daemonize = arg_matches. is_present ( "daemonize" ) ;
376
394
377
395
if init && conf. daemonize {
378
- eprintln ! ( "--daemonize cannot be used with --init" ) ;
379
- exit ( 1 ) ;
396
+ bail ! ( "--daemonize cannot be used with --init" )
380
397
}
381
398
382
399
// The configuration is all set up now. Turn it into a 'static
@@ -386,16 +403,21 @@ fn main() -> Result<()> {
386
403
387
404
// Create repo and exit if init was requested
388
405
if init {
389
- branches:: init_pageserver ( conf, create_tenant) ?;
406
+ branches:: init_pageserver ( conf, create_tenant) . context ( "Failed to init pageserver" ) ?;
390
407
// write the config file
391
- let cfg_file_contents = toml:: to_string_pretty ( & params) ?;
408
+ let cfg_file_contents = toml:: to_string_pretty ( & params)
409
+ . context ( "Failed to create pageserver config contents for initialisation" ) ?;
392
410
// TODO support enable-auth flag
393
- std:: fs:: write ( & cfg_file_path, cfg_file_contents) ?;
394
-
395
- return Ok ( ( ) ) ;
411
+ std:: fs:: write ( & cfg_file_path, cfg_file_contents) . with_context ( || {
412
+ format ! (
413
+ "Failed to initialize pageserver config at '{}'" ,
414
+ cfg_file_path. display( )
415
+ )
416
+ } ) ?;
417
+ Ok ( ( ) )
418
+ } else {
419
+ start_pageserver ( conf) . context ( "Failed to start pageserver" )
396
420
}
397
-
398
- start_pageserver ( conf)
399
421
}
400
422
401
423
fn start_pageserver ( conf : & ' static PageServerConf ) -> Result < ( ) > {
0 commit comments