@ -35,9 +35,9 @@ var staticZip string
var staticFS fs . FS
var staticFS fs . FS
func init ( ) {
func init ( ) {
flag . StringVar ( & confPath , "c" , util . RelativePath ( "conf.ini" ) , " 配置文件路径 ")
flag . StringVar ( & confPath , "c" , util . RelativePath ( "conf.ini" ) , " Path to the config file. ")
flag . BoolVar ( & isEject , "eject" , false , " 导出内置静态资源 ")
flag . BoolVar ( & isEject , "eject" , false , " Eject all embedded static files. ")
flag . StringVar ( & scriptName , "database-script" , "" , " 运行内置数据库助手脚本 ")
flag . StringVar ( & scriptName , "database-script" , "" , " Name of database util script. ")
flag . Parse ( )
flag . Parse ( )
staticFS = archiver . ArchiveFS {
staticFS = archiver . ArchiveFS {
@ -71,7 +71,7 @@ func main() {
signal . Notify ( sigChan , os . Interrupt , syscall . SIGTERM , syscall . SIGHUP , syscall . SIGQUIT )
signal . Notify ( sigChan , os . Interrupt , syscall . SIGTERM , syscall . SIGHUP , syscall . SIGQUIT )
go func ( ) {
go func ( ) {
sig := <- sigChan
sig := <- sigChan
util . Log ( ) . Info ( " 收到信号 %s, 开始关闭 server ", sig )
util . Log ( ) . Info ( " Signal %s received, shutting down server... ", sig )
ctx := context . Background ( )
ctx := context . Background ( )
if conf . SystemConfig . GracePeriod != 0 {
if conf . SystemConfig . GracePeriod != 0 {
var cancel context . CancelFunc
var cancel context . CancelFunc
@ -81,16 +81,16 @@ func main() {
err := server . Shutdown ( ctx )
err := server . Shutdown ( ctx )
if err != nil {
if err != nil {
util . Log ( ) . Error ( " 关闭 server 错误, %s", err )
util . Log ( ) . Error ( " Failed to shutdown server: %s", err )
}
}
} ( )
} ( )
// 如果启用了SSL
// 如果启用了SSL
if conf . SSLConfig . CertPath != "" {
if conf . SSLConfig . CertPath != "" {
util . Log ( ) . Info ( " 开始监听 %s ", conf . SSLConfig . Listen )
util . Log ( ) . Info ( " Listening to %q ", conf . SSLConfig . Listen )
server . Addr = conf . SSLConfig . Listen
server . Addr = conf . SSLConfig . Listen
if err := server . ListenAndServeTLS ( conf . SSLConfig . CertPath , conf . SSLConfig . KeyPath ) ; err != nil {
if err := server . ListenAndServeTLS ( conf . SSLConfig . CertPath , conf . SSLConfig . KeyPath ) ; err != nil {
util . Log ( ) . Error ( " 无法监听[%s], %s", conf . SSLConfig . Listen , err )
util . Log ( ) . Error ( " Failed to listen to %q: %s", conf . SSLConfig . Listen , err )
return
return
}
}
}
}
@ -100,23 +100,23 @@ func main() {
// delete socket file before listening
// delete socket file before listening
if _ , err := os . Stat ( conf . UnixConfig . Listen ) ; err == nil {
if _ , err := os . Stat ( conf . UnixConfig . Listen ) ; err == nil {
if err = os . Remove ( conf . UnixConfig . Listen ) ; err != nil {
if err = os . Remove ( conf . UnixConfig . Listen ) ; err != nil {
util . Log ( ) . Error ( " 删除 socket 文件错误, %s", err )
util . Log ( ) . Error ( " Failed to delete socket file: %s", err )
return
return
}
}
}
}
api . TrustedPlatform = conf . UnixConfig . ProxyHeader
api . TrustedPlatform = conf . UnixConfig . ProxyHeader
util . Log ( ) . Info ( " 开始监听 %s ", conf . UnixConfig . Listen )
util . Log ( ) . Info ( " Listening to %q ", conf . UnixConfig . Listen )
if err := RunUnix ( server ) ; err != nil {
if err := RunUnix ( server ) ; err != nil {
util . Log ( ) . Error ( " 无法监听[%s], %s", conf . UnixConfig . Listen , err )
util . Log ( ) . Error ( " Failed to listen to %q: %s", conf . UnixConfig . Listen , err )
}
}
return
return
}
}
util . Log ( ) . Info ( " 开始监听 %s ", conf . SystemConfig . Listen )
util . Log ( ) . Info ( " Listening to %q ", conf . SystemConfig . Listen )
server . Addr = conf . SystemConfig . Listen
server . Addr = conf . SystemConfig . Listen
if err := server . ListenAndServe ( ) ; err != nil {
if err := server . ListenAndServe ( ) ; err != nil {
util . Log ( ) . Error ( " 无法监听[%s], %s", conf . SystemConfig . Listen , err )
util . Log ( ) . Error ( " Failed to listen to %q: %s", conf . SystemConfig . Listen , err )
}
}
}
}