Skip to content

Instantly share code, notes, and snippets.

@monobilisim
Created January 19, 2017 01:46
Show Gist options
  • Select an option

  • Save monobilisim/071a3a9bdc0455902a5966a07a33987c to your computer and use it in GitHub Desktop.

Select an option

Save monobilisim/071a3a9bdc0455902a5966a07a33987c to your computer and use it in GitHub Desktop.

Revisions

  1. monobilisim created this gist Jan 19, 2017.
    85 changes: 85 additions & 0 deletions caddy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,85 @@
    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides: caddy
    # 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
    # Short-Description: starts the caddy web server
    # Description: starts caddy using start-stop-daemon
    ### END INIT INFO

    # Original Author: Frédéric Galusik (fredg)
    # Maintainer: Daniel van Dorp (djvdorp)
    # Modified by: Mono Bilişim (monobilisim)
    ## yum install -y daemonize

    DESC="the caddy web server"
    NAME=caddy
    DAEMON=$(which caddy)

    DAEMONUSER=webapps
    EMAIL=root@localhost
    PIDFILE=/var/run/$NAME.pid
    LOCKFILE=/var/lock/subsys/$NAME
    LOGFILE=/var/log/caddy/$NAME.log
    CONFIGFILE=/etc/caddy/Caddyfile
    DAEMONOPTS="-agree=true -email=$EMAIL -pidfile=$PIDFILE -log=$LOGFILE -conf=$CONFIGFILE"

    USERBIND="setcap cap_net_bind_service=+ep"
    STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"

    test -x $DAEMON || exit 0

    # Set the CADDYPATH; Let's Encrypt certificates will be written to this directory.
    export CADDYPATH=/etc/caddy/ssl

    # Set the ulimits
    ulimit -n 8192

    start() {
    $USERBIND $DAEMON
    daemonize -p $PIDFILE -l $LOCKFILE $DAEMON $DAEMONOPTS
    }

    stop() {
    kill -9 $(cat "$PIDFILE")
    rm -f $PIDFILE $LOCKFILE
    }

    status() {
    if [ -f $PIDFILE ]; then
    if kill -0 $(cat "$PIDFILE"); then
    echo "$NAME is running"
    else
    echo "$NAME process is dead, but pidfile exists"
    fi
    else
    echo "$NAME is not running"
    fi
    }

    case "$1" in
    start)
    echo "Starting $NAME"
    start
    ;;
    stop)
    echo "Stopping $NAME"
    stop
    ;;
    restart)
    echo "Restarting $NAME"
    stop
    start
    ;;
    status)
    status
    ;;
    *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 2
    ;;
    esac

    exit 0