我仍然处理systemd并遇到了一些问题.这不是一个问题,但我想了解更多关于它的方式.我在其他地方找不到任何参考.
首先,我了解服务的自定义单元文件应该放在/ etc / systemd / system中.但是,如果单元文件可以位于其他位置,那么管理我们的服务器会很好.
systemctl link /path/to/servicename.service
这将在/ etc / systemd / system中创建上述链接.您现在可以启动/停止此服务.从表面上看,这似乎是我们管理服务的好方法.
root@test1:/etc/systemd/system# systemctl link /root/myservice.service
Created symlink from /etc/systemd/system/myservice.service to /root/myservice.service.
root@test1:/etc/systemd/system# systemctl status myservice.service
* myservice.service - My Test Service
Loaded: loaded (/root/myservice.service; linked; vendor preset: enabled)
root@test1:/etc/systemd/system# systemctl enable myservice.service
Failed to execute operation: No such file or directory
使用完全相同的单元文件,但复制到/ etc / systemd / system而不是链接,你得到:
root@test1:/etc/systemd/system# cp -p /root/myservice.service .
root@test1:/etc/systemd/system# systemctl daemon-reload
root@test1:/etc/systemd/system# systemctl status myservice.service
* myservice.service - My Test Service
Loaded: loaded (/etc/systemd/system/myservice.service; disabled; vendor preset: enabled)
root@test1:/etc/systemd/system# systemctl enable myservice.service
Created symlink from /etc/systemd/system/multi-user.target.wants/myservice.service to /etc/systemd/system/myservice.service.
如果是这种情况,“链接”功能的重点是什么?从文档中可以看出:
link FILENAME
Link a unit file that is not in the unit file search paths into the unit file search path. This requires an absolute path to a unit file. The effect of this can be undone with disable. The effect of this command is that a unit file is available for start and other commands although it is not installed directly in the unit search path.
解决方法:
手册页有误导性.
systemctl link /root/myservice.service
systemctl enable /root/myservice.service
第一个使您可以执行systemctl启动myservice.第二个使得myservice可以自动启动(正如@Julien指出的那样,自动添加链接).
我想……我一整天都试图绕过这一切.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。