File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed
Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -336,7 +336,7 @@ oasis1qqncl383h8458mr9cytatygctzwsx02n4c5f8ed7
336336
337337### compact-experimental
338338
339- Run
339+ Run (when the node is not running):
340340
341341``` sh
342342oasis-node storage compact-experimental --config /path/to/config/file
@@ -367,7 +367,7 @@ maintenance periods.
367367
368368### prune-experimental
369369
370- Run
370+ Run (when the node is not running):
371371
372372``` sh
373373oasis-node storage prune-experimental --config /path/to/config/file
Original file line number Diff line number Diff line change 22package common
33
44import (
5+ "errors"
56 "fmt"
67 "io"
8+ "io/fs"
79 "os"
810 "path/filepath"
911 "strings"
@@ -71,6 +73,20 @@ func InternalSocketPath() string {
7173 return filepath .Join (DataDir (), InternalSocketName )
7274}
7375
76+ // IsNodeRunning returns true when the node is running.
77+ func IsNodeRunning () (bool , error ) {
78+ path := InternalSocketPath ()
79+
80+ if _ , err := os .Stat (path ); err != nil {
81+ if errors .Is (err , fs .ErrNotExist ) {
82+ return false , nil
83+ }
84+ return false , fmt .Errorf ("stat %s: %w" , path , err )
85+ }
86+
87+ return true , nil
88+ }
89+
7490// IsNodeCmd returns true iff the current command is the ekiden node.
7591func IsNodeCmd () bool {
7692 return isNodeCmd
Original file line number Diff line number Diff line change @@ -321,6 +321,15 @@ func doDBCompactions(_ *cobra.Command, args []string) error {
321321 cmdCommon .EarlyLogAndExit (err )
322322 }
323323
324+ running , err := cmdCommon .IsNodeRunning ()
325+ if err != nil {
326+ return fmt .Errorf ("failed to ensure the node is not running: %w" , err )
327+ }
328+
329+ if running {
330+ return fmt .Errorf ("compaction can only be done when the node is not running" )
331+ }
332+
324333 dataDir := cmdCommon .DataDir ()
325334
326335 logger .Info ("Starting database compactions. This may take a while..." )
@@ -439,6 +448,15 @@ func doPrune(_ *cobra.Command, args []string) error {
439448 cmdCommon .EarlyLogAndExit (err )
440449 }
441450
451+ running , err := cmdCommon .IsNodeRunning ()
452+ if err != nil {
453+ return fmt .Errorf ("failed to ensure the node is not running: %w" , err )
454+ }
455+
456+ if running {
457+ return fmt .Errorf ("pruning can only be done when the node is not running" )
458+ }
459+
442460 if config .GlobalConfig .Consensus .Prune .Strategy == cmtConfig .PruneStrategyNone {
443461 logger .Info ("skipping consensus pruning since disabled in the config" )
444462 return nil
You can’t perform that action at this time.
0 commit comments