Add /meta/{up_since,kill}
This commit is contained in:
parent
b153d45f07
commit
92d308879b
|
@ -50,6 +50,8 @@ func Start(conf common.Conf, db *sql.DB) *gin.Engine {
|
|||
// 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))
|
||||
gv1.GET("/meta/kill", Method(v1.MetaKillGET, db, common.PrivilegeAPIMeta))
|
||||
gv1.GET("/meta/up_since", Method(v1.MetaUpSinceGET, db, common.PrivilegeAPIMeta))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
9
app/v1/init.go
Normal file
9
app/v1/init.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upSince = time.Now()
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/osuripple/api/common"
|
||||
)
|
||||
|
@ -17,6 +19,40 @@ func MetaRestartGET(md common.MethodData) (r common.Response) {
|
|||
}
|
||||
r.Code = 200
|
||||
r.Message = "brb"
|
||||
go proc.Signal(syscall.SIGUSR2)
|
||||
go func() {
|
||||
time.Sleep(time.Second)
|
||||
proc.Signal(syscall.SIGUSR2)
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
// MetaKillGET kills the API process. NOTE TO EVERYONE: NEVER. EVER. USE IN PROD.
|
||||
// Mainly created because I couldn't bother to fire up a terminal, do htop and kill the API each time.
|
||||
func MetaKillGET(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
|
||||
}
|
||||
const form = "02/01/2006"
|
||||
r.Code = 200
|
||||
// yes
|
||||
r.Message = fmt.Sprintf("RIP ripple API %s - %s", upSince.Format(form), time.Now().Format(form))
|
||||
go func() {
|
||||
time.Sleep(time.Second)
|
||||
proc.Kill()
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
var upSince time.Time
|
||||
|
||||
// MetaUpSinceGET retrieves the moment the API application was started.
|
||||
// Mainly used to get if the API was restarted.
|
||||
func MetaUpSinceGET(md common.MethodData) common.Response {
|
||||
return common.Response{
|
||||
Code: 200,
|
||||
Data: upSince.UnixNano(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user