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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
63fb433
use Before and After to determine the order these should start in.
ddpbsd May 3, 2016
56d40d3
Adjust the service files for the server install to preserve desired
ddpbsd May 3, 2016
42a7434
Stop the processes too, I guess.
ddpbsd May 3, 2016
58bafaa
Add enable files for dbd, agentlessd, and csyslogd. This should help
ddpbsd May 3, 2016
b425d0a
Require the dot files created when enabling via ossec-control to
ddpbsd May 3, 2016
358811a
Enable disable in systemd setups.
ddpbsd May 3, 2016
da1cfee
Merge branch 'master' of github.com:ddpbsd/ossec-hids into systemd_se…
ddpbsd Jul 12, 2016
c243cd9
Merge branch 'master' of github.com:ddpbsd/ossec-hids into systemd_co…
ddpbsd Jul 12, 2016
5900c89
Merge branch 'master' of github.com:ddpbsd/ossec-hids into systemd_co…
ddpbsd Aug 24, 2016
fccfb6b
ssytemctl -> systemctl
ddpbsd Aug 24, 2016
23662c5
Merge branch 'systemd_control' of https://github.com/ddpbsd/ossec-hid…
Sep 15, 2016
249ac8d
Merge branch 'master' of https://github.com/ddpbsd/ossec-hids into sy…
Sep 15, 2016
07e0c4f
Merge branch 'master' of https://github.com/ossec/ossec-hids into sys…
ddpbsd Sep 15, 2016
314ed7f
Merge branch 'systemd_services' of github.com:ddpbsd/ossec-hids into …
ddpbsd Sep 15, 2016
2e2dccf
I think ossec-server.service should be ossec-server.target.
Sep 15, 2016
3da96bf
UNTESTED: Try to install the systemd files
Sep 15, 2016
ea84264
Silly typo.
Sep 15, 2016
0c1817f
ENEEDCOFFEE: Fix the paths.
Sep 15, 2016
79fd4e1
I forgot /bin/sh is neutered on Ubuntu.
Sep 15, 2016
3f2e6dd
Merge branch 'systemd_combined' of ssh://buzzell/home/ddp/src/project…
ddpbsd Sep 15, 2016
2f4d859
Try to appease systems without /etc/systemd/system
ddpbsd Sep 15, 2016
e387076
X -> x
ddpbsd Nov 1, 2016
0a09265
I'm not sure why I thought systemctl was installed in /sbin, it's
ddpbsd Nov 1, 2016
309d5e2
Merge branch 'master' of https://github.com/ossec/ossec-hids into sys…
ddpbsd Apr 26, 2017
df44614
Merge branch 'master' of github.com:ddpbsd/ossec-hids into systemd_co…
ddpbsd Aug 22, 2018
0bc9ad2
2 silly mistakes spotted by phamvuong
ddpbsd Aug 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ install-agent: install-common

install -d -m 0750 -o ${OSSEC_USER} -g ${OSSEC_GROUP} ${PREFIX}/queue/rids

ifeq (${uname_S},Linux)
if [ -d /etc/systemd/system ]; then install -m 0444 systemd/agent/ossec-agentd.service systemd/agent/ossec-agent.target systemd/agent/ossec-execd.service systemd/agent/ossec-logcollector.service systemd/agent/ossec-syscheckd.service /etc/systemd/system/; fi
endif

install-local: install-server-generic

install-hybrid: install-server-generic
Expand Down Expand Up @@ -501,6 +505,10 @@ endif

install -m 0640 -o root -g ${OSSEC_GROUP} ../etc/decoder.xml ${PREFIX}/etc/

ifeq (${uname_S},Linux)
if [ -d /etc/systemd/system ]; then install -m 0444 -o root -g root systemd/server/ossec-agentsless.service systemd/server/ossec-analysisd.service systemd/server/ossec-csyslog.service systemd/server/ossec-dbd.service systemd/server/ossec-execd.service systemd/server/ossec-logcollector.service systemd/server/ossec-maild.service systemd/server/ossec-monitord.service systemd/server/ossec-remoted.service systemd/server/ossec-server.target systemd/server/ossec-syscheckd.service /etc/systemd/system/; fi
endif

rm -f ${PREFIX}/etc/shared/merged.mg


Expand Down
19 changes: 19 additions & 0 deletions src/init/ossec-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ PWD=`pwd`
DIR=`dirname $PWD`;


if [ X`uname` = "XLinux" ]; then
SYSTEMCTL=`which systemctl`
fi

### Do not modify bellow here ###
NAME="OSSEC HIDS"
VERSION="v3.0.0"
Expand Down Expand Up @@ -124,6 +128,13 @@ start()
lock;
checkpid;

if [ X`uname` = "XLinux" ]; then
if [ -x ${SYSTEMCTL} ]; then
${SYSTEMCTL} start ossec-agent.target
fi
exit 0
fi

# We actually start them now.
for i in ${SDAEMONS}; do
pstatus ${i};
Expand Down Expand Up @@ -180,6 +191,14 @@ pstatus()
stopa()
{
lock;

if [ X`uname` = "XLinux" ]; then
if [ -x ${SYSTEMCTL} ]; then
${SYSTEMCTL} stop ossec-agent.target
fi
exit 0
fi

checkpid;
for i in ${DAEMONS}; do
pstatus ${i};
Expand Down
31 changes: 31 additions & 0 deletions src/init/ossec-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ PWD=`pwd`
DIR=`dirname $PWD`;
PLIST=${DIR}/bin/.process_list;


if [ X`uname` = "XLinux" ]; then
SYSTEMCTL=`which systemctl`
fi


### Do not modify bellow here ###

# Getting additional processes
Expand Down Expand Up @@ -109,10 +115,13 @@ enable()

if [ "X$2" = "Xdatabase" ]; then
echo "DB_DAEMON=ossec-dbd" >> ${PLIST};
touch ${DIR}/etc/.dbd
elif [ "X$2" = "Xclient-syslog" ]; then
echo "CSYSLOG_DAEMON=ossec-csyslogd" >> ${PLIST};
touch ${DIR}/etc/.csyslogd
elif [ "X$2" = "Xagentless" ]; then
echo "AGENTLESS_DAEMON=ossec-agentlessd" >> ${PLIST};
touch ${DIR}/etc/.agentlessd
elif [ "X$2" = "Xdebug" ]; then
echo "DEBUG_CLI=\"-d\"" >> ${PLIST};
else
Expand All @@ -137,10 +146,13 @@ disable()

if [ "X$2" = "Xdatabase" ]; then
echo "DB_DAEMON=\"\"" >> ${PLIST};
rm /var/ossec/etc/.dbd
elif [ "X$2" = "Xclient-syslog" ]; then
echo "CSYSLOG_DAEMON=\"\"" >> ${PLIST};
rm /var/ossec/etc/.csyslogd
elif [ "X$2" = "Xagentless" ]; then
echo "AGENTLESS_DAEMON=\"\"" >> ${PLIST};
rm /var/ossec/etc/.agentlessd
elif [ "X$2" = "Xdebug" ]; then
echo "DEBUG_CLI=\"\"" >> ${PLIST};
else
Expand Down Expand Up @@ -192,6 +204,7 @@ testconfig()
# Start function
start()
{

SDAEMONS="${DB_DAEMON} ${CSYSLOG_DAEMON} ${AGENTLESS_DAEMON} ossec-maild ossec-execd ossec-analysisd ossec-logcollector ossec-remoted ossec-syscheckd ossec-monitord"

echo "Starting $NAME $VERSION (by $AUTHOR)..."
Expand All @@ -200,6 +213,16 @@ start()
echo "OSSEC analysisd: Testing rules failed. Configuration error. Exiting."
exit 1;
fi

## If the system is Linux, look for systemctl. If that file exists, use it.
## XXX - system paths and exact execution are probably wrong.
if [ X`uname` = "XLinux" ]; then
if [ -x ${SYSTEMCTL} ]; then
${SYSTEMCTL} start ossec-server.target
fi
exit 0
fi

lock;
checkpid;

Expand Down Expand Up @@ -268,6 +291,14 @@ pstatus()
stopa()
{
lock;

if [ X`uname` = "XLinux" ]; then
if [ -x ${SYSTEMCTL} ]; then
${SYSTEMCTL} stop ossec-server.target
fi
exit 0
fi

checkpid;
for i in ${DAEMONS}; do
pstatus ${i};
Expand Down
2 changes: 2 additions & 0 deletions src/systemd/agent/ossec-agentd.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description=OSSEC Agent
PartOf=ossec-agent.target
After=ossec-execd.service
Before=ossec-syscheckd.service ossec-logcollector.service

[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down
1 change: 1 addition & 0 deletions src/systemd/agent/ossec-execd.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[Unit]
Description=OSSEC Execd
PartOf=ossec-agent.target
Before=ossec-syscheckd.service ossec-agentd.service ossec-logcollector.service

[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down
2 changes: 2 additions & 0 deletions src/systemd/agent/ossec-logcollector.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description=OSSEC Logcollector
PartOf=ossec-agent.target
After=ossec-execd.service ossec-agentd.service
Before=ossec-syscheckd.service

[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down
1 change: 1 addition & 0 deletions src/systemd/agent/ossec-syscheckd.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[Unit]
Description=OSSEC syscheckd
PartOf=ossec-agent.target
After=ossec-execd.service ossec-agentd.service ossec-logcollector.service

[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down
4 changes: 3 additions & 1 deletion src/systemd/server/ossec-agentless.service
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[Unit]
Description=OSSEC Agentless
PartOf=ossec-server.target
After=ossec-analysisd.service ossec-execd.service ossec-logcollector.service ossec-maild.service ossec-monitord.service ossec-remoted.service ossec-syscheckd.service
ConditionPathExists=/var/ossec/etc/.agentlessd

[Service]
EnvironmentFile=/etc/ossec-init.conf
Environment=DIRECTORY=/var/ossec

ExecStartPre=/usr/bin/env ${DIRECTORY}/bin/ossec-agentlessd -t
ExecStart=/usr/bin/env ${DIRECTORY}/bin/ossec-agentlessd -f
ExecStart=/usr/bin/env ${DIRECTORY}/bin/ossec-agentlessd -f
2 changes: 2 additions & 0 deletions src/systemd/server/ossec-analysisd.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description=OSSEC Analysisd
PartOf=ossec-server.target
After=ossec-maild.service ossec-execd.service
Before=ossec-agentless.service ossec-csyslog.service ossec-dbd.service ossec-logcollector.service ossec-monitord.service ossec-remoted.service ossec-syscheckd.service

[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down
4 changes: 3 additions & 1 deletion src/systemd/server/ossec-csyslog.service
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[Unit]
Description=OSSEC Syslog client
PartOf=ossec-server.target
After=ossec-analysisd.service ossec-dbd.service ossec-execd.service ossec-logcollector.service ossec-maild.service ossec-monitord.service ossec-remoted.service ossec-syscheckd.service
ConditionPathExists=/var/ossec/etc/.csyslogd

[Service]
EnvironmentFile=/etc/ossec-init.conf
Environment=DIRECTORY=/var/ossec

ExecStartPre=/usr/bin/env ${DIRECTORY}/bin/ossec-csyslogd -t
ExecStart=/usr/bin/env ${DIRECTORY}/bin/ossec-csyslogd -f
ExecStart=/usr/bin/env ${DIRECTORY}/bin/ossec-csyslogd -f
2 changes: 2 additions & 0 deletions src/systemd/server/ossec-dbd.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description=The OSSEC DBD
PartOf=ossec-server.target
After=ossec-analysisd.service ossec-execd.service ossec-logcollector.service ossec-maild.service ossec-monitord.service ossec-remoted.service ossec-syscheckd.service
ConditionPathExists=/var/ossec/etc/.dbd

[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down
2 changes: 2 additions & 0 deletions src/systemd/server/ossec-execd.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description=OSSEC Execd
PartOf=ossec-server.target
After=ossec-maild.service
Before=ossec-agentless.service ossec-analysisd.service ossec-csyslog.service ossec-dbd.service ossec-logcollector.service ossec-monitord.service ossec-remoted.service ossec-syscheckd.service

[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down
2 changes: 2 additions & 0 deletions src/systemd/server/ossec-logcollector.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[Unit]
Description=OSSEC Logcollector
PartOf=ossec-server.target
After=ossec-maild.service ossec-execd.service ossec-analysisd.service
Before=ossec-agentless.service ossec-csyslog.service ossec-dbd.service ossec-monitord.service ossec-remoted.service ossec-syscheckd.service

[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down
1 change: 1 addition & 0 deletions src/systemd/server/ossec-maild.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[Unit]
Description=OSSEC Maild
PartOf=ossec-server.target
Before=ossec-agentless.service ossec-analysisd.service ossec-csyslog.service ossec-dbd.service ossec-execd.service ossec-logcollector.service ossec-monitord.service ossec-remoted.service ossec-syscheckd.service

[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down
3 changes: 3 additions & 0 deletions src/systemd/server/ossec-monitord.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[Unit]
Description=OSSEC monitord
PartOf=ossec-server.target
After=ossec-maild.service ossec-execd.service ossec-analysisd.service ossec-logcollector.service ossec-remoted.service ossec-syscehckd.service
Before=ossec-agentless.service ossec-csyslog.service ossec-dbd.service


[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down
2 changes: 2 additions & 0 deletions src/systemd/server/ossec-remoted.service
Original file line number Diff line number Diff line change
@@ -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

Before=ossec-agentless.service ossec-csyslog.service ossec-dbd.service ossec-monitord.service ossec-syscheckd.service

[Service]
Type=forking
Expand Down
2 changes: 2 additions & 0 deletions src/systemd/server/ossec-syscheckd.service
Original file line number Diff line number Diff line change
@@ -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


[Service]
EnvironmentFile=/etc/ossec-init.conf
Expand Down