微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux-如何为启动时执行启用systemd单元模板?

我有一个服务器,可以在嵌入式目标上使用Yocto兼容文件系统在系统启动时启动.文件系统将systemd用于其服务系统.

我的服务器使用systemd模板单元文件,但无法启用它.我们使用模板来提供服务器使用的sqlite数据库文件的完整路径名.模板单元文件名为:

/lib/systemd/system/[email protected]

内容

[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 [email protected] [email protected]

当我跑步时:

# systemctl start [email protected]

服务器使用正确的参数启动,找到数据库,然后按预期在后台执行.因此,我尝试启用服务模板,以便它将在系统启动时启动服务:

# systemctl enable [email protected]
    Failed to execute operation: No such file or directory

既然失败了,我尝试启用模板文件本身:

# systemctl enable TDI_DataServer@
    ln -s '/lib/systemd/system/[email protected]''/etc/systemd/system/multi-user.target.wants/[email protected]'

从表面上看,系统似乎很高兴,但是在引导时,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/[email protected]; 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 [email protected]

但是,如果我将/ var / lib / ndc中的数据库文件名称从“ DataServer.DB”更改为“ DataServer.db”(即,小数点后的小写字母),则会发出以下命令:

# systemctl enable [email protected]

…一切正常.符号链接在/etc/systemd/system/multi-user.target.wants中创建,并且在系统下次重新启动时,我们的DataServer服务会找到其数据库并愉快地运行.

我已经通知了我们的第三方文件系统提供商. Yocto的人们和systemd的维护者可能会对这感兴趣.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐