[Dancer-users] many dancer apps with Starman (part 3)

Pedro Melo melo at simplicidade.org
Fri Jul 15 15:51:51 CEST 2011


On Fri, Jul 15, 2011 at 2:15 PM, Mr. Puneet Kishor <punk.kish at gmail.com> wrote:
> On Jul 15, 2011, at 3:05 AM, Pedro Melo wrote:
>> On Thu, Jul 14, 2011 at 10:57 PM, Mr. Puneet Kishor <punk.kish at gmail.com> wrote:
>>> On Jul 11, 2011, at 6:59 AM, Pedro Melo wrote:
>>>> First: Use the --pid option of plackup and give it a very descriptive
>>>> name, in a well known directory. With that, you can use kill
>>>> -SIGNAL_NAME `head -1 /path/to/pids/app_descriptive_name` ... You can
>>>> even use tab completion.
>> [...]
>>> What is the way to restart an already running app? Am I the only one who is a bit lost with the documentation for Starman and other servers (or, even the plackup documentation)?
>> Err :)... Starman perldoc, under DESCRIPTION, the Signals item starts
>> with: "Supports HUP for graceful restarts..."...
> Yes, I read that, but I don't know what that means (I know more Unix than my neighbor, but that is still waaaaay too little). I know that Ctrl-C sends a HUP, and so does `kill`, doesn't it?

Ok, assume that you've started your app like this:

starman --pid my_x_app.pid bin/app.pl

This will start a starman with the default number of workers and it
will write the PID of the manager process into the my_x_app.pid file.

To restart the app do:

kill -HUP `head -1 my_x_app.pid`

The head -1 my_x_app.pid will get the first line of the file, the PID
of the process and the kill command will send the SIGHUP signal to
that pid.

This will restart your app, gracefully, without loosing requests.

To try, do this:

 * open three new windows;
 * on window 1, start you app under starman: starman --pid
my_x_app.pid bin/app.pl
 * on window 2, type the command kill -HUP `head -1 my_x_app.pid` but
don't execute it yet
 * on window 3, type ab -c 4 -n 4000
 * start the command on window 3 (this will generate 4000 requests
with 4 concurrent clients);
 * while that is running, go to windows 2 and execute the command. You
can execute it multiple times (!! is your friend, just type
!!<ENTER>). Each time, the app will restart.
 * when the ab command on window 3 finishes, notice that you didn't
have any errors. You did have longer response times for some requests,
while the app is restarting, but no lost requests.

Its possible to remove even the longer response times using
server-starter *I think* but I don't use it, don't know how well it

>> Use the --pid option to write the master process pid number to a file
>> so you don't have to use ps (which on Mac OS X lacks the -f option
>> unfortunately).
> Yes, I am able to use your suggested technique
>  $ kill `head -1 /path/to/pidfile/with/descriptive/name`
> What SIGNAL can I send for a restart?

-HUP, see above

Pedro Melo
xmpp:melo at simplicidade.org
mailto:melo at simplicidade.org

More information about the Dancer-users mailing list