#! /bin/bash

if [ $1 == "start" ]; then 
    # Change the file ownership back to drydock user. This is 
    # necessary since the host may not have the drydock user. 
    chown -R drydock:drydock $MONGO_DATA
    chown -R drydock:drydock $MONGO_LOG

    # Start the mongo server
    su drydock -c '/usr/bin/mongod --fork --logpath $MONGO_LOG --dbpath $MONGO_DATA --smallfiles'

    # Start the ssh server in the foreground
    /usr/sbin/sshd -D
elif [ $1 == "stop" ]; then 
    # Shutdown MongoDB. 
    su drydock -c '/usr/bin/mongod --shutdown'

    # Killing the ssh daemon should automatically exit the container,
    # since the sshd is the only thing running in the foreground. 
    pkill -f sshd
fi