我们公司遇到了以下问题。我们有多个红帽企业Linux服务器,"SAP HANA S/4“正在运行。我们创建了一个systemd服务来自动启动和停止守护进程,这样我们就不需要在重新启动或关闭时手动与系统交互。
Autostart运行良好,但在关闭时正确停止守护进程似乎有问题。守护进程与另一个用户一起运行(每个服务器都是单独的)。看起来,在实际服务停止之前,systemd就开始关闭用户会话;因此,服务将不能正常停止。
服务
[Unit]
Description=saphana
After=remote-fs.target user.slice sapinit.service multi-user.target
Requires=user.slice
[Service]
KillMode=none
Type=oneshot
ExecStart=/hana/source/scripts/sapHanaControl.pl start
ExecStop=/hana/source/scripts/sapHanaControl.pl stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
这个脚本在ExecStart中被调用,ExecStop基本上执行以下命令。
On启动:
"sudo -u $username csh -c "sapcontrol -nr $instance -function Start"
On停止: "sudo -u $username csh -c“边控-nr $instance -function Stop
Shutdown日志
Systemd日志的输出显示如下:
Jun 20 16:23:05 host123 systemd[1]: Stopping Session c4 of user **userxy**.
Jun 20 16:23:05 host123sapHanaControl.pl[15003]: sudo -u **userxy** csh -c "sapcontrol -nr 00 -function Stop"
Jun 20 16:23:05 host123 sapHanaControl.pl[15003]: 20.06.2018 16:23:05
Jun 20 16:23:05 host123 sapHanaControl.pl[15003]: Stop
Jun 20 16:23:05 host123 sapHanaControl.pl[15003]: FAIL: NIECONN_REFUSED (Connection refused), NiRawConnect failed in plugin_fopen()
<#>更新
当系统正常运行时,我看到以下进程正在运行:
[root@wsstadt325 ~]# ps -ef | grep sapstartsrv
d61adm 1740 1 0 11:56 ? 00:00:01 /usr/sap/D61/HDB05/exe/sapstartsrv pf=/usr/sap/D61/SYS/profile/D61_HDB05_wsstadt325 -D -u d61adm
sapadm 1741 1 0 11:56 ? 00:00:04 /usr/sap/hostctrl/exe/sapstartsrv pf=/usr/sap/hostctrl/exe/host_profile -D
d21adm 1946 1 0 11:56 ? 00:00:02 /usr/sap/D21/ASCS01/exe/sapstartsrv pf=/usr/sap/D21/SYS/profile/D21_ASCS01_wsstadt325 -D -u d21adm
d21adm 2182 1 0 11:56 ? 00:00:02 /usr/sap/D21/D00/exe/sapstartsrv pf=/usr/sap/D21/SYS/profile/D21_D00_wsstadt325 -D -u d21adm`
让我的脚本在系统重新启动/关机时记录"ps -ef \ grep sapstartsrv“输出。
ps -ef | grep sapstartsrv
sapadm 1683 1 0 13:52 ? 00:00:01 /usr/sap/hostctrl/exe/sapstartsrv pf=/usr/sap/hostctrl/exe/host_profile -D
root 5706 5522 0 14:00 ? 00:00:00 sh -c ps -ef | grep sapstartsrv
root 5708 5706 0 14:00 ? 00:00:00 grep sapstartsrv
sapstartsrv服务是由默认的Service (皂init)启动的,在我自己的Systemd服务(因此,在重新启动时,它是相反的顺序)之前,它就会得到星体--问题似乎是,systemctl开始扼杀用户会话(在我的例子中,用户是: d21adm和d61adm),在我的实际Systemd服务停止之前,该进程正在运行。(希望这至少有点道理)
下面是整个systemd链的映像(我的服务位于最末端):所涉及的服务:- sapinit.service (默认的服务)- saphana.service (我的自定义服务)
发布于 2018-07-09 14:07:39
如下面的KB https://www.suse.com/de-de/support/kb/doc/?id=7022671所述,找出了问题的原因
Systemd在90秒后杀死每个user.slice (此超时不能更改),看起来systemd只是在不修改pan.d的情况下自动停止SAP实例。所描述的解决方案似乎有点“黑客化”,但它有效。
cp /etc/pam.d/system-auth /etc/pam.d/custom-su-session
vim /etc/pam.d/custom-su-session
在“会话可选pam_systemd.so”之前插入以下一行
session [success=1 new_authtok_reqd=ok default=ignore] pam_listfile.so item=user sense=allow file=/etc/custom-su-session
当执行su命令时,这一行跳过user.slice创建,用户列在文件/etc/定制su-会话中。
vim /etc/pam.d/su
将session include system-auth
替换为session include custom-su-session
https://unix.stackexchange.com/questions/451245
复制相似问题