#!/bin/bash

function create_fuse_dev {
    # We'll need to create /dev/fuse since we removed 
    # it during the installation (since build doesn't support
    # privileged operations)
    if [ ! -e /dev/fuse ]; then
	mknod /dev/fuse c 10 229
    fi
}

if [ $1 == "start" ]; then 
    # Configure the master node. 
    /service/configuration/configure start
elif [ $1 == "listen" ]; then 
    create_fuse_dev
    cat /service/keys/id_rsa.pub >> /root/.ssh/authorized_keys
    /usr/sbin/glusterd &
    /usr/sbin/sshd -D
elif [ $1 == "stop" ]; then 
    # Stop the gluster volume
    /service/configuration/configure stop

    # Stop the gluster daemon
    pkill -f glusterd

    # Now stop the ssh daemon. 
    pkill -f sshd
elif [ $1 == "clean" ]; then 
    /service/configuration/configure clean    
fi
