Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

The PSGI/Plack interface is unbelievably good to develop for, but I feel ashamed every time I have to tell our sysadmins that "I run this stuff as nohup twiggy --listen :1234 app.psgi & from my home directory, oh and it must be up 24x7 on production".

So I'd like to write an init script for my PSGI apps once and for all.

Previous searches suggest using Ubic::Service::Plack but I fear our admins would object, as they already have init for running/stopping and zabbix for monitoring. I believe there are other people in the Perl community who have their reasons to stick to sys v init.

Now, there's Daemon::Control so I only have to reinvent a wheel of minimal diameter. Looks like there's some prior art, but I'd like to generalize a bit.

In my ideal world with unicorns and pegasi, the workflow should look like:

  • Edit file /etc/plack/config.yml (first time only);
  • Copy my app's spec into /etc/plack/apps.d (install script should be able to do it, too);
  • Say service plack start and that's it.

The main config should contain: app files relocation (like /etc/plack/apps.d), sane defaults for apps, and probably more. Upon loading the config it should be checked for sanity, consistency, port/name/pidfile intersections, etc.

An app config may contain:

  • app (path, required) - path to the PSGI application in question
  • port (number, required) - desired port
  • name (string) - symbolic name (both service plack restart $port and service plack restart $name should be OK)
  • pid_file (printf-like) - pid file path format with %p for port and %n for symbolic name
  • log_file (printf-like) - file where stdin and stdout are redirected
  • server (command) - plackup, twiggy, etc.
  • server_args (list) - additional args to be passed to the server
  • env (hash) - hash of environment variables (e.g. PERL5LIB)
  • dir (directory) - working directory of the script (by default should cd / or something)
  • user (user|number) - user to run under
  • group (group|number) - group to run under

Now some questions I'd like to ask before doing any serious development.

  • How to name the executable, plack or psgi? Is Plack::InitScript a good name for the the underlying module (looks like PSGI namespace is reserved). I guess I should name everything the same way so that there's as little confusion as possible.
  • File format - should I stick with YAML, or maybe there's some .ini variation, like git-config? Should it be possible to configure multiple services in one file?
  • I'd also like to implement ping method to check that the app is really there and serves the content (by HEAD'ing some specific URI). Should it be a nonstandard ping command, a nonstandard --ping option, or just a separate script?
  • Enabling/disabling - should I add a auto|enabled/noauto|disabled option to the application config, or use apache-like sites_available/sites_enabled approach? Should it be possible to temporary bring up an application that is normally off, or is it unneeded complexity?
  • What else did I miss?

In reply to RFC: SysVInit script for multiple PSGI applications by Dallaylaen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (12)
    As of 2014-12-22 09:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (113 votes), past polls