mirror of
https://github.com/KaySar12/NextZen-UserService.git
synced 2025-03-15 23:25:35 +07:00
create default config if it does not already exist (#39)
This commit is contained in:
parent
f626b02570
commit
9a986a60ad
@ -1,6 +1,5 @@
|
||||
[Unit]
|
||||
After=casaos-message-bus.service
|
||||
ConditionFileNotEmpty=/etc/casaos/user-service.conf
|
||||
Description=CasaOS User Service
|
||||
|
||||
[Service]
|
||||
|
5
main.go
5
main.go
@ -40,6 +40,9 @@ var (
|
||||
|
||||
//go:embed api/user-service/openapi.yaml
|
||||
_docYAML string
|
||||
|
||||
//go:embed build/sysroot/etc/casaos/user-service.conf.sample
|
||||
_confSample string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -59,7 +62,7 @@ func init() {
|
||||
println("git commit:", commit)
|
||||
println("build date:", date)
|
||||
|
||||
config.InitSetup(*configFlag)
|
||||
config.InitSetup(*configFlag, _confSample)
|
||||
|
||||
logger.LogInit(config.AppInfo.LogPath, config.AppInfo.LogSaveName, config.AppInfo.LogFileExt)
|
||||
|
||||
|
@ -5,35 +5,56 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/constants"
|
||||
"github.com/IceWhaleTech/CasaOS-UserService/model"
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
// models with default values
|
||||
|
||||
var CommonInfo = &model.CommonModel{
|
||||
RuntimePath: "/var/run/casaos",
|
||||
}
|
||||
var (
|
||||
CommonInfo = &model.CommonModel{
|
||||
RuntimePath: constants.DefaultRuntimePath,
|
||||
}
|
||||
|
||||
var AppInfo = &model.APPModel{
|
||||
DBPath: "/var/lib/casaos",
|
||||
UserDataPath: "/var/lib/casaos",
|
||||
LogPath: "/var/log/casaos",
|
||||
LogSaveName: "user",
|
||||
LogFileExt: "log",
|
||||
}
|
||||
AppInfo = &model.APPModel{
|
||||
DBPath: constants.DefaultDataPath,
|
||||
UserDataPath: constants.DefaultDataPath,
|
||||
LogPath: constants.DefaultLogPath,
|
||||
LogSaveName: "user",
|
||||
LogFileExt: "log",
|
||||
}
|
||||
|
||||
var Cfg *ini.File
|
||||
Cfg *ini.File
|
||||
ConfigFilePath string
|
||||
)
|
||||
|
||||
func InitSetup(config string) {
|
||||
configFilePath := UserServiceConfigFilePath
|
||||
func InitSetup(config string, sample string) {
|
||||
ConfigFilePath = UserServiceConfigFilePath
|
||||
if len(config) > 0 {
|
||||
configFilePath = config
|
||||
ConfigFilePath = config
|
||||
}
|
||||
|
||||
// create default config file if not exist
|
||||
if _, err := os.Stat(ConfigFilePath); os.IsNotExist(err) {
|
||||
fmt.Println("config file not exist, create it")
|
||||
// create config file
|
||||
file, err := os.Create(ConfigFilePath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// write default config
|
||||
_, err = file.WriteString(sample)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
Cfg, err = ini.Load(configFilePath)
|
||||
Cfg, err = ini.Load(ConfigFilePath)
|
||||
if err != nil {
|
||||
fmt.Printf("Fail to read file: %v", err)
|
||||
os.Exit(1)
|
||||
|
Loading…
Reference in New Issue
Block a user