mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #1013 in YUNIONIO/onecloud from ~QIUJIAN/onecloud:feature/qj-image-p2p-distribution to release/2.6.0
* commit '4c6f196ec541d1b8c8e2d79ea69c7bd7f9fcf1a6': temp commit minor updates torrent recode
This commit is contained in:
@@ -24,6 +24,10 @@ func InitApp(options *CommonOptions, dbAccess bool) *appsrv.Application {
|
||||
}
|
||||
|
||||
func ServeForever(app *appsrv.Application, options *CommonOptions) {
|
||||
ServeForeverWithCleanup(app, options, nil)
|
||||
}
|
||||
|
||||
func ServeForeverWithCleanup(app *appsrv.Application, options *CommonOptions, onStop func()) {
|
||||
AppDBInit(app)
|
||||
addr := net.JoinHostPort(options.Address, strconv.Itoa(options.Port))
|
||||
proto := "http"
|
||||
@@ -47,8 +51,8 @@ func ServeForever(app *appsrv.Application, options *CommonOptions) {
|
||||
if len(options.SslKeyfile) == 0 {
|
||||
log.Fatalf("Missing ssl-keyfile")
|
||||
}
|
||||
app.ListenAndServeTLS(addr, certfile, options.SslKeyfile)
|
||||
app.ListenAndServeTLSWithCleanup(addr, certfile, options.SslKeyfile, onStop)
|
||||
} else {
|
||||
app.ListenAndServe(addr)
|
||||
app.ListenAndServeWithCleanup(addr, onStop)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,9 @@ func (self *SCronJobManager) Start() {
|
||||
}
|
||||
|
||||
func (self *SCronJobManager) Stop() {
|
||||
close(self.stop)
|
||||
if self.stop != nil {
|
||||
close(self.stop)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SCronJobManager) run() {
|
||||
|
||||
@@ -137,6 +137,13 @@ var (
|
||||
Action: PolicyActionGet,
|
||||
Result: rbacutils.OwnerAllow,
|
||||
},
|
||||
{
|
||||
Service: "image",
|
||||
Resource: "images",
|
||||
Action: PolicyActionPerform,
|
||||
Extra: []string{"update-torrent-status"},
|
||||
Result: rbacutils.GuestAllow,
|
||||
},
|
||||
{
|
||||
Service: "log",
|
||||
Resource: "actions",
|
||||
|
||||
@@ -190,7 +190,7 @@ func queryKey(isAdmin bool, userCred mcclient.TokenCredential, service string, r
|
||||
}
|
||||
|
||||
func (manager *SPolicyManager) Allow(isAdmin bool, userCred mcclient.TokenCredential, service string, resource string, action string, extra ...string) rbacutils.TRbacResult {
|
||||
if manager.cache != nil {
|
||||
if manager.cache != nil && userCred != nil {
|
||||
key := queryKey(isAdmin, userCred, service, resource, action, extra...)
|
||||
val := manager.cache.Get(key)
|
||||
if val != nil {
|
||||
@@ -231,7 +231,12 @@ func (manager *SPolicyManager) allowWithoutCache(isAdmin bool, userCred mcclient
|
||||
log.Warningf("no policies fetched")
|
||||
return rbacutils.Deny
|
||||
}
|
||||
userCredJson := userCred.ToJson()
|
||||
var userCredJson jsonutils.JSONObject
|
||||
if userCred != nil {
|
||||
userCredJson = userCred.ToJson()
|
||||
} else {
|
||||
userCredJson = jsonutils.NewDict()
|
||||
}
|
||||
currentPriv := rbacutils.Deny
|
||||
for _, p := range policies {
|
||||
result := p.Allow(userCredJson, service, resource, action, extra...)
|
||||
|
||||
@@ -1,26 +1,3 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/signalutils"
|
||||
"yunion.io/x/pkg/utils"
|
||||
)
|
||||
|
||||
type SServiceBase struct{}
|
||||
|
||||
func (s *SServiceBase) RegisterQuitSignals(quitHandler signalutils.Trap) {
|
||||
quitSignals := []os.Signal{syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM}
|
||||
signalutils.RegisterSignal(quitHandler, quitSignals...)
|
||||
|
||||
signalutils.StartTrap()
|
||||
}
|
||||
|
||||
func (s *SServiceBase) RegisterSIGUSR1() {
|
||||
// dump goroutine stack
|
||||
signalutils.RegisterSignal(func() {
|
||||
utils.DumpAllGoroutineStack(log.Logger().Out)
|
||||
}, syscall.SIGUSR1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user