Caddy: Documentation: Add a section on starting Caddy as a service

Created on 6 Feb 2016  路  2Comments  路  Source: caddyserver/caddy

The web site contains information on running Caddy in the foreground as a user process. I think that it would be helpful to document running is as a background service.

Maybe include an example /etc/init.d/caddyd script:

#!/bin/bash
#
# source in standard functions
#
. /etc/init.d/functions

SYSCFG=caddy
EMAILADDR='[email protected]'
TITLE="Caddy Web Server"

DAEMON=/usr/local/bin/caddy
DAEMON_CFGFILE=/home/caddy/Caddyfile
DAEMON_DIR=/home/caddy
DAEMON_PIDFILE=/home/caddy/Caddyfile.pid
DAEMON_USER=caddy

if [ -f /etc/sysconfig/${SYSCFG} ]; then
  . /etc/sysconfig/${SYSCFG}
fi

start() {
  cd "${DAEMON_DIR}"
  echo $"Starting ${TITLE}: "
  if [ -f "${DAEMON_PIDFILE}" ]; then
    PID=$( cat "${DAEMON_PIDFILE}" )
    echo "${DAEMON} already running: ${PID}"
    exit 2
  fi
  daemon --user="${DAEMON_USER}" --pidfile="${DAEMON_PIDFILE}" "${DAEMON} -quiet=true -conf='${DAEMON_CFGFILE}' -pidfile='${DAEMON_PIDFILE}' -agree=true -email='${EMAILADDR}' &"
  RETVAL=$?
  echo "done."
  echo
  return ${RETVAL}
}

stop() {
  echo $"Shutting down ${TITLE}: "
  killproc -p "${DAEMON_PIDFILE}" "${DAEMON}"
  echo "done."
  return 0
}

case "$1" in
    start) start ;;
     stop) stop ;;
   status) status "${DAEMON}" ;;
  restart) stop ; start ;;
        *) echo $"Usage: {start|stop|status|restart}" ; exit 1 ;;
esac
exit $?
documentation

Most helpful comment

@mholt I agree caddy is just a web server but i beg to differ from your opinion. Caddy mentions

Easy on Beginners

As one of the main features in its site. So a beginner will not have experience as a seasoned sysadmin, Though there are several community scripts I would rather prefer Caddy approved init.d/systemd service script than from a random persons "hack". a web server needs to start with system, just because some is a beginner I don;t think he must ssh into server after every restart/failure and run Caddy manually, atleast Caddy must work with community and release an officially supported way to make caddy work seamlessly. Caddy community is quite active and I think they will help you in this. This is just my opinion.

All 2 comments

I have mixed feelings about documenting how to run Caddy in different environments and with different process managers because they're all outside the scope of Caddy. Caddy is a web server, and these are sysadmin issues.

So they won't be added to the Caddy website/docs, although we do have https://github.com/caddyserver/examples that people are welcome to contribute to, or perhaps the developer wiki (the wiki on this project).

@mholt I agree caddy is just a web server but i beg to differ from your opinion. Caddy mentions

Easy on Beginners

As one of the main features in its site. So a beginner will not have experience as a seasoned sysadmin, Though there are several community scripts I would rather prefer Caddy approved init.d/systemd service script than from a random persons "hack". a web server needs to start with system, just because some is a beginner I don;t think he must ssh into server after every restart/failure and run Caddy manually, atleast Caddy must work with community and release an officially supported way to make caddy work seamlessly. Caddy community is quite active and I think they will help you in this. This is just my opinion.

Was this page helpful?
0 / 5 - 0 ratings