欢迎光临
我们一直在努力

CentOS 7/8 Systemd 劫持 SysVinit

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

赞(2) 打赏
转载请注明来源:IT技术资讯 » CentOS 7/8 Systemd 劫持 SysVinit

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏