All configuration reload-able

release/v1.15
Unknown 2014-03-21 01:48:10 -04:00
parent 369ddf76a8
commit f6596f11c4
13 changed files with 88 additions and 45 deletions

View File

@ -28,6 +28,7 @@ There are some very good products in this category such as [gitlab](http://gitla
- Repository viewer.
- Gravatar support.
- Mail service(register).
- Administration panel.
- Supports MySQL, PostgreSQL and SQLite3(binary release only).
## Installation

View File

@ -16,30 +16,39 @@ import (
"github.com/gogits/gogs/modules/base"
)
var orm *xorm.Engine
var (
orm *xorm.Engine
dbCfg struct {
Type, Host, Name, User, Pwd, Path, SslMode string
}
)
func LoadModelsConfig() {
dbCfg.Type = base.Cfg.MustValue("database", "DB_TYPE")
dbCfg.Host = base.Cfg.MustValue("database", "HOST")
dbCfg.Name = base.Cfg.MustValue("database", "NAME")
dbCfg.User = base.Cfg.MustValue("database", "USER")
dbCfg.Pwd = base.Cfg.MustValue("database", "PASSWD")
dbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db")
dbCfg.SslMode = base.Cfg.MustValue("database", "SSL_MODE")
}
func setEngine() {
dbType := base.Cfg.MustValue("database", "DB_TYPE")
dbHost := base.Cfg.MustValue("database", "HOST")
dbName := base.Cfg.MustValue("database", "NAME")
dbUser := base.Cfg.MustValue("database", "USER")
dbPwd := base.Cfg.MustValue("database", "PASSWD")
dbPath := base.Cfg.MustValue("database", "PATH", "data/gogs.db")
sslMode := base.Cfg.MustValue("database", "SSL_MODE")
var err error
switch dbType {
switch dbCfg.Type {
case "mysql":
orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@%s/%s?charset=utf8",
dbUser, dbPwd, dbHost, dbName))
dbCfg.User, dbCfg.Pwd, dbCfg.Host, dbCfg.Name))
case "postgres":
orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
dbUser, dbPwd, dbName, sslMode))
dbCfg.User, dbCfg.Pwd, dbCfg.Name, dbCfg.SslMode))
case "sqlite3":
os.MkdirAll(path.Dir(dbPath), os.ModePerm)
orm, err = xorm.NewEngine("sqlite3", dbPath)
os.MkdirAll(path.Dir(dbCfg.Path), os.ModePerm)
orm, err = xorm.NewEngine("sqlite3", dbCfg.Path)
default:
fmt.Printf("Unknown database type: %s\n", dbType)
fmt.Printf("Unknown database type: %s\n", dbCfg.Type)
os.Exit(2)
}
if err != nil {
@ -61,7 +70,7 @@ func setEngine() {
orm.ShowSQL = true
}
func init() {
func NewEngine() {
setEngine()
if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
new(Action), new(Access)); err != nil {

View File

@ -13,6 +13,9 @@ import (
)
func init() {
LoadModelsConfig()
NewEngine()
var err error
orm, err = xorm.NewEngine("sqlite3", "./test.db")
if err != nil {

View File

@ -41,10 +41,12 @@ var (
LanguageIgns, Licenses []string
)
func init() {
func LoadRepoConfig() {
LanguageIgns = strings.Split(base.Cfg.MustValue("repository", "LANG_IGNS"), "|")
Licenses = strings.Split(base.Cfg.MustValue("repository", "LICENSES"), "|")
}
func NewRepoContext() {
zip.Verbose = false
// Check if server has basic git setting.

View File

@ -148,7 +148,7 @@ func newRegisterMailService() {
log.Info("Register Mail Service Enabled")
}
func init() {
func NewConfigContext() {
var err error
workDir, err := exeDir()
if err != nil {

View File

@ -40,7 +40,7 @@ func (m Message) Content() string {
var mailQueue chan *Message
func init() {
func NewMailerContext() {
mailQueue = make(chan *Message, base.Cfg.MustInt("mailer", "SEND_BUFFER_LEN", 10))
go processMailQueue()
}

View File

@ -11,12 +11,14 @@ import (
func Dashboard(ctx *middleware.Context) {
ctx.Data["Title"] = "Admin Dashboard"
ctx.Data["PageIsDashboard"] = true
ctx.Data["Stats"] = models.GetStatistic()
ctx.HTML(200, "admin/dashboard")
}
func Users(ctx *middleware.Context) {
ctx.Data["Title"] = "User Management"
ctx.Data["PageIsUsers"] = true
var err error
ctx.Data["Users"], err = models.GetUsers(100, 0)
@ -29,6 +31,8 @@ func Users(ctx *middleware.Context) {
func Repositories(ctx *middleware.Context) {
ctx.Data["Title"] = "Repository Management"
ctx.Data["PageIsRepos"] = true
var err error
ctx.Data["Repos"], err = models.GetRepos(100, 0)
if err != nil {
@ -37,3 +41,9 @@ func Repositories(ctx *middleware.Context) {
}
ctx.HTML(200, "admin/repos")
}
func Config(ctx *middleware.Context) {
ctx.Data["Title"] = "Server Configuration"
ctx.Data["PageIsConfig"] = true
ctx.HTML(200, "admin/config")
}

View File

@ -0,0 +1,17 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div id="gogs-body" class="container" data-page="admin">
{{template "admin/nav" .}}
<div id="gogs-admin-container" class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">
Server Configuration
</div>
<div class="panel-body">
</div>
</div>
</div>
</div>
{{template "base/footer" .}}

View File

@ -1,14 +1,7 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div id="gogs-body" class="container" data-page="admin">
<div id="gogs-user-setting-nav" class="col-md-3">
<ul class="list-group" data-init="tabs">
<li class="list-group-item active"><a href="/admin"><i class="fa fa-tachometer fa-lg"></i> Dashboard</a></li>
<li class="list-group-item"><a href="/admin/users"><i class="fa fa-users fa-lg"></i> Users</a></li>
<li class="list-group-item"><a href="/admin/repos"><i class="fa fa-book fa-lg"></i> Repositories</a></li>
</ul>
</div>
{{template "admin/nav" .}}
<div id="gogs-admin-container" class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">

8
templates/admin/nav.tmpl Normal file
View File

@ -0,0 +1,8 @@
<div id="gogs-user-setting-nav" class="col-md-3">
<ul class="list-group" data-init="tabs">
<li class="list-group-item{{if .PageIsDashboard}} active{{end}}"><a href="/admin"><i class="fa fa-tachometer fa-lg"></i> Dashboard</a></li>
<li class="list-group-item{{if .PageIsUsers}} active{{end}}"><a href="/admin/users"><i class="fa fa-users fa-lg"></i> Users</a></li>
<li class="list-group-item{{if .PageIsRepos}} active{{end}}"><a href="/admin/repos"><i class="fa fa-book fa-lg"></i> Repositories</a></li>
<li class="list-group-item{{if .PageIsConfig}} active{{end}}"><a href="/admin/config"><i class="fa fa-cogs fa-lg"></i> Configuration</a></li>
</ul>
</div>

View File

@ -1,14 +1,7 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div id="gogs-body" class="container" data-page="admin">
<div id="gogs-user-setting-nav" class="col-md-3">
<ul class="list-group" data-init="tabs">
<li class="list-group-item"><a href="/admin"><i class="fa fa-tachometer fa-lg"></i> Dashboard</a></li>
<li class="list-group-item"><a href="/admin/users"><i class="fa fa-users fa-lg"></i> Users</a></li>
<li class="list-group-item active"><a href="/admin/repos"><i class="fa fa-book fa-lg"></i> Repositories</a></li>
</ul>
</div>
{{template "admin/nav" .}}
<div id="gogs-admin-container" class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">

View File

@ -1,14 +1,7 @@
{{template "base/head" .}}
{{template "base/navbar" .}}
<div id="gogs-body" class="container" data-page="admin">
<div id="gogs-user-setting-nav" class="col-md-3">
<ul class="list-group" data-init="tabs">
<li class="list-group-item"><a href="/admin"><i class="fa fa-tachometer fa-lg"></i> Dashboard</a></li>
<li class="list-group-item active"><a href="/admin/users"><i class="fa fa-users fa-lg"></i> Users</a></li>
<li class="list-group-item"><a href="/admin/repos"><i class="fa fa-book fa-lg"></i> Repositories</a></li>
</ul>
</div>
{{template "admin/nav" .}}
<div id="gogs-admin-container" class="col-md-9">
<div class="panel panel-default">
<div class="panel-heading">

20
web.go
View File

@ -16,9 +16,11 @@ import (
"github.com/gogits/binding"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/routers"
"github.com/gogits/gogs/routers/admin"
@ -36,6 +38,16 @@ gogs web`,
Flags: []cli.Flag{},
}
// globalInit is for global configuration reload-able.
func globalInit() {
base.NewConfigContext()
mailer.NewMailerContext()
models.LoadModelsConfig()
models.LoadRepoConfig()
models.NewRepoContext()
models.NewEngine()
}
// Check run mode(Default of martini is Dev).
func checkRunMode() {
switch base.Cfg.MustValue("", "RUN_MODE") {
@ -59,6 +71,7 @@ func newMartini() *martini.ClassicMartini {
}
func runWeb(*cli.Context) {
globalInit()
base.NewServices()
checkRunMode()
log.Info("%s %s", base.AppName, base.AppVer)
@ -101,9 +114,10 @@ func runWeb(*cli.Context) {
m.Get("/help", routers.Help)
adminReq := middleware.AdminRequire()
m.Any("/admin", reqSignIn, adminReq, admin.Dashboard)
m.Any("/admin/users", reqSignIn, adminReq, admin.Users)
m.Any("/admin/repos", reqSignIn, adminReq, admin.Repositories)
m.Get("/admin", reqSignIn, adminReq, admin.Dashboard)
m.Get("/admin/users", reqSignIn, adminReq, admin.Users)
m.Get("/admin/repos", reqSignIn, adminReq, admin.Repositories)
m.Get("/admin/config", reqSignIn, adminReq, admin.Config)
m.Post("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.SettingPost)
m.Get("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.Setting)