description     "{{{ description }}}"
start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
umask {{{umask}}}
{{#nice}}
nice {{{nice}}}
{{/nice}}
{{#chroot}}
chroot {{{chroot}}}
{{/chroot}}
chdir {{{chdir}}}
{{#limit_coredump}}
limit core {{{limit_coredump}}} {{{limit_coredump}}}
{{/limit_coredump}}
{{#limit_cputime}}
limit cpu {{{limit_cputime}}} {{{limit_cputime}}}
{{/limit_cputime}}
{{#limit_data}}
limit data {{{limit_data}}} {{{limit_data}}}
{{/limit_data}}
{{#limit_file_size}}
limit fsize {{{limit_file_size}}} {{{limit_file_size}}}
{{/limit_file_size}}
{{#limit_locked_memory}}
limit memlock {{{limit_locked_memory}}} {{{limit_locked_memory}}}
{{/limit_locked_memory}}
#limit msgqueue <softlimit> <hardlimit>
#limit nice <softlimit> <hardlimit>
{{#limit_open_files}}
limit nofile {{{limit_open_files}}} {{{limit_open_files}}}
{{/limit_open_files}}
{{#limit_user_processes}}
limit nproc {{{limit_user_processes}}} {{{limit_user_processes}}}
{{/limit_user_processes}}
{{#limit_physical_memory}}
limit rss {{{limit_physical_memory}}} {{{limit_physical_memory}}}
{{/limit_physical_memory}}
#limit rtprio <softlimit> <hardlimit>
#limit sigpending <softlimit> <hardlimit>
{{#limit_stack_size}}
limit stack {{{limit_stack_size}}} {{{limit_stack_size}}}
{{/limit_stack_size}}
setuid {{{user}}}
setgid {{{group}}}

# Set a really really large kill timeout
# By default, upstart has a kill timeout of 5 seconds.
# If the program is being stopped, but hasn't finished by the time this 'kill
# timeout' has expired, then upstart will destroy the process with SIGKILL.
# SIGKILL is a way to cause data loss, so we try to disable this feature by
# default.
kill timeout 99999999

{{#prestart}}
pre-start script
  {{{ prestart }}}

  status=$?
  if [ "$status" -gt 0 ] ; then
    echo "Prestart command failed with code $status."

    # Per init(5) docs, simply calling 'stop' will abort this start.
    stop
  fi
end script
{{/prestart}}

script
  # When loading default and sysconfig files, we use `set -a` to make
  # all variables automatically into environment variables.
  set -a
  [ -r {{{default_file}}} ] && . {{{default_file}}}
  [ -r {{{sysconfig_file}}} ] && . {{{sysconfig_file}}}
  set +a
  exec {{{program}}} {{{shell_args}}}
end script
