go-sonic / sonic

Sonic is a blogging platform developed by Go. Simple and powerful
MIT License
1.99k stars 255 forks source link

Systemd 启动失败 #325

Closed rampageX closed 10 months ago

rampageX commented 10 months ago

检查清单

是什么版本出现了此问题?

1.1.3

使用的什么数据库?

SQLite3

使用的哪种方式部署?

Executable file

在线站点地址

本地

发生了什么?

直接用命令行启动没有问题:

/root/sonic/sonic -config /root/sonic/conf/config.yaml
Sonic started at         http://192.168.2.20:8080
Sonic admin started at         http://192.168.2.20:8080/admin

但是用 systemctl 启动就会失败

相关日志输出

Oct 27 13:48:40 N1-U20 sonic[551419]: panic: template dir: /resources/template not exist
Oct 27 13:48:40 N1-U20 sonic[551419]: goroutine 1 [running]:
Oct 27 13:48:40 N1-U20 sonic[551419]: github.com/go-sonic/sonic/config.NewConfig()
Oct 27 13:48:40 N1-U20 sonic[551419]: #011github.com/go-sonic/sonic/config/config.go:74 +0x5b0
Oct 27 13:48:40 N1-U20 sonic[551419]: reflect.Value.call({0x1260be0?, 0x14e9db8?, 0x400039eba8?}, {0x1459808, 0x4}, {0x1fd56a0, 0x0, 0x1338940?})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011reflect/value.go:596 +0x994
Oct 27 13:48:40 N1-U20 sonic[551419]: reflect.Value.Call({0x1260be0?, 0x14e9db8?, 0x10?}, {0x1fd56a0?, 0x400039ec01?, 0x1fd56a0?})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011reflect/value.go:380 +0x94
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.defaultInvoker({0x1260be0?, 0x14e9db8?, 0x1fd56a0?}, {0x1fd56a0?, 0x0?, 0x16e4ea0?})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/container.go:238 +0x28
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.(*constructorNode).Call(0x40004ff380, {0x16e4ea0, 0x40000c1c20})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/constructor.go:185 +0x250
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.paramSingle.Build({{0x0, 0x0}, 0x0, {0x16ec628, 0x122d880}}, {0x16e4ea0, 0x40000c1c20})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/param.go:287 +0x2b0
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.paramList.BuildList({{0x16ec628, 0x12a0f00}, {0x40003a42c0, 0x2, 0x2}}, {0x16e4ea0, 0x40000c1c20})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/param.go:150 +0xa0
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.(*constructorNode).Call(0x40004ff200, {0x16e4ea0, 0x40000c1c20})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/constructor.go:155 +0xc8
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.paramSingle.Build({{0x0, 0x0}, 0x0, {0x16ec628, 0x14400a0}}, {0x16e4ea0, 0x40000c1c20})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/param.go:287 +0x2b0
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.paramObjectField.Build(...)
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/param.go:484
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.paramObject.Build({{0x16ec628, 0x400003e4e0}, {0x4000539e90, 0x1, 0x1}, {0x0, 0x0, 0x0}}, {0x16e4ea0, 0x40000c1c20})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/param.go:412 +0x44c
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.paramList.BuildList({{0x16ec628, 0x40004ba8c0}, {0x4000544430, 0x1, 0x1}}, {0x16e4ea0, 0x40000c1c20})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/param.go:150 +0xa0
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.(*Scope).Invoke(0x40000c1c20, {0x40004ba8c0, 0x400012c930}, {0x0, 0x0, 0x400012c930?})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/invoke.go:122 +0x228
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/dig.(*Container).Invoke(0x4000040ac8?, {0x40004ba8c0?, 0x400012c930?}, {0x0?, 0x20?, 0x1f9fdc0?})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/dig@v1.17.1/invoke.go:82 +0x2c
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/fx.runInvoke({0xffff643dfb18?, 0x40000ba678?}, {{0x40004ba8c0, 0x400012c930}, {0x40003adad0, 0x4, 0x5}})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/fx@v1.20.1/invoke.go:108 +0x1b8
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/fx.(*module).executeInvoke(0x40000bc4e0, {{0x40004ba8c0, 0x400012c930}, {0x40003adad0, 0x4, 0x5}})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/fx@v1.20.1/module.go:288 +0x104
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/fx.(*module).executeInvokes(0x40000bc4e0)
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/fx@v1.20.1/module.go:274 +0xdc
Oct 27 13:48:40 N1-U20 sonic[551419]: go.uber.org/fx.New({0x400017ca00, 0x14, 0x1?})
Oct 27 13:48:40 N1-U20 sonic[551419]: #011go.uber.org/fx@v1.20.1/app.go:503 +0x820
Oct 27 13:48:40 N1-U20 sonic[551419]: main.InitApp()
Oct 27 13:48:40 N1-U20 sonic[551419]: #011github.com/go-sonic/sonic/main.go:74 +0x558
Oct 27 13:48:40 N1-U20 sonic[551419]: main.main()
Oct 27 13:48:40 N1-U20 sonic[551419]: #011github.com/go-sonic/sonic/main.go:24 +0x1c
Oct 27 13:48:40 N1-U20 systemd[1]: sonic.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Oct 27 13:48:40 N1-U20 systemd[1]: sonic.service: Failed with result 'exit-code'.
Oct 27 13:48:40 N1-U20 systemd[1]: sonic.service: Scheduled restart job, restart counter is at 5.
Oct 27 13:48:40 N1-U20 systemd[1]: Stopped Go-Sonic Service.
Oct 27 13:48:40 N1-U20 systemd[1]: sonic.service: Start request repeated too quickly.
Oct 27 13:48:40 N1-U20 systemd[1]: sonic.service: Failed with result 'exit-code'.
Oct 27 13:48:40 N1-U20 systemd[1]: Failed to start Go-Sonic Service.

附加信息

No response

textworld commented 10 months ago

贴一下你的systemd配置

rampageX commented 10 months ago

贴一下你的systemd配置

就用内置模板改的:

[Unit]
Description=Go-Sonic Service
Documentation=https://github.com/go-sonic/sonic
After=network.target nss-lookup.target

[Service]
User=root
ExecStart=/root/sonic/sonic  -config /root/sonic/conf/config.yaml
Restart=on-failure
RestartPreventExitStatus=23

[Install]
WantedBy=multi-user.target

在 N1 盒子的实体系统 Ubuntu 20.04 aarch64,以及虚拟机 x86 系统 Debian 11 内试过,都是一样。

1379 commented 10 months ago

应该是你的config.yaml 里面的work_dir 没有改?你应该改成sonic 所在的目录

rampageX commented 10 months ago

应该是你的config.yaml 里面的work_dir 没有改?你应该改成sonic 所在的目录

的确,改为 /root/sonic 这个绝对路径就可以了,谢谢!