/
server.go
40 lines (33 loc) Β· 929 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package api
import (
"net/http"
"os"
"syscall"
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/acl"
"github.com/photoprism/photoprism/internal/get"
)
// StopServer shuts down the server.
//
// POST /api/v1/server/stop
func StopServer(router *gin.RouterGroup) {
router.POST("/server/stop", func(c *gin.Context) {
s := Auth(c, acl.ResourceConfig, acl.ActionManage)
conf := get.Config()
// Abort if permission was not granted.
if s.Invalid() || conf.Public() || conf.DisableSettings() || conf.DisableRestart() {
AbortForbidden(c)
return
}
process, err := os.FindProcess(os.Getpid())
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, NewResponse(http.StatusInternalServerError, err, ""))
return
} else {
c.JSON(http.StatusOK, conf.Options())
}
if err = process.Signal(syscall.SIGTERM); err != nil {
log.Errorf("server: %s", err)
}
})
}