github.com/rpdict/ponzu@v0.10.1-0.20190226054626-477f29d6bf5e/docs/src/System-Deployment/SysV-Style.md (about)

     1  title: Deploying Ponzu on Linux with System-V style init
     2  
     3  For reference, here is an example init script to run Ponzu servers. You must 
     4  define the `PROJECT_DIR` & `RUNAS` variables by replacing `<PROJECT DIRECTORY>`
     5  & `<USER>` in the script below:
     6  
     7  ```bash
     8  #!/bin/sh
     9  ### BEGIN INIT INFO
    10  # Provides:          ponzu-server
    11  # Required-Start:    $local_fs $network $named $time $syslog
    12  # Required-Stop:     $local_fs $network $named $time $syslog
    13  # Default-Start:     2 3 4 5
    14  # Default-Stop:      0 1 6
    15  # Description:       Ponzu API & Admin server
    16  ### END INIT INFO
    17  
    18  PROJECT_DIR=<PROJECT DIRECTORY>
    19  SCRIPT='cd $PROJECT_DIR && ponzu run --port=80' # add --https here to get TLS/HTTPS
    20  RUNAS=<USER>
    21  
    22  PIDFILE=/var/run/ponzu-server.pid
    23  LOGFILE=/var/log/ponzu-server.log
    24  
    25  start() {
    26    if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
    27      echo 'Service already running' >&2
    28      return 1
    29    fi
    30    echo 'Starting serviceā€¦' >&2
    31    local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
    32    su -c "$CMD" $RUNAS > "$PIDFILE"
    33    echo 'Service started' >&2
    34  }
    35  
    36  stop() {
    37    if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
    38      echo 'Service not running' >&2
    39      return 1
    40    fi
    41    echo 'Stopping serviceā€¦' >&2
    42    kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
    43    echo 'Service stopped' >&2
    44  }
    45  
    46  uninstall() {
    47    echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
    48    local SURE
    49    read SURE
    50    if [ "$SURE" = "yes" ]; then
    51      stop
    52      rm -f "$PIDFILE"
    53      echo "Notice: log file is not be removed: '$LOGFILE'" >&2
    54      update-rc.d -f <NAME> remove
    55      rm -fv "$0"
    56    fi
    57  }
    58  
    59  case "$1" in
    60    start)
    61      start
    62      ;;
    63    stop)
    64      stop
    65      ;;
    66    uninstall)
    67      uninstall
    68      ;;
    69    restart)
    70      stop
    71      start
    72      ;;
    73    *)
    74      echo "Usage: $0 {start|stop|restart|uninstall}"
    75  esac
    76  ```