init.d script for plack-powered site

275 views
Skip to first unread message

Mark Norman Francis

unread,
Dec 19, 2010, 7:01:54 PM12/19/10
to psgi-...@googlegroups.com
Hi,

Before I go re-inventing the wheel, does anyone have a Ubuntu-flavoured init.d script for starting/stopping/restarting a plack-powered website?

-- Norm.

Alex Kapranoff

unread,
Dec 20, 2010, 7:15:07 AM12/20/10
to psgi-...@googlegroups.com
Hello, Mark!

While I don't have answer for your particular request, I would recomment trying Ubic http://search.cpan.org/dist/Ubic/ with Ubic::Service::Plack for your task.
Ubic may also be installed from this PPA https://launchpad.net/~berekuk/+archive/ubic

--
Alex Kapranoff.

Lars Thegler

unread,
Dec 20, 2010, 6:22:54 AM12/20/10
to psgi-...@googlegroups.com
On Mon, Dec 20, 2010 at 1:01 AM, Mark Norman Francis
<no...@cackhanded.net> wrote:
> Before I go re-inventing the wheel, does anyone have a Ubuntu-flavoured init.d script for starting/stopping/restarting a plack-powered website?

Ubuntu now uses Upstart, which seems very easy to write init scripts
for. See http://sysadvent.blogspot.com/2010/12/day-19-upstart.html

> -- Norm.

/ars

Jonathan Rockway

unread,
Dec 20, 2010, 8:48:21 AM12/20/10
to psgi-...@googlegroups.com

I personally like supervise. Create the supervise "run" scripts for
plackup and your logger:

$ mkdir -p myapp/services/myapp/log
$ cd myapp
$ cat > services/myapp/run
#!/bin/bash
exec softlimit -a 300000000 plackup myapp.psgi
$ cat > services/myapp/log/run
#!/bin/bash
exec multilog t '+*' 10000000s 10n ../logs/myapp/

(softlimit limits memory usage to 300M with setrlimit. It's optional,
but it's nice to not have your whole system go down because your web app
is leaky :)

Then start supervise, either by itself:

$ supervise services/myapp

Or, if you have a bunch of services in your services directory:

$ svscan services/myapp

Then you can check the status of your app easily:

$ svstat services/myapp
services/myapp/: up (pid 1234) 238473 seconds

And you can control it:

$ svc -t services/myapp # bounce myapp (kill with SIGTERM, supervise
restarts it)

$ svc -d services/myapp # bring down but don't restart

$ svc -s services/myapp # SIGSTOP
$ svc -c services/myapp # SIGCONT

I find this to be a lot easier than maintaining init scripts.

I am using this for a 10+-process app at work and am writing a plack app
for checking it all via the web. Take a look at metavise in my github
(when I push it, which will be later this week).

--Jon

--
print just => another => perl => hacker => if $,=$"

Mark Norman Francis

unread,
Dec 20, 2010, 10:07:39 AM12/20/10
to psgi-...@googlegroups.com
> Ubuntu now uses Upstart, which seems very easy to write init scripts
> for. See http://sysadvent.blogspot.com/2010/12/day-19-upstart.html

That does indeed look easy. Thanks very much!

(Which is not to say that the other solutions offered were useless, but I like to go with the grain of the OS :)

-- Norm.

Reply all
Reply to author
Forward
0 new messages