Skip to content

Commit

Permalink
fix: fix service init crash (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao92 authored May 25, 2022
1 parent 4be2c3a commit f801527
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 38 deletions.
4 changes: 2 additions & 2 deletions config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const portal = config.devServer.https ? 'https' : 'http';
const port = config.devServer.port;
const ip = config.devServer.host || '127.0.0.1';

const goServerPath = path.resolve(process.cwd(), './server');
const goServerPath = path.resolve(process.cwd(), './server-v2/api/studio');

const goServerProcess = spawn('go run main.go', { cwd: goServerPath, shell: true });
const goServerProcess = spawn('make run', { cwd: goServerPath, shell: true });
goServerProcess.stdout.on('data', (data) => console.log(chalk.blue(`server::${data.toString().slice(0, -1)}`)));
goServerProcess.on('close', () =>
console.log(chalk.red('\ngo server 启动失败,服务器将不可用,请切换到 server 目录调试异常\n'))
Expand Down
83 changes: 50 additions & 33 deletions server-v2/api/studio/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,69 @@ func (c *Config) Validate() error {
}

func (c *Config) Complete() {
if c.File.TaskIdPath == "" {
_, err := os.Stat(DefaultFilesDataDir)
taskIdFile := DefaultTaskIdPath
if c.File.TaskIdPath != "" {
taskIdFile = c.File.TaskIdPath
}
abs, _ := filepath.Abs(taskIdFile)
_, err := ioutil.ReadFile(abs)
if err != nil {
if os.IsNotExist(err) {
os.MkdirAll(DefaultFilesDataDir, 0o766)
}
abs, _ := filepath.Abs(DefaultTaskIdPath)
_, err = ioutil.ReadFile(abs)
if err != nil {
absDir := filepath.Dir(abs)
_, err := os.Stat(absDir)
if os.IsNotExist(err) {
_, err := os.Create(abs)
if err != nil {
zap.L().Fatal("DefaultTaskIdPath Init fail", zap.Error(err))
} else {
zap.L().Fatal("DefaultTaskIdPath Init fail", zap.Error(err))
}
os.MkdirAll(absDir, 0o776)
}
_, err = os.Create(abs)
if err != nil {
zap.L().Fatal("DefaultTaskIdPath Init fail", zap.Error(err))
}
}
c.File.TaskIdPath = abs
}
c.File.TaskIdPath = abs

if c.File.UploadDir == "" {
abs, _ := filepath.Abs(DefaultUploadDir)
c.File.UploadDir = abs
_, err := os.Stat(abs)
if os.IsNotExist(err) {
os.MkdirAll(abs, 0o776)
}
uploadDir := DefaultUploadDir
if c.File.UploadDir != "" {
uploadDir = c.File.UploadDir
}
abs, _ = filepath.Abs(uploadDir)
c.File.UploadDir = abs
_, err = os.Stat(abs)
if os.IsNotExist(err) {
os.MkdirAll(abs, 0o776)
}

if c.File.TasksDir == "" {
abs, _ := filepath.Abs(DefaultTasksDir)
c.File.TasksDir = abs
_, err := os.Stat(abs)
if os.IsNotExist(err) {
os.MkdirAll(abs, 0o766)
}
tasksDir := DefaultTasksDir
if c.File.TasksDir != "" {
tasksDir = c.File.TasksDir
}
abs, _ = filepath.Abs(tasksDir)
c.File.TasksDir = abs
_, err = os.Stat(abs)
if os.IsNotExist(err) {
os.MkdirAll(abs, 0o776)
}

if c.File.SqliteDbFilePath == "" {
_, err := os.Stat(DefaultFilesDataDir)
sqliteDbFilePath := DefaultSqliteDbFilePath
if c.File.SqliteDbFilePath != "" {
sqliteDbFilePath = c.File.SqliteDbFilePath
}
abs, _ = filepath.Abs(sqliteDbFilePath)
_, err = ioutil.ReadFile(abs)
if err != nil {
if os.IsNotExist(err) {
os.MkdirAll(DefaultFilesDataDir, 0o766)
absDir := filepath.Dir(abs)
_, err := os.Stat(absDir)
if os.IsNotExist(err) {
os.MkdirAll(absDir, 0o776)
}
_, err = os.Create(abs)
if err != nil {
zap.L().Fatal("SqliteDbFilePath Init fail", zap.Error(err))
}
}
abs, _ := filepath.Abs(DefaultSqliteDbFilePath)
c.File.SqliteDbFilePath = abs
}
c.File.SqliteDbFilePath = abs
}

func (c *Config) InitConfig() error {
Expand Down
2 changes: 1 addition & 1 deletion server-v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
require (
github.com/facebook/fbthrift v0.31.1-0.20211129061412-801ed7f9f295 // indirect
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
github.com/vesoft-inc/nebula-http-gateway/ccore v0.0.0-20220413113447-a3f4c56287d8
github.com/vesoft-inc/nebula-http-gateway/ccore v0.0.0-20220518092450-316a5f6420ef
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
)
Expand Down
4 changes: 2 additions & 2 deletions server-v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ github.com/vesoft-inc/go-pkg v0.0.0-20220516090733-5ce93ad3254b h1:MVAkGU2YH1p3P
github.com/vesoft-inc/go-pkg v0.0.0-20220516090733-5ce93ad3254b/go.mod h1:HCAXRhF2io+nPLQnl+RQ6XyVcp1Xdv6NgslXRBBCiEU=
github.com/vesoft-inc/nebula-go/v3 v3.0.0-20220425030225-cdb52399b40a h1:/8l9RT6gU0cUS1Cgzqv3A9dKto19VQBjVk1BqAAqqvM=
github.com/vesoft-inc/nebula-go/v3 v3.0.0-20220425030225-cdb52399b40a/go.mod h1:+sXv05jYQBARdTbTcIEsWVXCnF/6ttOlDK35xQ6m54s=
github.com/vesoft-inc/nebula-http-gateway/ccore v0.0.0-20220413113447-a3f4c56287d8 h1:iL92Uk6hAe4vUBK/L99wf5295HYOtnD4plctVA5xek0=
github.com/vesoft-inc/nebula-http-gateway/ccore v0.0.0-20220413113447-a3f4c56287d8/go.mod h1:sFEvE+cY4TgwqWx6H6msOqAUzRhsEHHKaaMgIZENHuQ=
github.com/vesoft-inc/nebula-http-gateway/ccore v0.0.0-20220518092450-316a5f6420ef h1:Hco8JsAXm2ujRpJjo+qGnVyASHXDnopHwA20anmmnV4=
github.com/vesoft-inc/nebula-http-gateway/ccore v0.0.0-20220518092450-316a5f6420ef/go.mod h1:sFEvE+cY4TgwqWx6H6msOqAUzRhsEHHKaaMgIZENHuQ=
github.com/vesoft-inc/nebula-importer v1.0.1-0.20220505095506-93febd41c2be h1:7YGSREZ6uS1WjCdKTlHEvhSeYURJFY7UXQZ008+EB2Y=
github.com/vesoft-inc/nebula-importer v1.0.1-0.20220505095506-93febd41c2be/go.mod h1:8xAQi6KI2qe40Dop/GqDXmBEurt7qGp5Pjd1MESAVNA=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
Expand Down

0 comments on commit f801527

Please sign in to comment.