alist/cmd/common.go

51 lines
977 B
Go
Raw Permalink Normal View History

2022-08-07 05:09:59 +00:00
package cmd
import (
2022-11-11 10:42:06 +00:00
"os"
"path/filepath"
"strconv"
2022-08-07 05:09:59 +00:00
"github.com/alist-org/alist/v3/internal/bootstrap"
"github.com/alist-org/alist/v3/internal/bootstrap/data"
2023-09-05 05:04:27 +00:00
"github.com/alist-org/alist/v3/internal/db"
2022-11-11 10:42:06 +00:00
"github.com/alist-org/alist/v3/pkg/utils"
log "github.com/sirupsen/logrus"
2022-08-07 05:09:59 +00:00
)
func Init() {
bootstrap.InitConfig()
bootstrap.Log()
bootstrap.InitDB()
data.InitData()
bootstrap.InitIndex()
bootstrap.InitUpgradePatch()
2022-08-07 05:09:59 +00:00
}
2022-11-11 10:42:06 +00:00
2023-09-05 05:04:27 +00:00
func Release() {
db.Close()
}
2022-11-11 10:42:06 +00:00
var pid = -1
var pidFile string
func initDaemon() {
ex, err := os.Executable()
if err != nil {
log.Fatal(err)
}
exPath := filepath.Dir(ex)
_ = os.MkdirAll(filepath.Join(exPath, "daemon"), 0700)
pidFile = filepath.Join(exPath, "daemon/pid")
if utils.Exists(pidFile) {
bytes, err := os.ReadFile(pidFile)
if err != nil {
log.Fatal("failed to read pid file", err)
}
id, err := strconv.Atoi(string(bytes))
if err != nil {
log.Fatal("failed to parse pid data", err)
}
pid = id
}
}