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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...