Skip to content

Commit

Permalink
Issue #98 - Added optionality for debugging mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattm27 committed Oct 26, 2024
1 parent ccee821 commit 674df1e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 43 deletions.
28 changes: 17 additions & 11 deletions scripts/rest-api.sh
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 '--------------------------------------------------'

31 changes: 0 additions & 31 deletions scripts/test.sh

This file was deleted.

47 changes: 47 additions & 0 deletions scripts/webcrawler.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 674df1e

Please sign in to comment.