Skip to content

Commit

Permalink
core: rename data dir environment var
Browse files Browse the repository at this point in the history
This change serves two goals:
- Rename the env var to CHAIN_CORE_DATA.
- Leave overriding the location to platform-specific
tooling.

For the second item, the Mac OS X app explicitly sets
CHAIN_CORE_DATA to the appropriate location for
Mac OS X (as opposed to plain Darwin).

Future work: also update the Windows installer.

Closes #1014
  • Loading branch information
kr authored and iampogo committed Apr 22, 2017
1 parent 9cf7010 commit 338f54e
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 59 deletions.
7 changes: 3 additions & 4 deletions cmd/corectl/main.go
Expand Up @@ -18,7 +18,6 @@ import (
"chain/core"
"chain/core/accesstoken"
"chain/core/config"
"chain/core/fileutil"
"chain/core/rpc"
"chain/crypto/ed25519"
"chain/env"
Expand All @@ -29,7 +28,7 @@ import (

// config vars
var (
dataDir = env.String("CORED_DATA_DIR", fileutil.DefaultDir())
home = core.HomeDirFromEnvironment()
coreURL = env.String("CORE_URL", "http://localhost:1999")

// build vars; initialized by the linker
Expand Down Expand Up @@ -304,8 +303,8 @@ func mustRPCClient() *rpc.Client {
// Note that this function, unlike maybeUseTLS in cored,
// does not load the cert and key from env vars,
// only from the filesystem.
certFile := filepath.Join(*dataDir, "tls.crt")
keyFile := filepath.Join(*dataDir, "tls.key")
certFile := filepath.Join(home, "tls.crt")
keyFile := filepath.Join(home, "tls.key")
config, err := core.TLSConfig(certFile, keyFile, "")
if err == core.ErrNoTLS {
return &rpc.Client{BaseURL: *coreURL}
Expand Down
9 changes: 4 additions & 5 deletions cmd/cored/main.go
Expand Up @@ -23,7 +23,6 @@ import (
"chain/core"
"chain/core/blocksigner"
"chain/core/config"
"chain/core/fileutil"
"chain/core/generator"
"chain/core/migrate"
"chain/core/rpc"
Expand Down Expand Up @@ -65,7 +64,7 @@ var (
rpsToken = env.Int("RATELIMIT_TOKEN", 0) // reqs/sec
rpsRemoteAddr = env.Int("RATELIMIT_REMOTE_ADDR", 0) // reqs/sec
indexTxs = env.Bool("INDEX_TRANSACTIONS", true)
dataDir = env.String("CORED_DATA_DIR", fileutil.DefaultDir())
home = core.HomeDirFromEnvironment()
bootURL = env.String("BOOTURL", "")

// build vars; initialized by the linker
Expand Down Expand Up @@ -140,7 +139,7 @@ func main() {
chainlog.Fatalkv(ctx, chainlog.KeyError, err)
}

raftDir := filepath.Join(*dataDir, "raft") // TODO(kr): better name for this
raftDir := filepath.Join(home, "raft") // TODO(kr): better name for this
// TODO(tessr): remove tls param once we have tls everywhere
raftDB, err := raft.Start(*listenAddr, raftDir, *bootURL, tlsConfig != nil)
if err != nil {
Expand Down Expand Up @@ -246,8 +245,8 @@ func main() {
// be nil.
func maybeUseTLS(ln net.Listener) (net.Listener, *tls.Config, error) {
config, err := core.TLSConfig(
filepath.Join(*dataDir, "tls.crt"),
filepath.Join(*dataDir, "tls.key"),
filepath.Join(home, "tls.crt"),
filepath.Join(home, "tls.key"),
*rootCAs,
)
if err == core.ErrNoTLS {
Expand Down
17 changes: 17 additions & 0 deletions core/env.go
@@ -0,0 +1,17 @@
package core

import (
"os"
"path/filepath"
)

// HomeDirFromEnvironment returns the directory to use
// for reading config and storing variable data.
// It returns $CHAIN_CORE_HOME,
// or, if that is empty, $HOME/.chaincore.
func HomeDirFromEnvironment() string {
if s := os.Getenv("CHAIN_CORE_HOME"); s != "" {
return s
}
return filepath.Join(os.Getenv("HOME"), ".chaincore")
}
12 changes: 0 additions & 12 deletions core/fileutil/dir.go

This file was deleted.

10 changes: 0 additions & 10 deletions core/fileutil/dir_darwin.go

This file was deleted.

10 changes: 0 additions & 10 deletions core/fileutil/dir_windows.go

This file was deleted.

8 changes: 0 additions & 8 deletions core/fileutil/doc.go

This file was deleted.

4 changes: 2 additions & 2 deletions desktop/mac/ChainCore/AppDelegate.swift
Expand Up @@ -59,10 +59,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, SUUpdaterDelegate {

func openInTerminalApp(_ appname: String) {
let routine = "open_\(appname)"
let param = String(format: "alias corectl='%@'; export DATABASE_URL='%@';",
let param = String(format: "alias corectl='%@'; export CHAIN_CORE_HOME='%@';",
arguments: [
ChainCore.shared.corectlPath.replacingOccurrences(of: " ", with: "\\ "),
ChainCore.shared.databaseURL
ChainCore.shared.homeDir
])

let launcher = ClientLauncher()
Expand Down
13 changes: 9 additions & 4 deletions desktop/mac/ChainCore/ChainCore.swift
Expand Up @@ -15,6 +15,10 @@ class ChainCore: NSObject {
return "postgres://localhost:\(dbPort)/core?sslmode=disable"
}

var homeDir: String {
return NSHomeDirectory() + "/Library/Application Support/Chain Core"
}

var corectlPath: String {
return Bundle.main.path(forResource: "corectl", ofType: nil)!
}
Expand Down Expand Up @@ -127,12 +131,13 @@ class ChainCore: NSObject {
task.launchPath = Bundle.main.path(forResource: "cored", ofType: nil)
task.arguments = []
task.environment = [
"DATABASE_URL": databaseURL,
"LISTEN": ":\(port)",
"LOGFILE": self.logURL.path,
"DATABASE_URL": databaseURL,
"CHAIN_CORE_HOME": homeDir,
"LISTEN": ":\(port)",
"LOGFILE": self.logURL.path,

// FIXME: cored binaries built with bin/build-cored-release have trouble acquiring a default user for Postgres connections. This ensures the current user's login name is always available in the environment.
"USER": NSUserName(),
"USER": NSUserName(),
]
//task.standardOutput = Pipe()
//task.standardError = Pipe()
Expand Down
2 changes: 1 addition & 1 deletion generated/rev/RevId.java
@@ -1,4 +1,4 @@

public final class RevId {
public final String Id = "main/rev2985";
public final String Id = "main/rev2986";
}
2 changes: 1 addition & 1 deletion generated/rev/revid.go
@@ -1,3 +1,3 @@
package rev

const ID string = "main/rev2985"
const ID string = "main/rev2986"
2 changes: 1 addition & 1 deletion generated/rev/revid.js
@@ -1,2 +1,2 @@

export const rev_id = "main/rev2985"
export const rev_id = "main/rev2986"
2 changes: 1 addition & 1 deletion generated/rev/revid.rb
@@ -1,4 +1,4 @@

module Chain::Rev
ID = "main/rev2985".freeze
ID = "main/rev2986".freeze
end

0 comments on commit 338f54e

Please sign in to comment.