Skip to content

Instantly share code, notes, and snippets.

@tstivers1990
Forked from ridercz/kestrel_service.sh
Last active February 19, 2025 22:32
Show Gist options
  • Select an option

  • Save tstivers1990/c92b4ff5fc4cf859f9f3 to your computer and use it in GitHub Desktop.

Select an option

Save tstivers1990/c92b4ff5fc4cf859f9f3 to your computer and use it in GitHub Desktop.

Revisions

  1. tstivers1990 revised this gist Oct 21, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion kestrel_service.sh
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,8 @@

    # Author: Ivan Derevianko aka druss <[email protected]>
    # Fixed for ASP.NET 5 beta 7 with DNVM/DNX by Michal A. Valasek - github.com/ridercz
    # Added support for dnx-watch added with ASP.NET 5 beta 8 by Anthony Stivers - github.com/tstivers1990
    # Added support for dnx-watch added with ASP.NET 5 beta 8, improved configurability,
    # fixed 'nohup: ignoring input and redirecting stderr to stdout' message when starting - Anthony Stivers (github.com/tstivers1990)

    # Set path variable so that dnx-watch can find dnx

  2. tstivers1990 revised this gist Oct 21, 2015. 1 changed file with 17 additions and 6 deletions.
    23 changes: 17 additions & 6 deletions kestrel_service.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides: <SCRIPT_NAME>
    # Provides: <SERVICE_NAME>
    # Required-Start: $local_fs $network $named $time $syslog
    # Required-Stop: $local_fs $network $named $time $syslog
    # Default-Start: 2 3 4 5
    @@ -10,10 +10,21 @@

    # Author: Ivan Derevianko aka druss <[email protected]>
    # Fixed for ASP.NET 5 beta 7 with DNVM/DNX by Michal A. Valasek - github.com/ridercz
    # Added support for dnx-watch added with ASP.NET 5 beta 8 by Anthony Stivers - github.com/tstivers1990

    WWW_USER=<USERNAME>
    DNXRUNTIME=<PATH_TO_RUNTIME> #/home/$WWW_USER/.dnx/runtimes/dnx-mono.1.0.0-beta7/bin/dnx
    APPROOT=<PATH_TO_APPLICATION> #/home/$WWW_USER/vNext/mvc/HelloMvc
    # Set path variable so that dnx-watch can find dnx

    WWW_USER=<WWW_USER>

    # We can use either dnx or dnx-watch here
    DNXRUNTIME=dnx-watch
    DNXFRAMEWORK=mono
    DNXVERSION=1.0.0-beta8
    DNXCOMMAND=kestrel

    APPROOT=/home/$WWW_USER/<APPROOT>

    DNXPATHS=/home/$WWW_USER/.dnx/runtimes/dnx-$DNXFRAMEWORK.$DNXVERSION/bin:/home/$WWW_USER/.dnx/bin

    PIDFILE=$APPROOT/kestrel.pid
    LOGFILE=$APPROOT/kestrel.log
    @@ -28,7 +39,7 @@ start() {
    return 1
    fi
    echo 'Starting service...' >&2
    su -c "start-stop-daemon -SbmCv -x /usr/bin/nohup -p \"$PIDFILE\" -d \"$APPROOT\" -- \"$DNXRUNTIME\" kestrel > \"$LOGFILE\"" $WWW_USER
    su -c "export PATH=$DNXPATHS:\${PATH} && start-stop-daemon -SbmCv -x /usr/bin/nohup -p \"$PIDFILE\" -d \"$APPROOT\" -- \"$DNXRUNTIME\" $DNXCOMMAND > \"$LOGFILE\" 2>&1" $WWW_USER
    echo 'Service started' >&2
    }

    @@ -58,4 +69,4 @@ case "$1" in
    echo "Usage: $0 {start|stop|restart}"
    esac

    export runlevel=$TMP_SAVE_runlevel_VAR
    export runlevel=$TMP_SAVE_runlevel_VAR
  3. @ridercz ridercz revised this gist Oct 9, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions kestrel_service.sh
    Original file line number Diff line number Diff line change
    @@ -9,10 +9,10 @@
    ### END INIT INFO

    # Author: Ivan Derevianko aka druss <[email protected]>
    # Fixed for ASP.NET 5 beta 5 with DNVM/DNX by Michal A. Valasek - github.com/ridercz
    # Fixed for ASP.NET 5 beta 7 with DNVM/DNX by Michal A. Valasek - github.com/ridercz

    WWW_USER=<USERNAME>
    DNXRUNTIME=<PATH_TO_RUNTIME> #/home/$WWW_USER/.dnx/runtimes/dnx-mono.1.0.0-beta5/bin/dnx
    DNXRUNTIME=<PATH_TO_RUNTIME> #/home/$WWW_USER/.dnx/runtimes/dnx-mono.1.0.0-beta7/bin/dnx
    APPROOT=<PATH_TO_APPLICATION> #/home/$WWW_USER/vNext/mvc/HelloMvc

    PIDFILE=$APPROOT/kestrel.pid
    @@ -28,7 +28,7 @@ start() {
    return 1
    fi
    echo 'Starting service...' >&2
    su -c "start-stop-daemon -SbmCv -x /usr/bin/nohup -p \"$PIDFILE\" -d \"$APPROOT\" -- \"$DNXRUNTIME\" . kestrel > \"$LOGFILE\"" $WWW_USER
    su -c "start-stop-daemon -SbmCv -x /usr/bin/nohup -p \"$PIDFILE\" -d \"$APPROOT\" -- \"$DNXRUNTIME\" kestrel > \"$LOGFILE\"" $WWW_USER
    echo 'Service started' >&2
    }

  4. @ridercz ridercz revised this gist Jul 13, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions kestrel_service.sh
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,10 @@
    ### END INIT INFO

    # Author: Ivan Derevianko aka druss <[email protected]>
    # Fixed for ASP.NET 5 beta 5 with DNVM/DNX by Michal A. Valasek - github.com/ridercz

    WWW_USER=<USERNAME>
    DNXRUNTIME=<PATH_TO_RUNTIME> #/home/$WWW_USER/.k/runtimes/kre-mono.1.0.0-beta3/bin/k
    DNXRUNTIME=<PATH_TO_RUNTIME> #/home/$WWW_USER/.dnx/runtimes/dnx-mono.1.0.0-beta5/bin/dnx
    APPROOT=<PATH_TO_APPLICATION> #/home/$WWW_USER/vNext/mvc/HelloMvc

    PIDFILE=$APPROOT/kestrel.pid
    @@ -27,7 +28,7 @@ start() {
    return 1
    fi
    echo 'Starting service...' >&2
    su -c "start-stop-daemon -SbmCv -x /usr/bin/nohup -p \"$PIDFILE\" -d \"$APPROOT\" -- \"$DNXRUNTIME\" kestrel > \"$LOGFILE\"" $WWW_USER
    su -c "start-stop-daemon -SbmCv -x /usr/bin/nohup -p \"$PIDFILE\" -d \"$APPROOT\" -- \"$DNXRUNTIME\" . kestrel > \"$LOGFILE\"" $WWW_USER
    echo 'Service started' >&2
    }

  5. @drussilla drussilla revised this gist Jun 12, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kestrel_service.sh
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ start() {
    echo 'Service already running' >&2
    return 1
    fi
    echo 'Starting service' >&2
    echo 'Starting service...' >&2
    su -c "start-stop-daemon -SbmCv -x /usr/bin/nohup -p \"$PIDFILE\" -d \"$APPROOT\" -- \"$DNXRUNTIME\" kestrel > \"$LOGFILE\"" $WWW_USER
    echo 'Service started' >&2
    }
    @@ -36,7 +36,7 @@ stop() {
    echo 'Service not running' >&2
    return 1
    fi
    echo 'Stopping service' >&2
    echo 'Stopping service...' >&2
    start-stop-daemon -K -p "$PIDFILE"
    rm -f "$PIDFILE"
    echo 'Service stopped' >&2
  6. @drussilla drussilla revised this gist Jun 12, 2015. 1 changed file with 11 additions and 6 deletions.
    17 changes: 11 additions & 6 deletions kestrel_service.sh
    Original file line number Diff line number Diff line change
    @@ -2,29 +2,32 @@
    ### BEGIN INIT INFO
    # Provides: <SCRIPT_NAME>
    # Required-Start: $local_fs $network $named $time $syslog
    # Required-Stop:
    # Required-Stop: $local_fs $network $named $time $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Description: Script to run asp.net 5 application in background
    ### END INIT INFO

    # Author: Ivan Derevianko aka druss <[email protected]>

    USER=<USERNAME> #kestrel
    DNXRUNTIME=<PATH_TO_RUNTIME> #/home/$USER/.k/runtimes/kre-mono.1.0.0-beta3/bin/k
    APPROOT=<PATH_TO_APPLICATION> #/home/$USER/mvc/HelloMvc
    WWW_USER=<USERNAME>
    DNXRUNTIME=<PATH_TO_RUNTIME> #/home/$WWW_USER/.k/runtimes/kre-mono.1.0.0-beta3/bin/k
    APPROOT=<PATH_TO_APPLICATION> #/home/$WWW_USER/vNext/mvc/HelloMvc

    PIDFILE=$APPROOT/kestrel.pid
    LOGFILE=$APPROOT/kestrel.log

    # fix issue with DNX exception in case of two env vars with the same name but different case
    TMP_SAVE_runlevel_VAR=$runlevel
    unset runlevel

    start() {
    if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
    echo 'Service already running' >&2
    return 1
    fi
    echo 'Starting service…' >&2
    su -c "start-stop-daemon -SbmCv -x /usr/bin/nohup -p \"$PIDFILE\" -d \"$APPROOT\" -- \"$DNXRUNTIME\" kestrel > \"$LOGFILE\"" $USER
    su -c "start-stop-daemon -SbmCv -x /usr/bin/nohup -p \"$PIDFILE\" -d \"$APPROOT\" -- \"$DNXRUNTIME\" kestrel > \"$LOGFILE\"" $WWW_USER
    echo 'Service started' >&2
    }

    @@ -52,4 +55,6 @@ case "$1" in
    ;;
    *)
    echo "Usage: $0 {start|stop|restart}"
    esac
    esac

    export runlevel=$TMP_SAVE_runlevel_VAR
  7. @drussilla drussilla revised this gist Jun 12, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kestrel_service.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    ### BEGIN INIT INFO
    # Provides: <SCRIPT_NAME>
    # Required-Start: $local_fs $network $named $time $syslog
    # Required-Stop: $local_fs $network $named $time $syslog
    # Required-Stop:
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Description: Script to run asp.net 5 application in background
  8. @drussilla drussilla revised this gist Jun 12, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kestrel_service.sh
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@

    # Author: Ivan Derevianko aka druss <[email protected]>

    USER=<USERNAME>
    USER=<USERNAME> #kestrel
    DNXRUNTIME=<PATH_TO_RUNTIME> #/home/$USER/.k/runtimes/kre-mono.1.0.0-beta3/bin/k
    APPROOT=<PATH_TO_APPLICATION> #/home/$USER/mvc/HelloMvc

  9. @drussilla drussilla created this gist Jun 12, 2015.
    55 changes: 55 additions & 0 deletions kestrel_service.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides: <SCRIPT_NAME>
    # Required-Start: $local_fs $network $named $time $syslog
    # Required-Stop: $local_fs $network $named $time $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Description: Script to run asp.net 5 application in background
    ### END INIT INFO

    # Author: Ivan Derevianko aka druss <[email protected]>

    USER=<USERNAME>
    DNXRUNTIME=<PATH_TO_RUNTIME> #/home/$USER/.k/runtimes/kre-mono.1.0.0-beta3/bin/k
    APPROOT=<PATH_TO_APPLICATION> #/home/$USER/mvc/HelloMvc

    PIDFILE=$APPROOT/kestrel.pid
    LOGFILE=$APPROOT/kestrel.log


    start() {
    if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
    echo 'Service already running' >&2
    return 1
    fi
    echo 'Starting service…' >&2
    su -c "start-stop-daemon -SbmCv -x /usr/bin/nohup -p \"$PIDFILE\" -d \"$APPROOT\" -- \"$DNXRUNTIME\" kestrel > \"$LOGFILE\"" $USER
    echo 'Service started' >&2
    }

    stop() {
    if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
    echo 'Service not running' >&2
    return 1
    fi
    echo 'Stopping service…' >&2
    start-stop-daemon -K -p "$PIDFILE"
    rm -f "$PIDFILE"
    echo 'Service stopped' >&2
    }

    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    stop
    start
    ;;
    *)
    echo "Usage: $0 {start|stop|restart}"
    esac