summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author无闻 <u@gogs.io>2015-02-08 20:22:02 -0500
committer无闻 <u@gogs.io>2015-02-08 20:22:02 -0500
commitcd0ee35b3f887cc4ab6ba16cc2d955bfae607678 (patch)
treebbe4ad9e924700d35833daf4f681a568dad278f5
parent3a44143b81aa050f53d5e0e2c87d4a84345cd94e (diff)
parent1ab09e4f1b27789121dfba9a6c6e4aa0011ab215 (diff)
downloadgitea-cd0ee35b3f887cc4ab6ba16cc2d955bfae607678.tar.gz
gitea-cd0ee35b3f887cc4ab6ba16cc2d955bfae607678.zip
Merge pull request #905 from phsmit/conf_on_cli
Add option to provide configuration file on command line
-rw-r--r--cmd/dump.go4
-rw-r--r--cmd/serve.go7
-rw-r--r--cmd/update.go8
-rw-r--r--cmd/web.go4
-rw-r--r--models/publickey.go4
-rw-r--r--models/repo.go4
-rw-r--r--modules/setting/setting.go14
-rw-r--r--routers/install.go5
8 files changed, 37 insertions, 13 deletions
diff --git a/cmd/dump.go b/cmd/dump.go
index 3e1ccdb8a3..57f1113ea3 100644
--- a/cmd/dump.go
+++ b/cmd/dump.go
@@ -26,10 +26,14 @@ It can be used for backup and capture Gogs server image to send to maintainer`,
Action: runDump,
Flags: []cli.Flag{
cli.BoolFlag{"verbose, v", "show process details", ""},
+ cli.StringFlag{"config, c", "custom/conf/app.ini", "Configuration file", ""},
},
}
func runDump(ctx *cli.Context) {
+ if ctx.IsSet("config") {
+ setting.CustomConf = ctx.String("config")
+ }
setting.NewConfigContext()
models.LoadModelsConfig()
models.SetEngine()
diff --git a/cmd/serve.go b/cmd/serve.go
index 1f5d944d4f..af18e05c1e 100644
--- a/cmd/serve.go
+++ b/cmd/serve.go
@@ -27,7 +27,9 @@ var CmdServ = cli.Command{
Usage: "This command should only be called by SSH shell",
Description: `Serv provide access auth for repositories`,
Action: runServ,
- Flags: []cli.Flag{},
+ Flags: []cli.Flag{
+ cli.StringFlag{"config, c", "custom/conf/app.ini", "Configuration file", ""},
+ },
}
func setup(logPath string) {
@@ -83,6 +85,9 @@ func In(b string, sl map[string]models.AccessType) bool {
}
func runServ(k *cli.Context) {
+ if k.IsSet("config") {
+ setting.CustomConf = k.String("config")
+ }
setup("serv.log")
keys := strings.Split(os.Args[2], "-")
diff --git a/cmd/update.go b/cmd/update.go
index cc55693e2b..2ea7e942dd 100644
--- a/cmd/update.go
+++ b/cmd/update.go
@@ -11,6 +11,7 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/log"
+ "github.com/gogits/gogs/modules/setting"
)
var CmdUpdate = cli.Command{
@@ -18,10 +19,15 @@ var CmdUpdate = cli.Command{
Usage: "This command should only be called by SSH shell",
Description: `Update get pushed info and insert into database`,
Action: runUpdate,
- Flags: []cli.Flag{},
+ Flags: []cli.Flag{
+ cli.StringFlag{"config, c", "custom/conf/app.ini", "Configuration file", ""},
+ },
}
func runUpdate(c *cli.Context) {
+ if c.IsSet("config") {
+ setting.CustomConf = c.String("config")
+ }
cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
if cmd == "" {
return
diff --git a/cmd/web.go b/cmd/web.go
index 55b6bf0874..ceb2134447 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -55,6 +55,7 @@ and it takes care of all the other things for you`,
Action: runWeb,
Flags: []cli.Flag{
cli.StringFlag{"port, p", "3000", "Temporary port number to prevent conflict", ""},
+ cli.StringFlag{"config, c", "custom/conf/app.ini", "Configuration file", ""},
},
}
@@ -165,6 +166,9 @@ func newMacaron() *macaron.Macaron {
}
func runWeb(ctx *cli.Context) {
+ if ctx.IsSet("config") {
+ setting.CustomConf = ctx.String("config")
+ }
routers.GlobalInit()
checkVersion()
diff --git a/models/publickey.go b/models/publickey.go
index 67ab4242f2..893ff5c96a 100644
--- a/models/publickey.go
+++ b/models/publickey.go
@@ -29,7 +29,7 @@ import (
const (
// "### autogenerated by gitgos, DO NOT EDIT\n"
- _TPL_PUBLICK_KEY = `command="%s serv key-%d",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s` + "\n"
+ _TPL_PUBLICK_KEY = `command="%s serv --config=%s key-%d",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s` + "\n"
)
var (
@@ -98,7 +98,7 @@ func (k *PublicKey) OmitEmail() string {
// GetAuthorizedString generates and returns formatted public key string for authorized_keys file.
func (key *PublicKey) GetAuthorizedString() string {
- return fmt.Sprintf(_TPL_PUBLICK_KEY, appPath, key.Id, key.Content)
+ return fmt.Sprintf(_TPL_PUBLICK_KEY, appPath, setting.CustomConf, key.Id, key.Content)
}
var (
diff --git a/models/repo.go b/models/repo.go
index 3e07adba63..5a40c5b987 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -30,7 +30,7 @@ import (
)
const (
- TPL_UPDATE_HOOK = "#!/usr/bin/env %s\n%s update $1 $2 $3\n"
+ TPL_UPDATE_HOOK = "#!/usr/bin/env %s\n%s update --config=%s $1 $2 $3\n"
)
var (
@@ -424,7 +424,7 @@ func initRepository(f string, u *User, repo *Repository, initReadme bool, repoLa
// hook/post-update
if err := createHookUpdate(filepath.Join(repoPath, "hooks", "update"),
- fmt.Sprintf(TPL_UPDATE_HOOK, setting.ScriptType, "\""+appPath+"\"")); err != nil {
+ fmt.Sprintf(TPL_UPDATE_HOOK, setting.ScriptType, "\""+appPath+"\"", setting.CustomConf)); err != nil {
return err
}
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 6a205921b8..f5212a2867 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -125,6 +125,7 @@ var (
Cfg *ini.File
ConfRootPath string
CustomPath string // Custom directory path.
+ CustomConf string
ProdMode bool
RunUser string
IsWindows bool
@@ -173,13 +174,16 @@ func NewConfigContext() {
CustomPath = path.Join(workDir, "custom")
}
- cfgPath := path.Join(CustomPath, "conf/app.ini")
- if com.IsFile(cfgPath) {
- if err = Cfg.Append(cfgPath); err != nil {
- log.Fatal(4, "Fail to load custom 'conf/app.ini': %v", err)
+ if len(CustomConf) == 0 {
+ CustomConf = path.Join(CustomPath, "conf/app.ini")
+ }
+
+ if com.IsFile(CustomConf) {
+ if err = Cfg.Append(CustomConf); err != nil {
+ log.Fatal(4, "Fail to load custom conf '%s': %v", CustomConf, err)
}
} else {
- log.Warn("No custom 'conf/app.ini' found, ignore this if you're running first time")
+ log.Warn("Custom config (%s) not found, ignore this if you're running first time", CustomConf)
}
Cfg.NameMapper = ini.AllCapsUnderscore
diff --git a/routers/install.go b/routers/install.go
index 9c3f134d45..a3583a1a98 100644
--- a/routers/install.go
+++ b/routers/install.go
@@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"path"
+ "path/filepath"
"strings"
"github.com/Unknwon/com"
@@ -221,8 +222,8 @@ func InstallPost(ctx *middleware.Context, form auth.InstallForm) {
cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")
cfg.Section("security").Key("SECRET_KEY").SetValue(base.GetRandomString(15))
- os.MkdirAll("custom/conf", os.ModePerm)
- if err := cfg.SaveTo(path.Join(setting.CustomPath, "conf/app.ini")); err != nil {
+ os.MkdirAll(filepath.Dir(setting.CustomConf), os.ModePerm)
+ if err := cfg.SaveTo(setting.CustomConf); err != nil {
ctx.RenderWithErr(ctx.Tr("install.save_config_failed", err), INSTALL, &form)
return
}