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 @@ -319,6 +319,15 @@ func doDBCompactions(_ *cobra.Command, args []string) error {
319319 cmdCommon .EarlyLogAndExit (err )
320320 }
321321
322+ running , err := cmdCommon .IsNodeRunning ()
323+ if err != nil {
324+ return fmt .Errorf ("failed to ensure the node is not running: %w" , err )
325+ }
326+
327+ if running {
328+ return fmt .Errorf ("compaction can only be done when the node is not running" )
329+ }
330+
322331 dataDir := cmdCommon .DataDir ()
323332
324333 logger .Info ("Starting database compactions. This may take a while..." )
@@ -437,6 +446,15 @@ func doPrune(_ *cobra.Command, args []string) error {
437446 cmdCommon .EarlyLogAndExit (err )
438447 }
439448
449+ running , err := cmdCommon .IsNodeRunning ()
450+ if err != nil {
451+ return fmt .Errorf ("failed to ensure the node is not running: %w" , err )
452+ }
453+
454+ if running {
455+ return fmt .Errorf ("pruning can only be done when the node is not running" )
456+ }
457+
440458 if config .GlobalConfig .Consensus .Prune .Strategy == cmtConfig .PruneStrategyNone {
441459 logger .Info ("skipping consensus pruning since disabled in the config" )
442460 return nil
You can’t perform that action at this time.
0 commit comments