Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/cmd/common.go
1541 views
1
package cmd
2
3
import (
4
"github.com/alist-org/alist/v3/internal/bootstrap/patch/v3_46_0"
5
"os"
6
"path/filepath"
7
"strconv"
8
9
"github.com/alist-org/alist/v3/internal/bootstrap"
10
"github.com/alist-org/alist/v3/internal/bootstrap/data"
11
"github.com/alist-org/alist/v3/internal/db"
12
"github.com/alist-org/alist/v3/pkg/utils"
13
log "github.com/sirupsen/logrus"
14
)
15
16
func Init() {
17
bootstrap.InitConfig()
18
bootstrap.Log()
19
bootstrap.InitDB()
20
21
if v3_46_0.IsLegacyRoleDetected() {
22
utils.Log.Warnf("Detected legacy role format, executing ConvertLegacyRoles patch early...")
23
v3_46_0.ConvertLegacyRoles()
24
}
25
26
data.InitData()
27
bootstrap.InitStreamLimit()
28
bootstrap.InitIndex()
29
bootstrap.InitUpgradePatch()
30
}
31
32
func Release() {
33
db.Close()
34
}
35
36
var pid = -1
37
var pidFile string
38
39
func initDaemon() {
40
ex, err := os.Executable()
41
if err != nil {
42
log.Fatal(err)
43
}
44
exPath := filepath.Dir(ex)
45
_ = os.MkdirAll(filepath.Join(exPath, "daemon"), 0700)
46
pidFile = filepath.Join(exPath, "daemon/pid")
47
if utils.Exists(pidFile) {
48
bytes, err := os.ReadFile(pidFile)
49
if err != nil {
50
log.Fatal("failed to read pid file", err)
51
}
52
id, err := strconv.Atoi(string(bytes))
53
if err != nil {
54
log.Fatal("failed to parse pid data", err)
55
}
56
pid = id
57
}
58
}
59
60