Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
1  
there is a LSB (Linux Standard Base) for such things now... you may want to look into that. –  xenoterracide Mar 1 '12 at 5:40
    
Volume VIII. System Initialization has a few sections about init scripts, it's true. So at least init scripts are standard across Linux distributions. –  Tom Anderson Mar 1 '12 at 10:20
add comment

1 Answer 1

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.

share|improve this answer
    
The LSB mandates a file /lib/lsb/init-functions which contains some standard functions; i think these wrap things like start-stop-daemon, so there is a measure of portability there. However, the documentation on these functions is very poor. –  Tom Anderson Jun 18 '12 at 11:08
    
And yes, i am still working on this! –  Tom Anderson Jun 18 '12 at 11:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.