SysV, Upstart and systemd init script coexistence
https://askubuntu.com/questions/867843/sysv-upstart-and-systemd-init-script-coexistence
On my system (16.04), there are the files /lib/systemd/system/network-manager.service
and /etc/init.d/network-manager
, for example.
I don't understand how (and why) this works. I always restart Network Manager by sudo service network-manager restart
. Shouldn't this mess up systemd somehow? It still seems to work.
Why does service --status-all
list all kinds of services? Shouldn't 16.04 use systemd instead of Upstart?
Someone please explain how this coexistence works.
Answer
Only one init system can be active at once. On 16.04, that's systemd.
A number of packages ship with files for multiple init systems, so they can be managed with multiple init systems on different OSes. On Ubuntu, sometimes scripts for multiple init systems get installed, even though they are not all used at the same time.
Newer init systems try to maintain compatibility with older ones. In particular, systemd tries to maintain compatibility with both Upstart and SysV init scripts.
In the case of the "init.d" script you mentioned, that is a "SysV" init script, not an Upstart script. Also, "SysV" init scripts would only be started on boot if they were symlinked to a directory like "/etc/rc5.d". You'll find that Network Manager does not have a symlink installed there.
To understand how systemd
manages old "SysV" init scripts, see How does systemd use /etc/init.d scirpts?.
Now, to answer the question about why it works to restart Network Manager with "service network-manager restart". The service
command is used with both Upstart scripts and SysV init scripts, preferring the former. Network Manager also has an Upstart script installed on 16.04 at /etc/init/network-manager.conf
.
If you review the output of sudo strace service network-manager restart
, you can get a sense of what's happening. First, the output shows that systemctl
is being called, indicating that the command is being redirected to systemd. First, shortly after it opens /usr/bin/service
, you can see it start to read in the file as a shell script:
open("/usr/sbin/service", O_RDONLY) = 3
...
read(10, "#!/bin/sh\n\n#####################"..., 8192) = 8192
Now that we know that service
is a shell script, we can go check out the source code of it. In the source code, we find that is_systemd
is detected and set. For the systemd case, you can see that the command gets rewritten to be systemctl restart network-manager
.
So while the three init systems co-exist and have some compatibility, there are layers of complexity. To minimize the complexity of what's happening going forward, it's best to use systemd unit files and the systemctl
tool to manage services.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通