Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systemd control #895

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Systemd control #895

wants to merge 26 commits into from

Conversation

ddpbsd
Copy link
Member

@ddpbsd ddpbsd commented Jul 12, 2016

Requires/includes PR #894

This should allow ossec-control to utilize systemd to manage the ossec processes. Also untested, and kind of unsure if I finished it.


This change is Reviewable

## XXX - system paths and exact execution are probably wrong.
if [ X`uname` == "XLinux" ]; then
if [ -x /sbin/systemctl ]; then
/sbin/ssytemctl start ossec-server.service
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ssytemctl
Think this might need to be systemctl

@ddpbsd
Copy link
Member Author

ddpbsd commented Aug 24, 2016

Fixed the ssytemctl typo.

@ddpbsd ddpbsd mentioned this pull request Sep 15, 2016
@ddpbsd
Copy link
Member Author

ddpbsd commented Sep 15, 2016

I'm lightly testing the agent bits on Ubuntu 16.whatever LTS. Seems to be going well-ish so far.

@ddpbsd
Copy link
Member Author

ddpbsd commented Mar 15, 2017

I think restart isn't working. Will test later and update.

@@ -1,6 +1,7 @@
[Unit]
Description=OSSEC Execd
PartOf=ossec-agent.target
Before=ossec-ossec-syscheckd.service ossec-agentd.service ossec-logcollector.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here ? should be ossec-syscheckd

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting those mistakes. They should be corrected now.

${SYSTEMCTL} stop ossec-server.target
fi
exit 0
if
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fi

@phamvuong
Copy link
Contributor

phamvuong commented Aug 23, 2018

@ddpbsd I'm not sure if you want this kind of behavior: if one of the member services (such as execd, syscheckd, etc) is killed/crashed by some reason, the server/agent target should be stopped.
If this is the case then I think you may want to use this option in the target file
https://www.freedesktop.org/software/systemd/man/systemd.unit.html#BindsTo=

[Unit]
Description=OSSEC HIDS agent
After=network.target
BindsTo=ossec-execd.service ossec-syscheckd.service ossec-agentd.service ossec-logcollector.service

Wants=ossec-dbd.service
Wants=ossec-csyslog.service
Wants=ossec-agentless.service

[Install]
WantedBy=multi-user.target

@phamvuong
Copy link
Contributor

phamvuong commented Aug 23, 2018

And also there is one concern in this part of signal handle code:
https://github.com/ossec/ossec-hids/blob/master/src/shared/sig_op.c#L33

If the exit code is always 1, then service's Active state is always failed instead of 'inactive (dead)' if we use 'systemctl stop' to stop the target or any service.

client-syscheckd.service - OSSEC syscheckd
   Loaded: loaded (/usr/lib/systemd/system/client-syscheckd.service; static; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2018-08-23 09:06:30 CEST; 39s ago
  Process: 5235 ExecStart=/usr/bin/env ${DIRECTORY}/bin/ossec-syscheckd -f (code=exited, status=1/FAILURE)
  Process: 5225 ExecStartPre=/usr/bin/env ${DIRECTORY}/bin/ossec-syscheckd -t (code=exited, status=0/SUCCESS)
 Main PID: 5235 (code=exited, status=1/FAILURE)

@phamvuong
Copy link
Contributor

For the reload option in ossec-control.sh, you can apply the same thing in systemd using below option https://www.freedesktop.org/software/systemd/man/systemd.unit.html#PropagatesReloadTo=

However, it is applied for systemd version 235 and later only.

@@ -1,6 +1,8 @@
[Unit]
Description=OSSEC syscheckd
PartOf=ossec-server.target
After=ossec-maild.service ossec-execd.service ossec-analysisd.service ossec-remoted.service
Before=ossec-agentless.service ossec-csyslog.service ossec-dbd.service ossec-monitord.service ossec-remoted.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ossec-remoted has been in "After" section

@@ -1,6 +1,8 @@
[Unit]
Description=OSSEC remoted
PartOf=ossec-server.target
After=ossec-maild.service ossec-execd.service ossec-analysisd.service ossec-logcollector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ossec-logcollector.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants