2016-03-30 16:48:52 -05:00
|
|
|
// Copyright 2016 Tim Shannon. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
2016-03-29 16:43:58 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-04-05 16:59:52 -05:00
|
|
|
"flag"
|
2016-03-29 16:43:58 -05:00
|
|
|
"log"
|
|
|
|
"os"
|
2016-04-05 16:59:52 -05:00
|
|
|
"os/signal"
|
2016-03-29 16:43:58 -05:00
|
|
|
"path/filepath"
|
|
|
|
|
2016-04-19 14:52:55 -05:00
|
|
|
"git.townsourced.com/townsourced/config"
|
2016-03-29 16:43:58 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
//settings
|
|
|
|
var (
|
2016-03-30 16:48:52 -05:00
|
|
|
projectDir = "./projects" // /etc/ironsmith/
|
|
|
|
dataDir = "./data" // /var/ironsmith/
|
2016-04-05 16:59:52 -05:00
|
|
|
address = ":8026"
|
2016-03-29 16:43:58 -05:00
|
|
|
certFile = ""
|
|
|
|
keyFile = ""
|
|
|
|
)
|
|
|
|
|
2016-04-05 16:59:52 -05:00
|
|
|
//flags
|
|
|
|
var (
|
|
|
|
verbose = false
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.BoolVar(&verbose, "v", false, "Verbose prints to stdOut every command and stage as it processes")
|
|
|
|
|
|
|
|
//Capture program shutdown, to make sure everything shuts down nicely
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, os.Interrupt)
|
|
|
|
go func() {
|
|
|
|
for sig := range c {
|
|
|
|
if sig == os.Interrupt {
|
2016-04-06 16:59:24 -05:00
|
|
|
projects.stopAll()
|
2016-04-05 16:59:52 -05:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:43:58 -05:00
|
|
|
func main() {
|
2016-04-05 16:59:52 -05:00
|
|
|
flag.Parse()
|
|
|
|
|
2016-03-29 16:43:58 -05:00
|
|
|
settingPaths := config.StandardFileLocations("ironsmith/settings.json")
|
2016-04-05 16:59:52 -05:00
|
|
|
vlog("IronSmith will use settings files in the following locations (in order of priority):\n")
|
2016-03-29 16:43:58 -05:00
|
|
|
for i := range settingPaths {
|
2016-04-05 16:59:52 -05:00
|
|
|
vlog("\t%s\n", settingPaths[i])
|
2016-03-29 16:43:58 -05:00
|
|
|
}
|
|
|
|
cfg, err := config.LoadOrCreate(settingPaths...)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error loading or creating IronSmith settings file: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-04-05 16:59:52 -05:00
|
|
|
vlog("IronSmith is currently using the file %s for settings.\n", cfg.FileName())
|
2016-03-29 16:43:58 -05:00
|
|
|
|
|
|
|
projectDir = cfg.String("projectDir", projectDir)
|
|
|
|
dataDir = cfg.String("dataDir", dataDir)
|
|
|
|
address = cfg.String("address", address)
|
|
|
|
certFile = cfg.String("certFile", certFile)
|
|
|
|
keyFile = cfg.String("keyFile", keyFile)
|
|
|
|
|
2016-04-05 16:59:52 -05:00
|
|
|
vlog("Project Definition Directory: %s\n", projectDir)
|
|
|
|
vlog("Project Data Directory: %s\n", dataDir)
|
|
|
|
|
2016-03-29 16:43:58 -05:00
|
|
|
//prep dirs
|
2016-03-30 16:48:52 -05:00
|
|
|
err = os.MkdirAll(filepath.Join(projectDir, enabledProjectDir), 0777)
|
2016-03-29 16:43:58 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error Creating project directory at %s: %s", projectDir, err)
|
|
|
|
}
|
|
|
|
|
2016-03-30 16:48:52 -05:00
|
|
|
err = os.MkdirAll(dataDir, 0777)
|
2016-03-29 16:43:58 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error Creating project data directory at %s: %s", dataDir, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = prepTemplateProject()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error Creating project template file: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//load projects
|
2016-03-30 16:48:52 -05:00
|
|
|
err = projects.load()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error loading projects: %s", err)
|
|
|
|
}
|
2016-04-05 16:59:52 -05:00
|
|
|
|
|
|
|
//start web server
|
|
|
|
err = startServer()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error Starting web server: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:43:58 -05:00
|
|
|
}
|