From fd673de24768eb0a2fa524fd176db974b874bbd3 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Thu, 14 May 2015 07:20:30 -0700 Subject: [PATCH] run on prod env --- README.md | 2 ++ main.go | 15 +++++++++++---- transmet.conf | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 transmet.conf diff --git a/README.md b/README.md index f9f782b..aa0399a 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ goose up ## Build and run go build +edit transmet.conf to point to correct location + sudo cp transmet.conf /etc/init sudo service transmet start diff --git a/main.go b/main.go index 7a11f9e..7c8e1fd 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "os" "path/filepath" "regexp" + "flag" ) const VERSION = "0.1" @@ -38,10 +39,10 @@ var ( templates = map[string]*template.Template{} ) -func loadConfig() { - file, err := os.Open("config/local.json") +func loadConfig(env string) { + file, err := os.Open("config/" + env + ".json") if err != nil { - fmt.Println("Error: cannot open config file") + fmt.Println("Error: cannot open config file: config/" + env + ".json") os.Exit(-1) } decoder := json.NewDecoder(file) @@ -84,8 +85,14 @@ func initTemplates() { func main() { fmt.Println("transmet ", VERSION) + + envFlag := flag.String("env", "local", "load config/{env}.json") + flag.Parse() + + fmt.Println("Loading...") - loadConfig() + + loadConfig(*envFlag) dbConnect() initTemplates() init_route_handlers() diff --git a/transmet.conf b/transmet.conf new file mode 100644 index 0000000..d124ddb --- /dev/null +++ b/transmet.conf @@ -0,0 +1,17 @@ +# transmet: link storage server +# +# upstart init script + +description "transmet link storage" +author "Dan Ballard" + +start on (net-device-up + and local-filesystems + and runlevel [2345]) +stop on (runlevel [016]) + +chdir /opt/transmet + +respawn + +exec transmet --env prod