Is it possible to write portable service scripts to control a daemon

daemoninit.dscripting

I (or one of my colleagues) need to write one or more shell scripts to control the execution of a daemon. We need to be able to start the daemon, tell it to gracefully shut down, and force a shutdown. Basically, it's the sort of thing one would traditionally use a script in /etc/init.d for.

We will be deploying to Ubuntu. We may want to deploy to RedHat/CentOS, and possibly AIX. I'd like to have the ability to deploy to any unix, because i like doing things portably.

So, is it possible to write portable service scripts?

I suppose i can write a portable Bourne shell script which works like a normal init.d script, and accepts 'start' and 'stop' as commands. That would work anywhere, and would offer a natural interface on at least Debian and RedHat style systems. Would it fit in elsewhere? Is init.d universal? Are there any pitfalls to watch out for?

Are there any tools for generating service scripts in different forms? Something where i can write script fragments for starting and stopping, and have the tool produce scripts for various different platforms.

Are there any alternatives to platform-specific service script conventions? I've come across daemontools and runit; are these alternatives to init.d scripts? Are they any good? What else is there like this?

Does this make any sense?

Best Answer

Ot is possible to write them in a way so that it does not depend on the distro's specifics, but not all *nix start services in the same way. I am not sure about AIX, but Solaris for example doesn't even use sysvinit, instead it uses smf.

CentOS/RHEL typically uses /etc/rc.d/functions to assist with common functions for init script, while Debian uses a binary called start-stop-daemon. This is likely a reason that init scripts are often not found in upstream packages.

Personally, I would write an init script for each supported OS, to be included in that OS's package.

Related Question