7

I'm trying to come up with a nice init.d script that starts a psgi app, using start_server and starman. It needs to have the following features:

  • Run on RedHat (i.e. Debian's start-stop-daemon is not available)
  • Run start_server as another user
  • Be maintainable.

Ideally, I'd like to use the stuff that comes with /etc/init.d/functions to give the script the look and feel of any ol' RedHat init.d script.

More specifically, I'm looking for best practices to:

  • Daemonize a program that doesn't come with its own --daemonize option
  • Run the daemon under another UID.
innaM
  • 47,505
  • 4
  • 67
  • 87
  • 2
    While product and library recommendations aren't exactly on-topic here, have you considered [supervisor](http://supervisord.org/)? You can find it in the EPEL repo for both RHEL5 and 6. That takes care of the init script part, and you get all of the rest of the features you're looking for with pretty much no effort. – Charles Apr 28 '13 at 14:56
  • 1
    Wow. Thank you, Charles. If this thing works as advertised, I have a **lot** of work for it. Now why is this the first time I read about it? – innaM Apr 29 '13 at 08:29
  • I'm not sure, but spread the word! We use it in production to keep our Gearman workers running. – Charles Apr 29 '13 at 16:32

3 Answers3

1

You could try runit, it's another supervisor. Nowdays it seems a good practice to use one of these things. Here you could read a comparison of different supervisors.

Best practices:

  • Daemonize a program that doesn't come with its own --daemonize option

You don't have to daemonize the program, runit takes care of it.

  • Run the daemon under another UID.

Here you could use chpst

pasja
  • 365
  • 4
  • 10
1

If perl is running anyway how about using Ubic ? It's a perl based supervisor that makes LSB /etc/init.d/ compatibility fairly easy. I tend to use it the way runit/daemontools/s6 are used (in a separate services/ directory) but you have a lot of flexibility. Since you can use perl in your scripts there's a lot of interesting possibilities. In addition Ubic gives you portability since it will work in the same way on different platforms (BSD, Linux, Solaris, OS/X, etc).

G. Cito
  • 6,210
  • 3
  • 29
  • 42
1

Here's the init script we're using: starman-init

It has all the features you mentioned:

  • Uses start_server to support graceful restarts
  • Runs as unprivileged user/group nobody/nobody
  • Uses /etc/init.d/functions

Note that it assumes you have a local Perl installed for your application (such as plenv or perlbrew). You'll need to customize that for your environment.

mla
  • 172
  • 1
  • 7