无法在 RHEL 8.2 中使用 systemd 服务启动 (SysV init) 脚本

无法在 RHEL 8.2 中使用 systemd 服务启动 (SysV init) 脚本

我面临一个问题,即RHEL 8.2 中ExecStartSysV init脚本失败。我在使用完全相同的初始化脚本和服务单元设置的 RHEL 7.9 中没有遇到此问题。在网上查了很多资源,但仍然无法找出这个问题的根本原因。无论是由于版本问题还是RHEL 8.2 之间的systemd不兼容性。了解理想情况下我应该将其转换为服务单元,但由于某些要求我不能这样做。SysV initsystemd

RHEL 8.2systemd版本:v239

RHEL 7.9systemd版本:v219

/etc/systemd/system/mq.service文件:

[Unit]
Description=MQ service
After=network.target

[Service]
Type=forking
ExecStart=/etc/init.d/rc.mq start
ExecStop=/etc/init.d/rc.mq stop

[Install]
WantedBy=multi-user.target

/etc/init.d/rc.mq脚本:

#!/bin/sh
# chkconfig: 35 95 5

function fstart
{
  su - mqm -c "strmqm QMNAME" > /dev/null 2>&1
}

function fstop
{
  su - mqm -c "endmqm -i QMNAME"
  sleep 30
}

case $1 in
  start)
        fstart
        break;;
  stop)
        fstop
        break;;
  restart)
        fstop
        fstart
        break;;
  *)
    fstart
    break;;
esac
exit

$ systemctl status mq.service:

● mq.service - MQ service
   Loaded: loaded (/etc/systemd/system/mq.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Tue 2021-07-06 16:03:43 +08; 27s ago
  Process: 66183 ExecStop=/etc/init.d/rc.mq stop (code=exited, status=0/SUCCESS)
  Process: 66084 ExecStart=/etc/init.d/rc.mq start (code=exited, status=0/SUCCESS)

Jul 06 16:03:10 hostname.company.com su[66085]: pam_unix(su-l:session): session opened for user mqm by (uid=0)
Jul 06 16:03:10 hostname.company.com su[66085]: pam_unix(su-l:session): session opened for user mqm by (uid=0)
Jul 06 16:03:11 hostname.company.com su[66085]: pam_unix(su-l:session): session closed for user mqm
Jul 06 16:03:11 hostname.company.com su[66085]: pam_unix(su-l:session): session closed for user mqm
Jul 06 16:03:11 hostname.company.com su[66188]: (to mqm) root on none
Jul 06 16:03:11 hostname.company.com su[66188]: pam_unix(su-l:session): session opened for user mqm by (uid=0)
Jul 06 16:03:11 hostname.company.com su[66188]: pam_unix(su-l:session): session opened for user mqm by (uid=0)
Jul 06 16:03:11 hostname.company.com rc.mq[66183]: IBM MQ queue manager 'QMNAME' ending.
Jul 06 16:03:13 hostname.company.com rc.mq[66183]: IBM MQ queue manager 'QMNAME' ended.
Jul 06 16:03:43 hostname.company.com systemd[1]: Started MQ service.

$ journalctl -xe:

Jul 06 15:10:17 hostname.company.com systemd[1]: Starting MQ service...
-- Subject: Unit mq.service has begun start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit mq.service has begun starting up.
Jul 06 15:10:17 hostname.company.com systemd[1]: Started system activity accounting tool.
-- Subject: Unit sysstat-collect.service has finished start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit sysstat-collect.service has finished starting up.
--
-- The start-up result is done.
Jul 06 15:10:17 hostname.company.com su[62138]: (to mqm) root on none
Jul 06 15:10:17 hostname.company.com su[62138]: pam_unix(su-l:session): session opened for user mqm by (uid=0)
Jul 06 15:10:17 hostname.company.com systemd[1]: Started Session c513 of user mqm.
-- Subject: Unit session-c513.scope has finished start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit session-c513.scope has finished starting up.
--
-- The start-up result is done.
Jul 06 15:10:17 hostname.company.com su[62138]: pam_unix(su-l:session): session opened for user mqm by (uid=0)
Jul 06 15:10:17 hostname.company.com su[62138]: pam_unix(su-l:session): session closed for user mqm
Jul 06 15:10:17 hostname.company.com su[62138]: pam_unix(su-l:session): session closed for user mqm
Jul 06 15:10:17 hostname.company.com su[62245]: (to mqm) root on none
Jul 06 15:10:17 hostname.company.com su[62245]: pam_unix(su-l:session): session opened for user mqm by (uid=0)
Jul 06 15:10:17 hostname.company.com systemd[1]: Started Session c514 of user mqm.
-- Subject: Unit session-c514.scope has finished start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit session-c514.scope has finished starting up.
--
-- The start-up result is done.
Jul 06 15:10:17 hostname.company.com su[62245]: pam_unix(su-l:session): session opened for user mqm by (uid=0)
Jul 06 15:10:17 hostname.company.com rc.mq[62238]: IBM MQ queue manager 'QMNAME' ending.
Jul 06 15:10:19 hostname.company.com rc.mq[62238]: IBM MQ queue manager 'QMNAME' ended.
Jul 06 15:10:19 hostname.company.com su[62245]: pam_unix(su-l:session): session closed for user mqm
Jul 06 15:10:19 hostname.company.com su[62245]: pam_unix(su-l:session): session closed for user mqm
Jul 06 15:10:49 hostname.company.com systemd[1]: Started MQ service.
-- Subject: Unit mq.service has finished start-up
-- Defined-By: systemd
-- Support: https://access.redhat.com/support
--
-- Unit mq.service has finished starting up.
--
-- The start-up result is done.

尝试更改ExecStartExecStart=/sbin/service rc.mq start或运行此export _SYSTEMCTL_SKIP_REDIRECT=1,它仍然是相同的。

我可以知道这可能是什么原因吗?同样,此设置适用于 RHEL 7.9。

编辑**

发现/etc/pam.d/system-auth文件中的以下参数阻止服务启动,知道为什么吗?

-session    optional      pam_systemd.so

相关内容