#!/bin/bash

#!/bin/bash
#
# This is Server Emulator script for controlling vsftpd FTP server in either service mode or
# as a daemon in separated network namespace
#
CMD=$1
NS_NAME=$2
PROCESS_NAME=bind9

case $CMD in
start)
    systemctl start $PROCESS_NAME.service
    ERROR=$?
    ;;
stop)
    systemctl stop $PROCESS_NAME.service
    ERROR=$?
    ;;
restart)
    systemctl restart $PROCESS_NAME.service
    ERROR=$?
    ;;
status)
    systemctl status $PROCESS_NAME.service
    ERROR=$?
    ;;
startnetns)
    ip netns exec $NS_NAME vsftpd
    ERROR=$?
    ;;
stopnetns)
    killall -s TERM $PROCESS_NAME
    if [ $? -ne 0 ]; then
	killall -s KILL $PROCESS_NAME
    fi
    ERROR=$?
    ;;
statusnetns)
    # Output of the following echo command is processed programatically by Server Emulator to find out if the server is running
    echo $(pgrep -x $PROCESS_NAME)
    ERROR=$?
    ;;
*)
    ERROR=1
esac
exit $ERROR