@ -14,6 +14,7 @@ import (
"github.com/Unknwon/com"
"github.com/Unknwon/goconfig"
qlog "github.com/qiniu/log"
"github.com/gogits/cache"
"github.com/gogits/session"
@ -105,16 +106,14 @@ func newLogService() {
LogMode = Cfg . MustValue ( "log" , "MODE" , "console" )
modeSec := "log." + LogMode
if _ , err := Cfg . GetSection ( modeSec ) ; err != nil {
fmt . Printf ( "Unknown log mode: %s\n" , LogMode )
os . Exit ( 2 )
qlog . Fatalf ( "Unknown log mode: %s\n" , LogMode )
}
// Log level.
levelName := Cfg . MustValue ( "log." + LogMode , "LEVEL" , "Trace" )
level , ok := logLevels [ levelName ]
if ! ok {
fmt . Printf ( "Unknown log level: %s\n" , levelName )
os . Exit ( 2 )
qlog . Fatalf ( "Unknown log level: %s\n" , levelName )
}
// Generate log configuration.
@ -151,6 +150,7 @@ func newLogService() {
Cfg . MustValue ( modeSec , "CONN" ) )
}
log . Info ( "%s %s" , AppName , AppVer )
log . NewLogger ( Cfg . MustInt64 ( "log" , "BUFFER_LEN" , 10000 ) , LogMode , LogConfig )
log . Info ( "Log Mode: %s(%s)" , strings . Title ( LogMode ) , levelName )
}
@ -164,16 +164,14 @@ func newCacheService() {
case "redis" , "memcache" :
CacheConfig = fmt . Sprintf ( ` { "conn":"%s"} ` , Cfg . MustValue ( "cache" , "HOST" ) )
default :
fmt . Printf ( "Unknown cache adapter: %s\n" , CacheAdapter )
os . Exit ( 2 )
qlog . Fatalf ( "Unknown cache adapter: %s\n" , CacheAdapter )
}
var err error
Cache , err = cache . NewCache ( CacheAdapter , CacheConfig )
if err != nil {
fmt . Print f( "Init cache system failed, adapter: %s, config: %s, %v\n" ,
qlog . Fatal f( "Init cache system failed, adapter: %s, config: %s, %v\n" ,
CacheAdapter , CacheConfig , err )
os . Exit ( 2 )
}
log . Info ( "Cache Service Enabled" )
@ -199,9 +197,8 @@ func newSessionService() {
var err error
SessionManager , err = session . NewManager ( SessionProvider , * SessionConfig )
if err != nil {
fmt . Print f( "Init session system failed, provider: %s, %v\n" ,
qlog . Fatal f( "Init session system failed, provider: %s, %v\n" ,
SessionProvider , err )
os . Exit ( 2 )
}
log . Info ( "Session Service Enabled" )
@ -246,23 +243,20 @@ func NewConfigContext() {
//var err error
workDir , err := ExecDir ( )
if err != nil {
fmt . Printf ( "Fail to get work directory: %s\n" , err )
os . Exit ( 2 )
qlog . Fatalf ( "Fail to get work directory: %s\n" , err )
}
cfgPath := filepath . Join ( workDir , "conf/app.ini" )
Cfg , err = goconfig . LoadConfigFile ( cfgPath )
if err != nil {
fmt . Printf ( "Cannot load config file(%s): %v\n" , cfgPath , err )
os . Exit ( 2 )
qlog . Fatalf ( "Cannot load config file(%s): %v\n" , cfgPath , err )
}
Cfg . BlockMode = false
cfgPath = filepath . Join ( workDir , "custom/conf/app.ini" )
if com . IsFile ( cfgPath ) {
if err = Cfg . AppendFiles ( cfgPath ) ; err != nil {
fmt . Printf ( "Cannot load config file(%s): %v\n" , cfgPath , err )
os . Exit ( 2 )
qlog . Fatalf ( "Cannot load config file(%s): %v\n" , cfgPath , err )
}
}
@ -281,8 +275,7 @@ func NewConfigContext() {
}
// Does not check run user when the install lock is off.
if InstallLock && RunUser != curUser {
fmt . Printf ( "Expect user(%s) but current user is: %s\n" , RunUser , curUser )
os . Exit ( 2 )
qlog . Fatalf ( "Expect user(%s) but current user is: %s\n" , RunUser , curUser )
}
LogInRememberDays = Cfg . MustInt ( "security" , "LOGIN_REMEMBER_DAYS" )
@ -294,13 +287,11 @@ func NewConfigContext() {
// Determine and create root git reposiroty path.
homeDir , err := com . HomeDir ( )
if err != nil {
fmt . Printf ( "Fail to get home directory): %v\n" , err )
os . Exit ( 2 )
qlog . Fatalf ( "Fail to get home directory): %v\n" , err )
}
RepoRootPath = Cfg . MustValue ( "repository" , "ROOT" , filepath . Join ( homeDir , "git/g ogs-repositories" ) )
RepoRootPath = Cfg . MustValue ( "repository" , "ROOT" , filepath . Join ( homeDir , "gogs-repositories" ) )
if err = os . MkdirAll ( RepoRootPath , os . ModePerm ) ; err != nil {
fmt . Printf ( "Fail to create RepoRootPath(%s): %v\n" , RepoRootPath , err )
os . Exit ( 2 )
qlog . Fatalf ( "Fail to create RepoRootPath(%s): %v\n" , RepoRootPath , err )
}
}