-
Notifications
You must be signed in to change notification settings - Fork 25
/
toggle.go
40 lines (32 loc) · 829 Bytes
/
toggle.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 gpaccount handles the logic of the gPanel account server
package gpaccount
import (
"context"
"errors"
"log"
)
func (con *Controller) Start() error {
if con.Status == 1 {
return errors.New("account server is already on")
}
con.Status = 1
go con.Server.ListenAndServe()
log.Printf("gPanel Account %v now serving out of %s on port %d\n", con.Name, con.DocumentRoot, con.Port)
return nil
}
func (con *Controller) Stop(graceful bool) error {
if graceful {
context, cancel := context.WithTimeout(context.Background(), con.GracefulShutdownTimeout)
defer cancel()
err := con.Server.Shutdown(context)
if err == nil {
return nil
}
log.Printf("Graceful shutdown failed attempting forced: %v\n", err)
}
if err := con.Server.Close(); err != nil {
return err
}
con.Status = 0
return nil
}