terminating a failed post-start stanza

Alexander Petrov alexxxbt at gmail.com
Tue Apr 16 21:31:00 UTC 2013


Hello Michael, hello devs
Don't know why upstart's finite machine ignores errors in post-start but I
guess you can do following:

1) you can try kill postgres from post-start (or kill main, but you will
need to parse output of `initctl status`)
2) upstart kills all processes in process group so you can run postress in
background and check its status

env ready=/tmp/pgsql-ready
env ready_timeout=20

pre-start

  if [ -d /var/run/postgresql ]; then
     chmod 2775 /var/run/postgresql
  else
     install -d -m 2775 -o postgres -g postgres /var/run/postgresql
  fi

    rm -rf $ready
end script

main
  postgres .. &
 pid=$!

 for i in `seq 1 10` ; do
    if psql -c 'select 1' ; then
        touch $ready
        break
    fi
 done

 if [ -e $ready ] ; then
    wait $pid
 fi
end script

post-start
  while [ ! -e $ready ] ; do
   log "waiting.."
  done
end script



2013/4/16 Michael Barrett <loki77 at gmail.com>

> Hi, I'm working on converting my postgresql package to using upstart.
>  While doing so, I found that postgres takes a few moments after starting
> to actually start accepting connections.  I decided to use a post-start job
> to test whether the postgres server was up and available before letting
> upstart believe the service was ready.
>
> Currently my upstart job looks like this: http://dpaste.com/1060864/
>
> The issue I'm running into now is that whenever there is an issue with the
> postgres server that causes it to crash, the post-start job hangs
> indefinitely (as you'd expect from the loop).  I can't stop the job or
> restart it once I fix the issue.  The only way I've been able to fix it is
> to bring up postgres manually, which allows the post-start to finish.
>
> I've tried putting a maximum # of retries in the post-start script, then
> doing an exit 1 when it exceeds that amount, but that results in the 'start
> postgresql' command exiting successfully, which causes issues in other
> places in my application (because postgres isn't actually running).
>
> What is the suggested method for dealing with something like this?  Is
> there anyway to tell the post-start to terminate?  Is there any way for
> post-start to signal that there was an issue starting the daemon after a #
> of retries?  I'm sure I'm missing something key in my understanding, so any
> help would be appreciated.
>
> Thanks!
>
> --
> Michael Barrett
> loki77 at gmail.com
>
>
>
>
>
> --
> upstart-devel mailing list
> upstart-devel at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/upstart-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/upstart-devel/attachments/20130417/127635c5/attachment.html>


More information about the upstart-devel mailing list