最新消息:

CentOS 7/8 Systemd 劫持 SysVinit

systemctl admin 758浏览 0评论

CentOS 7 以后版本,已经使用 systemd 替换 sysvinit。所以 CentOS 6 之前版本 sysvinit 迁移到 CentOS 7 以后版本会被 systemd 替换掉,比如

centos 6

 # cat /etc/redhat-release
CentOS release 6.9 (Final)
 # /etc/init.d/memcached restart
Stopping memcached.:                                       [  OK  ]
Starting memcached.:                                       [  OK  ]

centos 7

 # cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
 # /etc/init.d/memcached restart
Restarting memcached (via systemctl):                      [  OK  ]

就变成 systemctl 调用,导致服务启动异常。

原因

/etc/init.d/memcached 加载了 /etc/rc.d/init.d/functions

 # cat /etc/init.d/memcached | grep functi
# Source function library
. /etc/rc.d/init.d/functions

解决

 # cat /etc/rc.d/init.d/functions
if [ PPID -ne 1 -a -z "SYSTEMCTL_SKIP_REDIRECT" ] && \
        [ -d /run/systemd/system ] ; then
    case "$0" in
    /etc/init.d/*|/etc/rc.d/init.d/*)
        _use_systemctl=1
        ;;
    esac
fi

只要 SYSTEMCTL_SKIP_REDIRECT 变量存在即可,就不会调用 _use_systemctl=1

方法一 (推荐)

 # cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
 # SYSTEMCTL_SKIP_REDIRECT=1 /etc/init.d/memcached restart
Stopping memcached.:                                       [  OK  ]
Starting memcached.:                                       [  OK  ]

方法二

直接修改 /etc/init.d/memcached. /etc/rc.d/init.d/functions 之前添加 SYSTEMCTL_SKIP_REDIRECT=1

转载请注明:爱开源 » CentOS 7/8 Systemd 劫持 SysVinit

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址