Security

Splunkをsystemdサービスとして停止するときの問題について

cweiliou_splunk
Splunk Employee
Splunk Employee

CentOS に 7.2.3 の Splunk Forwarder をインストールし、以下のマニュアルに記載された手順をもとに fowarder を systemd のサービスとして登録しました。
https://docs.splunk.com/Documentation/Splunk/7.2.3/Admin/RunSplunkassystemdservice

但し、"systemctl stop Splunkd.service" で forwarder を停止しようとしたときに、splunkのプロセスが強制終了されているように見えます。
強制終了ではなく、"./splunk stop"のように終了する方法はありますでしょうか。

0 Karma
1 Solution

cweiliou_splunk
Splunk Employee
Splunk Employee

splunkd プロセスが強制終了される理由としては、systemd が SIGTERM シグナルを送っているためです。
SIGTERM を SIGINT に変更することで強制終了の問題を回避することができます。
なお、splunk の unit ファイルに「KillMode=mixed」および「KillSignal=SIGINT」を追加することで、SIGTERM から SIGINT に変更できます。

# cat /etc/systemd/system/Splunkd.service
#This unit file replaces the traditional start-up script for systemd
#configurations, and is used when enabling boot-start for Splunk on
#systemd-based Linux distributions.

[Unit]
Description=Systemd service file for Splunk, generated by 'splunk enable boot-start'
After=network.target

[Service]
Type=simple
Restart=always
ExecStart=/home/splunk/723_so/splunk/bin/splunk _internal_launch_under_systemd
LimitNOFILE=65536
SuccessExitStatus=51 52
RestartPreventExitStatus=51
RestartForceExitStatus=52
User=splunk
Delegate=true
MemoryLimit=100G
CPUShares=1024
PermissionsStartOnly=true
ExecStartPost=/bin/bash -c "chown -R splunk:splunk /sys/fs/cgroup/cpu/system.slice/%n"
ExecStartPost=/bin/bash -c "chown -R splunk:splunk /sys/fs/cgroup/memory/system.slice/%n"
KillMode=mixed
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

また、splunk がシャットダウンに時間がかかる場合でも、強制終了される可能性がありますので、その際には、unitファイルに「TimeoutStopSec」を追加し、timeoutの時間を増やしてください。

View solution in original post

0 Karma

bandit
Motivator

Summary of the issue:
Splunk 6.0.0 - Splunk 7.2.1 defaults to using init.d when enabling boot start
Splunk 7.2.2 - Splunk 7.2.9 defaults to using systemd when enabling boot start
Splunk 7.3.0 - Splunk 8.x defaults to using init.d when enabling boot start

systemd defaults to prompting for root credentials upon stop/start/restart of Splunk

Here is a simple fix if you have encountered this issue and prefer to use the traditional init.d scripts vs systemd.

Splunk Enterprise/Heavy Forwarder example (note: replace the splunk user below with the account you run splunk as):

sudo /opt/splunk/bin/splunk disable boot-start
sudo /opt/splunk/bin/splunk enable boot-start -user splunk -systemd-managed 0

Splunk Universal Forwarder example (note: replace the splunk user below with the account you run splunk as):

sudo /opt/splunkforwarder/bin/splunk disable boot-start
sudo /opt/splunkforwarder/bin/splunk enable boot-start -user splunk -systemd-managed 0
0 Karma

cweiliou_splunk
Splunk Employee
Splunk Employee

splunkd プロセスが強制終了される理由としては、systemd が SIGTERM シグナルを送っているためです。
SIGTERM を SIGINT に変更することで強制終了の問題を回避することができます。
なお、splunk の unit ファイルに「KillMode=mixed」および「KillSignal=SIGINT」を追加することで、SIGTERM から SIGINT に変更できます。

# cat /etc/systemd/system/Splunkd.service
#This unit file replaces the traditional start-up script for systemd
#configurations, and is used when enabling boot-start for Splunk on
#systemd-based Linux distributions.

[Unit]
Description=Systemd service file for Splunk, generated by 'splunk enable boot-start'
After=network.target

[Service]
Type=simple
Restart=always
ExecStart=/home/splunk/723_so/splunk/bin/splunk _internal_launch_under_systemd
LimitNOFILE=65536
SuccessExitStatus=51 52
RestartPreventExitStatus=51
RestartForceExitStatus=52
User=splunk
Delegate=true
MemoryLimit=100G
CPUShares=1024
PermissionsStartOnly=true
ExecStartPost=/bin/bash -c "chown -R splunk:splunk /sys/fs/cgroup/cpu/system.slice/%n"
ExecStartPost=/bin/bash -c "chown -R splunk:splunk /sys/fs/cgroup/memory/system.slice/%n"
KillMode=mixed
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

また、splunk がシャットダウンに時間がかかる場合でも、強制終了される可能性がありますので、その際には、unitファイルに「TimeoutStopSec」を追加し、timeoutの時間を増やしてください。

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...