Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-18 11:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found