diff --git a/scripts/rest-api.sh b/scripts/rest-api.sh index 78ff833..2aef6d4 100755 --- a/scripts/rest-api.sh +++ b/scripts/rest-api.sh @@ -1,17 +1,16 @@ #!/bin/bash cd /srv/analysis/rest-api -echo "Running $0 in `pwd`" +echo "Running $0 in `pwd` with argument: $1" -set -e -set -x +set -e # Exit on error +set -x # Print commands for debugging # Start the MariaDB service service mariadb start service mariadb status &> /dev/null -# Configure the MariaDB database using compatible commands -# Update the root password and create the `analysis` database and tables +# Configure the MariaDB database and create necessary tables mysql -u root << SQLCOMMANDS || true ALTER USER 'root'@'localhost' IDENTIFIED BY 'toor'; FLUSH PRIVILEGES; @@ -45,15 +44,22 @@ CREATE TABLE IF NOT EXISTS debug ( ); SQLCOMMANDS - -# Install dependencies for the REST API using npm +# Install dependencies npm install -# Start the REST API using Node.js directly instead of systemd -# This step replaces `systemctl` usage since Docker containers typically don't use systemd -node index.js debug +# Use the first argument to determine which mode to start +echo "DEBUG_MODE is set to: '$DEBUG_MODE'" + +if [ "$DEBUG_MODE" = "true" ]; then + echo "Starting API in debug mode..." + node index.js debug +else + echo "Starting API in normal mode..." + node index.js +fi -set +x +set +x echo '--------------------------------------------------' echo "REST API started at http://localhost:8080/analysis" echo '--------------------------------------------------' + diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index 25b7bf2..0000000 --- a/scripts/test.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -trap popd EXIT -pushd $PWD &> /dev/null -cd $(dirname "$0") -cd .. - -dockerfail() { - echo "Docker not found. Check that Docker is installed and running." - exit 1 -} -docker ps &> /dev/null || dockerfail - -set -e -set -x - -#clean logs -rm -r ./logs || true -mkdir -p ./logs - -docker stop crawl_test || true -docker rm crawl_test || true -docker build --tag=crawl_test . &> build.log -docker run -d --name crawl_test --privileged \ - -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ - -v "$(pwd)":/srv/analysis \ - -p 5901:5901 \ - -p 6901:6901 \ - -p 8080:8080 \ - --user 0 \ - crawl_test || true diff --git a/scripts/webcrawler.sh b/scripts/webcrawler.sh new file mode 100755 index 0000000..6036178 --- /dev/null +++ b/scripts/webcrawler.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +trap popd EXIT +pushd $PWD &> /dev/null +cd $(dirname "$0") +cd .. + +# Check if Docker is installed and running +dockerfail() { + echo "Docker not found. Check that Docker is installed and running." + exit 1 +} +docker ps &> /dev/null || dockerfail + +set -e # Exit on errors +set -x # Print commands for debugging + +# Clean logs +rm -r ./logs || true +mkdir -p ./logs + +# Stop and remove the old container if it exists +docker stop crawl_test || true +docker rm crawl_test || true + +# Build the Docker image +docker build --tag=crawl_test . &> build.log + +# Check if the user provided the 'debug' argument +if [[ "$1" == "debug" ]]; then + DEBUG_MODE="true" + echo "Starting container with debugging enabled." +else + DEBUG_MODE="false" + echo "Starting container without debugging." +fi + +# Run the Docker container with the DEBUG_MODE environment variable +docker run -d --name crawl_test --privileged \ + -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ + -v "$(pwd)":/srv/analysis \ + -p 5901:5901 \ + -p 6901:6901 \ + -p 8080:8080 \ + -e DEBUG_MODE=$DEBUG_MODE \ + --user 0 \ + crawl_test || true diff --git a/supervisord.conf b/supervisord.conf index 1d10680..bfceab8 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -2,7 +2,7 @@ nodaemon=true [program:restapi] -command=sh /srv/analysis/scripts/rest-api.sh +command=sh /srv/analysis/scripts/rest-api.sh ${DEBUG_MODE} stdout_logfile=/srv/analysis/logs/restapi.log stderr_logfile=/srv/analysis/logs/restapi.error.log autostart=true