【发布时间】:2016-07-20 06:57:06
【问题描述】:
我有一个服务器要在系统启动时使用嵌入式目标上的 Yocto 兼容文件系统启动。文件系统使用 systemd 作为其服务系统。
我的服务器使用 systemd 模板单元文件,但我无法启用它。我们使用模板来提供服务器使用的 sqlite 数据库文件的完整路径名。模板单元文件命名为:
/lib/systemd/system/TDI_DataServer@.service
其内容:
[Unit]
Description=Data Server application (with DB=%I)
After=syslog.target
[Service]
Type=simple
ExecStart=/opt/ndc/DataServer --DEBUG --databaseFile=%I
Restart=always
RestartSec=2
[Install]
WantedBy=multi-user.target
数据库文件在/var/lib/ndc/DataServer.DB,所以我在/lib/systemd/system中创建了一个符号链接:
# ln -s TDI_DataServer@.service TDI_DataServer@-var-lib-ndc-DataServer.DB.service
当我跑步时:
# systemctl start TDI_DataServer@-var-lib-ndc-DataServer.DB
服务器使用正确的参数启动,找到数据库,并按预期在后台执行。所以我尝试启用服务模板,以便它在系统启动时启动服务:
# systemctl enable TDI_DataServer@-var-lib-ndc-DataServer.DB
Failed to execute operation: No such file or directory
由于失败,我尝试启用模板文件本身:
# systemctl enable TDI_DataServer@
ln -s '/lib/systemd/system/TDI_DataServer@.service''/etc/systemd/system/multi-user.target.wants/TDI_DataServer@.service'
表面上,系统看起来很开心,但是在启动时,systemd 没有正确执行 TDI_DataServer 的启动。它似乎将“多用户”参数(可能来自单元文件中的 WantedBy 目标?)提供给单元文件。
这里是 systemctl 状态:
$ systemctl status -l TDI*
● TDI_DataServer@multi-user.service - Data Server application (with DB=multi/user)
Loaded: loaded (/lib/systemd/system/TDI_DataServer@.service; enabled)
Active: activating (auto-restart) (Result: signal) since Sat 2000-02-05 20:41:05 UTC; 1s ago
Process: 2951 ExecStart=/opt/ndc/DataServer --DEBUG --databaseFile=%I (code=killed, signal=ABRT)
Main PID: 2951 (code=killed, signal=ABRT)
Feb 05 20:41:05 mityomapl138 DataServer[2951]: [949783265:2047] NOTICE: per-conn mem: 136 + 2140 headers + protocol rx buf
Feb 05 20:41:05 mityomapl138 DataServer[2951]: [949783265:2056] NOTICE: Listening on port 4243
Feb 05 20:41:05 mityomapl138 systemd[1]: TDI_DataServer@multi-user.service: main process exited, code=killed, status=6/ABRT
Feb 05 20:41:05 mityomapl138 systemd[1]: Unit TDI_DataServer@multi-user.service entered failed state.
Feb 05 20:41:05 mityomapl138 DataServer[2951]: 2000:02:05 20:41:05: WSServer connected on socket tcp://localhost:5556
Feb 05 20:41:05 mityomapl138 DataServer[2951]: 2000:02:05 20:41:05: bound to socket inproc://clients
Feb 05 20:41:05 mityomapl138 DataServer[2951]: 2000:02:05 20:41:05: DatabaseWorker using database multi/user
Feb 05 20:41:05 mityomapl138 DataServer[2951]: unable to open database file
Feb 05 20:41:05 mityomapl138 DataServer[2951]: terminate called after throwing an instance of 'SQLite::Exception'
Feb 05 20:41:05 mityomapl138 DataServer[2951]: what(): unable to open database file
● TDI_DataServer.service
Loaded: loaded (/etc/init.d/TDI_DataServer)
Active: inactive (dead)
我错过了什么吗?任何帮助将不胜感激。
【问题讨论】:
-
注意:如果我将自己的符号链接放在名为“TDI_DataServer@-var-lib-ndc-DataServer.DB.service”的 /etc/systemd/system/multi-user.target.wants 目录中,一切正常。只是“systemctl enable”应该为我做到这一点
标签: linux templates embedded-linux systemd yocto