Skip to content

Commit fe6d85e

Browse files
committed
go/oasis-node/cmd/storage: Warn when the node is running
1 parent a340557 commit fe6d85e

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

docs/oasis-node/cli.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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
342342
oasis-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
373373
oasis-node storage prune-experimental --config /path/to/config/file

go/oasis-node/cmd/common/common.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
package common
33

44
import (
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.
7591
func IsNodeCmd() bool {
7692
return isNodeCmd

go/oasis-node/cmd/storage/storage.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)