diff --git a/.goreleaser.debug.yaml b/.goreleaser.debug.yaml index bc1ddfa..8d47134 100644 --- a/.goreleaser.debug.yaml +++ b/.goreleaser.debug.yaml @@ -112,24 +112,22 @@ builds: goarm: - "7" archives: - - name_template: "{{ .Os }}-{{ .Arch }}-{{ .ProjectName }}-v{{ .Version }}" + - name_template: >- + {{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }} id: casaos-message-bus builds: - casaos-message-bus-amd64 - casaos-message-bus-arm64 - casaos-message-bus-arm-7 - replacements: - arm: arm-7 files: - build/**/* - - name_template: "{{ .Os }}-{{ .Arch }}-{{ .ProjectName }}-migration-tool-v{{ .Version }}" + - name_template: >- + {{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-migration-tool-v{{ .Version }} id: casaos-message-bus-migration-tool builds: - casaos-message-bus-migration-tool-amd64 - casaos-message-bus-migration-tool-arm64 - casaos-message-bus-migration-tool-arm-7 - replacements: - arm: arm-7 files: - build/sysroot/etc/**/* checksum: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 78cceab..4a65ee5 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -142,24 +142,22 @@ builds: goarm: - "7" archives: - - name_template: "{{ .Os }}-{{ .Arch }}-{{ .ProjectName }}-v{{ .Version }}" + - name_template: >- + {{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }} id: casaos-message-bus builds: - casaos-message-bus-amd64 - casaos-message-bus-arm64 - casaos-message-bus-arm-7 - replacements: - arm: arm-7 files: - build/**/* - - name_template: "{{ .Os }}-{{ .Arch }}-{{ .ProjectName }}-migration-tool-v{{ .Version }}" + - name_template: >- + {{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-migration-tool-v{{ .Version }} id: casaos-message-bus-migration-tool builds: - casaos-message-bus-migration-tool-amd64 - casaos-message-bus-migration-tool-arm64 - casaos-message-bus-migration-tool-arm-7 - replacements: - arm: arm-7 files: - build/sysroot/etc/**/* checksum: diff --git a/build/sysroot/usr/lib/systemd/system/casaos-message-bus.service b/build/sysroot/usr/lib/systemd/system/casaos-message-bus.service index 961f42c..dca2c80 100644 --- a/build/sysroot/usr/lib/systemd/system/casaos-message-bus.service +++ b/build/sysroot/usr/lib/systemd/system/casaos-message-bus.service @@ -1,6 +1,5 @@ [Unit] After=casaos-gateway.service -ConditionFileNotEmpty=/etc/casaos/message-bus.conf Description=CasaOS Message Bus Service [Service] diff --git a/config/init.go b/config/init.go index 1346ac7..bcca77d 100644 --- a/config/init.go +++ b/config/init.go @@ -1,8 +1,11 @@ package config import ( + "fmt" "log" + "os" + "github.com/IceWhaleTech/CasaOS-Common/utils/constants" "github.com/IceWhaleTech/CasaOS-MessageBus/common" "github.com/IceWhaleTech/CasaOS-MessageBus/model" "gopkg.in/ini.v1" @@ -10,11 +13,11 @@ import ( var ( CommonInfo = &model.CommonModel{ - RuntimePath: "/var/run/casaos", + RuntimePath: constants.DefaultRuntimePath, } AppInfo = &model.APPModel{ - LogPath: "/var/log/casaos", + LogPath: constants.DefaultLogPath, LogSaveName: common.MessageBusServiceName, LogFileExt: "log", } @@ -23,12 +26,29 @@ var ( ConfigFilePath string ) -func InitSetup(config string) { +func InitSetup(config string, sample string) { ConfigFilePath = MessageBusConfigFilePath if len(config) > 0 { 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) diff --git a/main.go b/main.go index eedc060..b35efc1 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,9 @@ var ( //go:embed api/message_bus/openapi.yaml _docYAML string + + //go:embed build/sysroot/etc/casaos/message-bus.conf.sample + _confSample string ) func main() { @@ -59,7 +62,7 @@ func main() { println("build date:", date) // initialization - config.InitSetup(*configFlag) + config.InitSetup(*configFlag, _confSample) logger.LogInit(config.AppInfo.LogPath, config.AppInfo.LogSaveName, config.AppInfo.LogFileExt)