run on prod env

This commit is contained in:
Dan Ballard 2015-05-14 07:20:30 -07:00
parent b45c66c94e
commit fd673de247
3 changed files with 30 additions and 4 deletions

View File

@ -30,6 +30,8 @@ goose up
## Build and run ## Build and run
go build go build
edit transmet.conf to point to correct location
sudo cp transmet.conf /etc/init sudo cp transmet.conf /etc/init
sudo service transmet start sudo service transmet start

15
main.go
View File

@ -11,6 +11,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"flag"
) )
const VERSION = "0.1" const VERSION = "0.1"
@ -38,10 +39,10 @@ var (
templates = map[string]*template.Template{} templates = map[string]*template.Template{}
) )
func loadConfig() { func loadConfig(env string) {
file, err := os.Open("config/local.json") file, err := os.Open("config/" + env + ".json")
if err != nil { if err != nil {
fmt.Println("Error: cannot open config file") fmt.Println("Error: cannot open config file: config/" + env + ".json")
os.Exit(-1) os.Exit(-1)
} }
decoder := json.NewDecoder(file) decoder := json.NewDecoder(file)
@ -84,8 +85,14 @@ func initTemplates() {
func main() { func main() {
fmt.Println("transmet ", VERSION) fmt.Println("transmet ", VERSION)
envFlag := flag.String("env", "local", "load config/{env}.json")
flag.Parse()
fmt.Println("Loading...") fmt.Println("Loading...")
loadConfig()
loadConfig(*envFlag)
dbConnect() dbConnect()
initTemplates() initTemplates()
init_route_handlers() init_route_handlers()

17
transmet.conf Normal file
View File

@ -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