Graceful restart!
This commit is contained in:
14
app/start.go
14
app/start.go
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// Start begins taking HTTP connections.
|
||||
func Start(conf common.Conf, db *sql.DB) {
|
||||
func Start(conf common.Conf, db *sql.DB) *gin.Engine {
|
||||
r := gin.Default()
|
||||
r.Use(gzip.Gzip(gzip.DefaultCompression), ErrorHandler())
|
||||
|
||||
@@ -38,12 +38,20 @@ func Start(conf common.Conf, db *sql.DB) {
|
||||
// ReadConfidential privilege required
|
||||
gv1.GET("/friends", Method(v1.FriendsGET, db, common.PrivilegeReadConfidential))
|
||||
gv1.GET("/friends/with/:id", Method(v1.FriendsWithGET, db, common.PrivilegeReadConfidential))
|
||||
|
||||
// M E T A
|
||||
// E T "wow thats so meta"
|
||||
// T E -- the one who said "wow that's so meta"
|
||||
// A T E M
|
||||
gv1.GET("/meta/restart", Method(v1.MetaRestartGET, db, common.PrivilegeAPIMeta))
|
||||
}
|
||||
}
|
||||
|
||||
r.NoRoute(v1.Handle404)
|
||||
if conf.Unix {
|
||||
|
||||
return r
|
||||
/*if conf.Unix {
|
||||
panic(r.RunUnix(conf.ListenTo))
|
||||
}
|
||||
panic(r.Run(conf.ListenTo))
|
||||
panic(r.Run(conf.ListenTo))*/
|
||||
}
|
||||
|
22
app/v1/meta.go
Normal file
22
app/v1/meta.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/osuripple/api/common"
|
||||
)
|
||||
|
||||
// MetaRestartGET restarts the API with Zero Downtime™.
|
||||
func MetaRestartGET(md common.MethodData) (r common.Response) {
|
||||
proc, err := os.FindProcess(syscall.Getpid())
|
||||
if err != nil {
|
||||
r.Code = 500
|
||||
r.Message = "couldn't find process. what the fuck?"
|
||||
return
|
||||
}
|
||||
r.Code = 200
|
||||
r.Message = "brb"
|
||||
go proc.Signal(syscall.SIGUSR2)
|
||||
return
|
||||
}
|
@@ -16,6 +16,7 @@ type privilegesData struct {
|
||||
PrivilegeManageRoles bool `json:"manage_roles"`
|
||||
PrivilegeManageAPIKeys bool `json:"manage_api_keys"`
|
||||
PrivilegeBlog bool `json:"blog"`
|
||||
PrivilegeAPIMeta bool `json:"api_meta"`
|
||||
}
|
||||
|
||||
// PrivilegesGET returns an explaination for the privileges, telling the client what they can do with this token.
|
||||
@@ -34,6 +35,7 @@ func PrivilegesGET(md common.MethodData) (r common.Response) {
|
||||
PrivilegeManageRoles: md.User.Privileges.HasPrivilegeManageRoles(),
|
||||
PrivilegeManageAPIKeys: md.User.Privileges.HasPrivilegeManageAPIKeys(),
|
||||
PrivilegeBlog: md.User.Privileges.HasPrivilegeBlog(),
|
||||
PrivilegeAPIMeta: md.User.Privileges.HasPrivilegeAPIMeta(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user