Nefarious Threats Hark, noble coder, a tale of valor unfolds before thee. In the vast…
- User
Nefarious Threats Hark, noble coder, a tale of valor unfolds before thee. In the vast kingdom of Databasia, a precious MongoDB server must be summoned upon thy local machine, its port numbered 27020. The realm demands that this server be fortified with the armor of TLS connections, shielding it from the nefarious threats lurking in the shadows. To achieve this, thou must inscribe within the sacred environment variables MONGO_TLS_CA_FILE_PATH and MONGO_TLS_CERT_KEY_PATH the paths to the revered TLS certificate authority file and a certificate key file, respectively. Take up this quest with the utmost precision, ensuring the sanctity and security of the server remains unbreached. The kingdom's trust lies in thy skilled hands. Constraints The script must be purely written in bash within the execute.sh file Output / Evaluation Criteria A mongodb server must be running on port 27020 with TLS enabled and connections to it must succeed.
- Assistant
#!/bin/bash # Ensure environment variables are set if [[ -z "$MONGO_TLS_CA_FILE_PATH" ]] || [[ -z "$MONGO_TLS_CERT_KEY_PATH" ]]; then echo "Environment variables MONGO_TLS_CA_FILE_PATH and MONGO_TLS_CERT_KEY_PATH must be set." exit 1 fi # Ensure the TLS files exist if [[ ! -f "$MONGO_TLS_CA_FILE_PATH" ]]; then echo "TLS CA file not found at: $MONGO_TLS_CA_FILE_PATH" exit 1 fi if [[ ! -f "$MONGO_TLS_CERT_KEY_PATH" ]]; then echo "TLS certificate key file not found at: $MONGO_TLS_CERT_KEY_PATH" exit 1 fi # Create a data directory for MongoDB DATA_DIR="./data/db27020" mkdir -p "$DATA_DIR" # Start MongoDB server with TLS enabled mongod \ --port 27020 \ --dbpath "$DATA_DIR" \ --tlsMode requireTLS \ --tlsCAFile "$MONGO_TLS_CA_FILE_PATH" \ --tlsCertificateKeyFile "$MONGO_TLS_CERT_KEY_PATH" \ --bind_ip localhost \ --fork \ --logpath "$DATA_DIR/mongod.log" # Check if MongoDB started successfully if [[ $? -ne 0 ]]; then echo "Failed to start MongoDB server." exit 1 fi echo "MongoDB server is running on port 27020 with TLS enabled."