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