diff --git a/README.md b/README.md index 55780d5e..a84436cd 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 bad7fa42..617f79d8 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..df3266e4 100644 --- a/wazuh/config/entrypoint.sh +++ b/wazuh/config/entrypoint.sh @@ -113,4 +113,17 @@ 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 + echo "Executing command \`${CUSTOM_COMMAND}\`" + exec_cmd_stdout "${CUSTOM_COMMAND}" +done + /sbin/my_init