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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值