linux-如何为启动时执行启用systemd单元模板?
作者:互联网
我有一个服务器,可以在嵌入式目标上使用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)
我想念什么吗?任何帮助将非常感激.
解决方法:
似乎提供给单位文件的%I参数的systemctl解析确实存在错误.如上所述,以下命令失败:
# systemctl enable TDI_DataServer@-var-lib-ndc-DataServer.DB
但是,如果我将/ var / lib / ndc中的数据库文件的名称从“ DataServer.DB”更改为“ DataServer.db”(即,小数点后的小写字母),则会发出以下命令:
# systemctl enable TDI_DataServer@-var-lib-ndc-DataServer.db
…一切正常.符号链接在/etc/systemd/system/multi-user.target.wants中创建,并且在系统下次重新启动时,我们的DataServer服务会找到其数据库并愉快地运行.
我已经通知了我们的第三方文件系统提供商. Yocto的人们和systemd的维护者可能会对这感兴趣.
标签:yocto,templates,embedded-linux,systemd,linux 来源: https://codeday.me/bug/20191118/2031412.html