Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

RFC: SysVInit script for multiple PSGI applications

by Dallaylaen (Scribe)
on Jul 03, 2013 at 13:31 UTC ( #1042222=perlmeditation: 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?

Comment on RFC: SysVInit script for multiple PSGI applications
Re: RFC: SysVInit script for multiple PSGI applications
by talexb (Canon) on Jul 05, 2013 at 13:17 UTC

    This sounds like a really cool project. I've bookmarked this page for next week when I hope to have some development time.

    I'll be back. :)

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      Well, I've started developing some code on github. I would appreciate help and/or critique!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1042222]
Approved by Corion
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (18)
As of 2014-10-23 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls