Skip to content

Instantly share code, notes, and snippets.

@scottsweb
Last active August 31, 2015 20:07
Show Gist options
  • Select an option

  • Save scottsweb/39143a93c11af4a13ddb to your computer and use it in GitHub Desktop.

Select an option

Save scottsweb/39143a93c11af4a13ddb to your computer and use it in GitHub Desktop.

Revisions

  1. scottsweb revised this gist Aug 31, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions unicorn
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,12 @@ PIDFILE=/var/run/unicorn.pid
    case "$1" in
    start)
    log_daemon_msg "Starting daemon" "$NAME"

    if [ ! -f "$LOG" ]; then
    touch $LOG
    chown $USER $LOG
    fi

    start-stop-daemon --start --background --quiet \
    --chuid $USER \
    --make-pidfile --pidfile $PIDFILE \
  2. scottsweb created this gist Aug 25, 2015.
    44 changes: 44 additions & 0 deletions unicorn
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #!/bin/bash
    ### BEGIN INIT INFO
    # Provides: unicorn
    # Required-Start: $local_fs $remote_fs $network
    # Required-Stop: $local_fs $remote_fs $network
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start or stop the unicorn hat server
    ### END INIT INFO

    USER=root
    NAME=unicorn
    SCRIPT="/home/scott/unicorn/server.py"
    LOG='/var/log/unicorn.log'
    PIDFILE=/var/run/unicorn.pid

    . /lib/lsb/init-functions

    case "$1" in
    start)
    log_daemon_msg "Starting daemon" "$NAME"
    start-stop-daemon --start --background --quiet \
    --chuid $USER \
    --make-pidfile --pidfile $PIDFILE \
    --startas /bin/bash -- -c "exec python $SCRIPT >> $LOG 2>&1"
    log_end_msg 0
    ;;
    stop)
    log_daemon_msg "Stopping daemon" "$NAME"
    pkill -f $SCRIPT
    rm -f $PIDFILE
    sleep 1
    log_end_msg 0
    ;;
    restart)
    $0 stop
    sleep 5
    $0 start
    ;;
    *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    esac
    exit 0