1
1
mirror of https://github.com/go-gitea/gitea synced 2024-10-31 23:34:25 +00:00

All configuration reload-able

This commit is contained in:
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. - Repository viewer.
- Gravatar support. - Gravatar support.
- Mail service(register). - Mail service(register).
- Administration panel.
- Supports MySQL, PostgreSQL and SQLite3(binary release only). - Supports MySQL, PostgreSQL and SQLite3(binary release only).
## Installation ## Installation

View File

@ -16,30 +16,39 @@ import (
"github.com/gogits/gogs/modules/base" "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() { 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 var err error
switch dbType { switch dbCfg.Type {
case "mysql": case "mysql":
orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@%s/%s?charset=utf8", 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": case "postgres":
orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", 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": case "sqlite3":
os.MkdirAll(path.Dir(dbPath), os.ModePerm) os.MkdirAll(path.Dir(dbCfg.Path), os.ModePerm)
orm, err = xorm.NewEngine("sqlite3", dbPath) orm, err = xorm.NewEngine("sqlite3", dbCfg.Path)
default: default:
fmt.Printf("Unknown database type: %s\n", dbType) fmt.Printf("Unknown database type: %s\n", dbCfg.Type)
os.Exit(2) os.Exit(2)
} }
if err != nil { if err != nil {
@ -61,7 +70,7 @@ func setEngine() {
orm.ShowSQL = true orm.ShowSQL = true
} }
func init() { func NewEngine() {
setEngine() setEngine()
if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch), if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
new(Action), new(Access)); err != nil { new(Action), new(Access)); err != nil {

View File

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

View File

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

View File

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

View File

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

View File

@ -11,12 +11,14 @@ import (
func Dashboard(ctx *middleware.Context) { func Dashboard(ctx *middleware.Context) {
ctx.Data["Title"] = "Admin Dashboard" ctx.Data["Title"] = "Admin Dashboard"
ctx.Data["PageIsDashboard"] = true
ctx.Data["Stats"] = models.GetStatistic() ctx.Data["Stats"] = models.GetStatistic()
ctx.HTML(200, "admin/dashboard") ctx.HTML(200, "admin/dashboard")
} }
func Users(ctx *middleware.Context) { func Users(ctx *middleware.Context) {
ctx.Data["Title"] = "User Management" ctx.Data["Title"] = "User Management"
ctx.Data["PageIsUsers"] = true
var err error var err error
ctx.Data["Users"], err = models.GetUsers(100, 0) ctx.Data["Users"], err = models.GetUsers(100, 0)
@ -29,6 +31,8 @@ func Users(ctx *middleware.Context) {
func Repositories(ctx *middleware.Context) { func Repositories(ctx *middleware.Context) {
ctx.Data["Title"] = "Repository Management" ctx.Data["Title"] = "Repository Management"
ctx.Data["PageIsRepos"] = true
var err error var err error
ctx.Data["Repos"], err = models.GetRepos(100, 0) ctx.Data["Repos"], err = models.GetRepos(100, 0)
if err != nil { if err != nil {
@ -37,3 +41,9 @@ func Repositories(ctx *middleware.Context) {
} }
ctx.HTML(200, "admin/repos") 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/head" .}}
{{template "base/navbar" .}} {{template "base/navbar" .}}
<div id="gogs-body" class="container" data-page="admin"> <div id="gogs-body" class="container" data-page="admin">
<div id="gogs-user-setting-nav" class="col-md-3"> {{template "admin/nav" .}}
<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>
<div id="gogs-admin-container" class="col-md-9"> <div id="gogs-admin-container" class="col-md-9">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <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/head" .}}
{{template "base/navbar" .}} {{template "base/navbar" .}}
<div id="gogs-body" class="container" data-page="admin"> <div id="gogs-body" class="container" data-page="admin">
<div id="gogs-user-setting-nav" class="col-md-3"> {{template "admin/nav" .}}
<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>
<div id="gogs-admin-container" class="col-md-9"> <div id="gogs-admin-container" class="col-md-9">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">

View File

@ -1,14 +1,7 @@
{{template "base/head" .}} {{template "base/head" .}}
{{template "base/navbar" .}} {{template "base/navbar" .}}
<div id="gogs-body" class="container" data-page="admin"> <div id="gogs-body" class="container" data-page="admin">
<div id="gogs-user-setting-nav" class="col-md-3"> {{template "admin/nav" .}}
<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>
<div id="gogs-admin-container" class="col-md-9"> <div id="gogs-admin-container" class="col-md-9">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">

20
web.go
View File

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