Best way to write an init.d script for start

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 (ie 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.

  • 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


    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).


    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.

    链接地址: http://www.djcxy.com/p/13164.html

    上一篇: Sphinx的include ::指令和“重复标签”警告

    下一篇: 编写init.d脚本的最佳方式