From cc188384817435870083e538a51ccdea04afc8aa Mon Sep 17 00:00:00 2001 From: forana Date: Tue, 2 Oct 2018 07:31:17 -0500 Subject: [PATCH 1/3] allow custom scripts or commands --- README.md | 15 +++++++++++++++ docker-compose.yml | 1 + wazuh/config/entrypoint.sh | 12 ++++++++++++ 3 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 963c2cb2..ec20f8a9 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,21 @@ Identified Wazuh configuration files to mount... '/wazuh-config-mount/etc/shared/default/agent.conf' -> '/var/ossec/data/etc/shared/default/agent.conf' ``` +## Custom commands/scripts + +To execute commands in the Wazuh manager container after configuration is placed but _before_ the +Wazuh API and manager are started, pass the commands as the docker commands/arguments: + +```sh +docker run -it --rm wazuh/wazuh:latest "echo 'hello world'" "uname -m" "ls /var/ossec" +``` + +A more real-world example: + +```sh +docker run -it --rm wazuh/wazuh:latest "/var/ossec/bin/ossec-control enable debug" +``` + ## More documentation * [Wazuh full documentation](http://documentation.wazuh.com) diff --git a/docker-compose.yml b/docker-compose.yml index 1bbdc2c6..a488de04 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,7 @@ services: # - my-path:/etc/postfix:Z # - my-path:/etc/filebeat # - my-custom-config-path/ossec.conf:/wazuh-config-mount/etc/ossec.conf +# command: ["echo 'hello world'"] depends_on: - logstash logstash: diff --git a/wazuh/config/entrypoint.sh b/wazuh/config/entrypoint.sh index b1fbab6e..1606404b 100644 --- a/wazuh/config/entrypoint.sh +++ b/wazuh/config/entrypoint.sh @@ -113,4 +113,16 @@ trap "ossec_shutdown; exit" SIGINT SIGTERM chmod -R g+rw ${DATA_PATH} +############################################################################## +# Interpret any passed arguments (via docker command to this entrypoint) as +# paths or commands, and execute them. +# +# This can be useful for actions that need to be run before the services are +# started, such as "/var/ossec/bin/ossec-control enable agentless". +############################################################################## +for CUSTOM_COMMAND in "$@" +do + exec_cmd_stdout "${CUSTOM_COMMAND}" +done + /sbin/my_init From b027b32a348b7801356e42a64903aa26f89a8d33 Mon Sep 17 00:00:00 2001 From: migruiz4 Date: Fri, 19 Oct 2018 13:54:12 -0500 Subject: [PATCH 2/3] add output for custom command execution Co-Authored-By: forana --- wazuh/config/entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wazuh/config/entrypoint.sh b/wazuh/config/entrypoint.sh index 1606404b..9960d8d8 100644 --- a/wazuh/config/entrypoint.sh +++ b/wazuh/config/entrypoint.sh @@ -122,6 +122,9 @@ chmod -R g+rw ${DATA_PATH} ############################################################################## for CUSTOM_COMMAND in "$@" do + echo "Executing command \`${CUSTOM_COMMAND}\`" + exec_cmd_stdout "${CUSTOM_COMMAND}" +done exec_cmd_stdout "${CUSTOM_COMMAND}" done From e373fac732e8446ecf20aaeab2491125d1ffb23e Mon Sep 17 00:00:00 2001 From: forana Date: Mon, 22 Oct 2018 09:20:52 -0500 Subject: [PATCH 3/3] fixed duplication --- wazuh/config/entrypoint.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/wazuh/config/entrypoint.sh b/wazuh/config/entrypoint.sh index 9960d8d8..df3266e4 100644 --- a/wazuh/config/entrypoint.sh +++ b/wazuh/config/entrypoint.sh @@ -125,7 +125,5 @@ do echo "Executing command \`${CUSTOM_COMMAND}\`" exec_cmd_stdout "${CUSTOM_COMMAND}" done - exec_cmd_stdout "${CUSTOM_COMMAND}" -done /sbin/my_init