========
tempalte
========

Lets create a minimal `buildout.cfg` file but first create a supervisor.conf
file. We normaly do this with the p01.recipe.setup:templete recipe::

  >>> write('sample-supervisord.conf',
  ... '''#
  ... # supervisor configuration dummy
  ... ''')

Now define the buildout.cfg file. Note that we do not create the conf file.
This should be done with the p01.recipe.setup:template recipe::

  >>> write('buildout.cfg',
  ... '''
  ... [buildout]
  ... parts = supervisor
  ...
  ... [supervisor]
  ... recipe = p01.recipe.setup:supervisor
  ... user = sample
  ... password = secret
  ... conf = sample-supervisord.conf
  ... generate-initd-script = true
  ... ''')

Now we can run buildout::

  >>> print system(buildout)
  Installing supervisor.
  Generated script '/sample-buildout/bin/supervisord'.
  Generated script '/sample-buildout/bin/supervisorctl'.

  >>> cat(sample_buildout, 'bin', 'supervisord')
  <BLANKLINE>
  import sys
  sys.path[0:0] = [
      '...supervisor-pyN.N.egg',
      '...meld3-pyN.N.egg',
      '/sample-pyN.N.egg',
      ]
  <BLANKLINE>
  <BLANKLINE>
  import sys; sys.argv.extend(["-c","sample-supervisord.conf"])
  <BLANKLINE>
  import supervisor.supervisord
  <BLANKLINE>
  if __name__ == '__main__':
      sys.exit(supervisor.supervisord.main())


  >>> cat(sample_buildout, 'bin', 'supervisorctl')
  <BLANKLINE>
  import sys
  sys.path[0:0] = [
      '...supervisor-pyN.N.egg',
      '...meld3-pyN.N.egg',
      '/sample-pyN.N.egg',
      ]
  <BLANKLINE>
  <BLANKLINE>
  import sys; sys.argv[1:1] = ["-c","sample-supervisord.conf","-u","sample","-p","secret","-s","http://127.0.0.1:9001"]
  <BLANKLINE>
  import supervisor.supervisorctl
  <BLANKLINE>
  if __name__ == '__main__':
      sys.exit(supervisor.supervisorctl.main(sys.argv[1:]))

  >>> ls(sample_buildout, 'bin')
  -  buildout-script.py
  -  buildout.exe
  -  supervisorctl-script.py
  -  supervisorctl.exe
  -  supervisord-script.py
  -  supervisord.exe

  >>> ls(sample_buildout, 'parts')
  d  buildout
  d  supervisor

  >>> ls(sample_buildout, 'parts', 'supervisor')
  -  supervisord-initd-script

  >>> cat(sample_buildout, 'parts', 'supervisor', 'supervisord-initd-script')
  #!/bin/sh
  ### BEGIN INIT INFO
  # Provides:          supervisor
  # Default-Start:     2 3 4 5
  # Default-Stop:      S 0 1 6
  # Short-Description: Starts/stops the supervisor daemon
  # Description:       This starts and stops the supervisor dameon
  #                    which is used to run and monitor arbitrary programs as
  #                    services, e.g. application servers etc.
  ### END INIT INFO
  <BLANKLINE>
  PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  DESC="supervisor daemon"
  NAME="supervisor"
  <BLANKLINE>
  ### GENERATED BY p01.recipe.setup:supervisor recipe
  DAEMON="/sample-buildout/bin/${NAME}d"
  SUPERVISORCTL="/sample-buildout/bin/${NAME}ctl"
  PIDFILE="/var/run/${NAME}d.pid"
  SCRIPTNAME="/etc/init.d/$NAME"
  CONFFILE="sample-supervisord.conf"
  ###
  <BLANKLINE>
  test -x "$DAEMON" || exit 0
  test -r "$CONFFILE" || exit 0
  <BLANKLINE>
  if [ -r "/etc/default/$NAME" ]; then
      . "/etc/default/$NAME"
  fi
  <BLANKLINE>
  set -e
  <BLANKLINE>
  d_start() {
      start-stop-daemon --start --quiet --pidfile "$PIDFILE" \
          --exec "$DAEMON" \
          || echo -n " already running"
  }
  <BLANKLINE>
  d_stop() {
      $SUPERVISORCTL shutdown
  }
  <BLANKLINE>
  d_reload() {
      $SUPERVISORCTL reload
  }
  <BLANKLINE>
  case "$1" in
    start)
      echo -n "Starting $DESC: $NAME"
      d_start
      echo "."
      ;;
    stop)
      echo -n "Stopping $DESC: $NAME"
      d_stop
      echo "."
      ;;
    reload|force-reload)
      echo -n "Reloading $DESC configuration..."
      d_reload
      echo "done."
    ;;
    restart)
      echo -n "Restarting $DESC: $NAME"
      d_stop
      sleep 1
      d_start
      echo "."
      ;;
    *)
      echo "Usage: "$SCRIPTNAME" {start|stop|restart|force-reload}" >&2
      exit 3
      ;;
  esac
  <BLANKLINE>
  exit 0
  <BLANKLINE>

We can also use plugins like superlance::

  >>> write('buildout.cfg',
  ... '''
  ... [buildout]
  ... parts = supervisor
  ...
  ... [supervisor]
  ... recipe = p01.recipe.setup:supervisor
  ... user = sample
  ... password = secret
  ... conf = sample-supervisord.conf
  ... generate-initd-script = true
  ... plugins = superlance
  ... ''')

  >>> print system(buildout)
  Uninstalling supervisor.
  Installing supervisor.
  Generated script '/sample-buildout/bin/supervisord'.
  Generated script '/sample-buildout/bin/supervisorctl'.
  Generated script '/sample-buildout/bin/httpok'.
  Generated script '/sample-buildout/bin/crashmailbatch'.
  Generated script '/sample-buildout/bin/memmon'.
  Generated script '/sample-buildout/bin/crashsms'.
  Generated script '/sample-buildout/bin/fatalmailbatch'.
  Generated script '/sample-buildout/bin/crashmail'.

  >>> ls(sample_buildout, 'bin')
  -  buildout
  -  crashmail
  -  crashmailbatch
  -  crashsms
  -  fatalmailbatch
  -  httpok
  -  memmon
  -  supervisorctl
  -  supervisord

Update will do nothing since nothing get changed otherwise on changed
configuration install get called as usual::

  >>> print system(buildout)
  Updating supervisor.
