@@ -3,6 +3,8 @@ package cmd
33import (
44 "context"
55 "fmt"
6+ "time"
7+
68 "github.com/algorandfoundation/nodekit/api"
79 cmdutils "github.com/algorandfoundation/nodekit/cmd/utils"
810 "github.com/algorandfoundation/nodekit/cmd/utils/explanations"
@@ -18,7 +20,6 @@ import (
1820 "github.com/charmbracelet/lipgloss"
1921 "github.com/charmbracelet/log"
2022 "github.com/spf13/cobra"
21- "time"
2223)
2324
2425// bootstrapCmdShort provides a brief description of the "bootstrap" command to initialize a fresh Algorand node.
@@ -40,7 +41,7 @@ var bootstrapCmdLong = lipgloss.JoinVertical(
4041
4142var tutorial = `# Welcome!
4243
43- This is the beginning of your adventure into running the an Algorand node!
44+ This is the beginning of your adventure into running an Algorand node!
4445
4546`
4647
@@ -51,6 +52,17 @@ var bootstrapCmd = &cobra.Command{
5152 Long : bootstrapCmdLong ,
5253 SilenceUsage : true ,
5354 RunE : func (cmd * cobra.Command , args []string ) error {
55+ // Exit the application in an invalid state
56+ if algod .IsInstalled () && ! algod .IsService () {
57+ dataDir , _ := algod .GetDataDir ("" )
58+ if dataDir == "" {
59+ dataDir = "<Path to data directory>"
60+ }
61+ log .Warn ("algorand is installed, but not running as a service. Continue at your own risk!" )
62+ log .Warn (fmt .Sprintf ("try connecting to the node with: ./nodekit -d %s" , dataDir ))
63+ log .Fatal ("invalid state, exiting" )
64+ }
65+
5466 ctx := context .Background ()
5567 httpPkg := new (api.HttpPkg )
5668 r , _ := glamour .NewTermRenderer (
@@ -84,23 +96,36 @@ var bootstrapCmd = &cobra.Command{
8496 if _ , err := p .Run (); err != nil {
8597 log .Fatal (err )
8698 }
99+
87100 if msg == nil {
88101 return nil
89102 }
90103
91- log .Warn (style .Yellow .Render (explanations .SudoWarningMsg ))
92- if msg .Install && ! algod .IsInstalled () {
104+ if msg .Install {
105+ log .Warn (style .Yellow .Render (explanations .SudoWarningMsg ))
106+
93107 err := algod .Install ()
94108 if err != nil {
95109 return err
96110 }
97- }
98111
99- // Wait for algod
100- time .Sleep (10 * time .Second )
112+ // Wait for algod
113+ time .Sleep (10 * time .Second )
101114
102- if ! algod .IsRunning () {
103- log .Fatal ("algod is not running" )
115+ if ! algod .IsRunning () {
116+ log .Fatal ("algod is not running. Something went wrong with installation" )
117+ }
118+ } else {
119+ if ! algod .IsRunning () {
120+ log .Info (style .Green .Render ("Starting Algod 🚀" ))
121+ log .Warn (style .Yellow .Render (explanations .SudoWarningMsg ))
122+ err := algod .Start ()
123+ if err != nil {
124+ log .Fatal (err )
125+ }
126+ log .Info (style .Green .Render ("Algorand started successfully 🎉" ))
127+ time .Sleep (2 * time .Second )
128+ }
104129 }
105130
106131 dataDir , err := algod .GetDataDir ("" )
@@ -114,7 +139,6 @@ var bootstrapCmd = &cobra.Command{
114139 }
115140
116141 if msg .Catchup {
117-
118142 network , err := utils .GetNetworkFromDataDir (dataDir )
119143 if err != nil {
120144 return err
0 commit comments