#!/bin/sh

case "$1" in
    'start')
        sudo -H -u wildfly bash -c '/opt/codiki/bin/codiki.sh start'
        ;;
    'stop')
        sudo -H -u wildfly bash -c '/opt/codiki/bin/codiki.sh stop'
        ;;
    'status')
        sudo -H -u wildfly bash -c '/opt/codiki/bin/codiki.sh status'
        ;;
    'restart')
        sudo -H -u wildfly bash -c '/opt/codiki/bin/codiki.sh restart'
        ;;
    *)
        # If no argument, we launch the app in case of server startup
        sudo -H -u wildfly bash -c '/opt/codiki/bin/codiki.sh start &>/dev/null'
        # And show the script usage
        echo "Usage: /etc/init.d/codiki {start|stop|status|restart}\n" >&2
        exit 3
        ;;
esac
exit 0