Skip to content

Commit 0f74685

Browse files
committed
removes isAlive check :: adds logging
1 parent 5d06de1 commit 0f74685

File tree

4 files changed

+63
-69
lines changed

4 files changed

+63
-69
lines changed

.goreleaser.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ builds:
55
goos:
66
- linux
77
- darwin
8+
- windows
89
goarch:
910
- 386
1011
- amd64
@@ -15,11 +16,10 @@ builds:
1516
goarch: 386
1617
archive:
1718
replacements:
18-
darwin: Darwin
19-
linux: Linux
20-
windows: Windows
19+
darwin: macOS
20+
windows: windows
2121
386: i386
22-
amd64: x86_64
22+
amd64: 64-bit
2323
format_overrides:
2424
- goos: windows
2525
format: zip
@@ -34,4 +34,4 @@ changelog:
3434
exclude:
3535
- Merge
3636
sign:
37-
artifacts: checksum
37+
artifacts: checksum

app/daemon/daemon.go

Lines changed: 44 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ import (
1515
"fmt"
1616

1717
"github.com/Encrypt-S/kauri-api/app/conf"
18-
"github.com/Encrypt-S/kauri-api/app/daemon/daemonrpc"
1918
"github.com/Encrypt-S/kauri-api/app/fs"
2019
)
2120

21+
// OSInfo defines OS's
2222
type OSInfo struct {
2323
DaemonName string
2424
OS string
2525
}
2626

27+
// GitHubReleases holds release data
2728
type GitHubReleases []struct {
2829
GitHubReleaseData
2930
}
3031

32+
// GitHubReleaseData defines release data avail
3133
type GitHubReleaseData struct {
3234
URL string `json:"url"`
3335
AssetsURL string `json:"assets_url"`
@@ -116,55 +118,36 @@ func StartManager(coinData conf.CoinData) {
116118
hbInterval = coinData.DaemonHeartbeat
117119
}
118120

119-
// check to see if the daemon is alive
120-
if isAlive(coinData) {
121-
log.Println(coinData.CurrencyCode + " daemon is alive!")
122-
} else {
123-
log.Println(coinData.CurrencyCode + " daemon is not yet alive...")
124-
125-
// only do thing if we are already not getting the daemon
126-
if !isGettingDaemon {
127-
log.Println(coinData.CurrencyCode + " daemon is unresponsive...")
128-
129-
if runningDaemon != nil {
130-
log.Println(coinData.CurrencyCode + " daemon is already running, just stop")
131-
Stop(coinData, runningDaemon)
132-
}
133-
134-
// kick off goroutine for DownloadAndStart
135-
go func() {
136-
137-
cmd, err := DownloadAndStart(coinData)
138-
139-
if err != nil {
140-
log.Println(err)
141-
} else {
142-
runningDaemon = cmd
143-
}
121+
// kick off goroutine for DownloadAndStart
122+
go func() {
123+
cmd, err := DownloadAndStart(coinData)
124+
if err != nil {
125+
log.Println(err)
126+
} else {
127+
runningDaemon = cmd
128+
}
144129

145-
}()
130+
}()
146131

147-
}
148-
}
149132
}
150133

151134
// returns false on error
152-
func isAlive(coinData conf.CoinData) bool {
153-
154-
isLiving := true
155-
156-
n := daemonrpc.RPCRequestData{}
157-
n.Method = "getblockcount"
158-
159-
_, err := daemonrpc.RequestDaemon(coinData, n, conf.DaemonConf)
160-
161-
if err != nil {
162-
isLiving = false
163-
}
164-
165-
return isLiving
166-
167-
}
135+
//func isAlive(coinData conf.CoinData) bool {
136+
//
137+
// isLiving := true
138+
//
139+
// n := daemonrpc.RPCRequestData{}
140+
// n.Method = "getblockcount"
141+
//
142+
// _, err := daemonrpc.RequestDaemon(coinData, n, conf.DaemonConf)
143+
//
144+
// if err != nil {
145+
// isLiving = false
146+
// }
147+
//
148+
// return isLiving
149+
//
150+
//}
168151

169152
// DownloadAndStart checks for current coin's daemon
170153
// and either downloads it or starts it up if already detected
@@ -184,12 +167,13 @@ func DownloadAndStart(coinData conf.CoinData) (*exec.Cmd, error) {
184167

185168
}
186169

187-
func Stop(coinData conf.CoinData, cmd *exec.Cmd) {
170+
// Stop kills the running daemon process
171+
// func Stop(coinData conf.CoinData, cmd *exec.Cmd) {
188172

189-
if err := cmd.Process.Kill(); err != nil {
190-
log.Fatal("failed to kill" + coinData.CurrencyCode + "process" + err.Error())
191-
}
192-
}
173+
// if err := cmd.Process.Kill(); err != nil {
174+
// log.Fatal("Failed to terminate " + coinData.CurrencyCode + " daemon process" + err.Error())
175+
// }
176+
// }
193177

194178
// CheckForDaemon checks for current coin's daemon
195179
// in appropriate path and reports back to DownLoadAndStartDaemons
@@ -198,8 +182,6 @@ func CheckForDaemon(coinData conf.CoinData) (string, error) {
198182
// get the latest release version, equal to daemon version
199183
releaseVersion := coinData.DaemonVersion
200184

201-
log.Println("Checking" + coinData.CurrencyCode + "daemon for v" + releaseVersion)
202-
203185
// get the apps current path
204186
path, err := fs.GetCurrentPath()
205187
if err != nil {
@@ -208,16 +190,15 @@ func CheckForDaemon(coinData conf.CoinData) (string, error) {
208190

209191
// build the path for current daemon
210192
path += "/lib/" + coinData.LibPath + "-" + releaseVersion + "/bin/" + getOSInfo(coinData).DaemonName
211-
log.Println("Searching for" + coinData.CurrencyCode + "daemon at " + path)
193+
log.Println("Searching for " + coinData.CurrencyCode + " daemon at " + path)
212194

213-
// check the current daemon exists
195+
// check that the current daemon exists
214196
if !fs.Exists(path) {
215-
log.Println(coinData.CurrencyCode + "daemon not found for v" + releaseVersion)
216-
return "", errors.New(coinData.CurrencyCode + "daemon found for v" + releaseVersion)
217-
} else {
218-
log.Println(coinData.CurrencyCode + "daemon located for v" + releaseVersion)
197+
return "", errors.New(coinData.CurrencyCode + " daemon not found")
219198
}
220199

200+
log.Println(coinData.CurrencyCode + " daemon located for v" + releaseVersion)
201+
221202
return path, nil
222203

223204
}
@@ -226,7 +207,7 @@ func CheckForDaemon(coinData conf.CoinData) (string, error) {
226207
// builds the command arguments, and executes start command
227208
func startCoinDaemons(coinData conf.CoinData, daemonPath string) *exec.Cmd {
228209

229-
log.Println("Booting" + coinData.CurrencyCode + "daemon")
210+
log.Println("Booting " + coinData.CurrencyCode + " daemon")
230211

231212
// build up the command flags from daemon config
232213
rpcUser := fmt.Sprintf("-rpcuser=%s", conf.DaemonConf.RPCUser)
@@ -304,6 +285,8 @@ func downloadDaemons(coinData conf.CoinData) {
304285

305286
dlPath, dlName, _ := getDownloadPathAndName(coinData, releaseInfo)
306287

288+
log.Println("Attempting to get release data for NAVCoin v" + coinData.DaemonVersion)
289+
307290
isGettingDaemon = true // flag we are getting the daemon
308291

309292
fs.DownloadExtract(dlPath, dlName)
@@ -320,7 +303,7 @@ func getReleaseDataForVersion(coinData conf.CoinData) (GitHubReleaseData, error)
320303

321304
releases, err := gitHubReleaseInfo(coinData.CurrencyCode, coinData.ReleaseAPI)
322305

323-
var e GitHubReleaseData = GitHubReleaseData{}
306+
var e = GitHubReleaseData{}
324307

325308
for _, elem := range releases {
326309
if elem.TagName == coinData.DaemonVersion {
@@ -371,7 +354,7 @@ func getDownloadPathAndName(coinData conf.CoinData, gitHubReleaseData GitHubRele
371354
asset := releaseInfo.Assets[e]
372355

373356
if strings.Contains(asset.Name, getOSInfo(coinData).OS) {
374-
// windows os check to provide .zip
357+
// windows os check to provide zip package :: .zip
375358
if strings.Contains(asset.Name, "win") {
376359
if filepath.Ext(asset.Name) == ".zip" {
377360
log.Println("win64 detected - preparing NAVCoin .zip download")
@@ -385,8 +368,6 @@ func getDownloadPathAndName(coinData conf.CoinData, gitHubReleaseData GitHubRele
385368
downloadPath = releaseInfo.Assets[e].BrowserDownloadURL
386369
downloadName = releaseInfo.Assets[e].Name
387370
} else {
388-
// TODO: more checks to be added for other systems
389-
// fall through to defaults :: fire-in-the-hole mode
390371
downloadPath = releaseInfo.Assets[e].BrowserDownloadURL
391372
downloadName = releaseInfo.Assets[e].Name
392373
}

app/fs/fs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func GetCurrentPath() (string, error) {
236236
return "", err
237237
}
238238
exPath := filepath.Dir(ex)
239+
log.Println("GetCurrentPath = " + exPath)
239240
return exPath, nil
240241
}
241242

app/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,24 @@ import (
1414
"github.com/gorilla/mux"
1515
)
1616

17+
// Idflags set by GoReleaser
18+
var (
19+
version = "dev"
20+
commit = "none"
21+
date = "unknown"
22+
)
23+
1724
func main() {
1825

19-
// prime the app
26+
// init app errors
2027
api.BuildAppErrors()
28+
29+
// init rpc details
2130
conf.CreateRPCDetails()
2231

32+
//
33+
fmt.Printf("%v, commit %v, built at %v", version, commit, date)
34+
2335
// log out server runtime OS and Architecture
2436
log.Println(fmt.Sprintf("Server running in %s:%s", runtime.GOOS, runtime.GOARCH))
2537
log.Println(fmt.Sprintf("App pid : %d.", os.Getpid()))

0 commit comments

Comments
 (0)