Best way to write an init.d script for start_server and starman?
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.