• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Register a program as a service

Red Squirrel

No Lifer
How do I go about registering a program as a service, programaticly?

I understand I have to make a special file in /etc/rc.d but is there odds that on some systems its not always going to be that path?

So is there a "real" way of doing it? I want to be able to do "service myapp start" and what not. And chkconfig myapp on/off to make it start at startup.

I'll be developing a hosting control panel system so I want it to act as a service. I may go a step further and even do a "service myapp recompile" feature.
 
I think the location is /etc/init.d and the special file is a script to actually start the program. The ideal is something clever that handles all the commands: start, stop, restart, etc. You might be able to get away with something lesser but I am not sure if that would upset your system. I would look at the contents of that folder and review some of those scripts.
 
Is it always /etc/init.d though? or do some distros like to put it somewhere else? Otherwise I already have an idea how I'll go about doing it. I can make my program able to handle a signal like sighup then just have the stop command send that signal, and starting will just execute it with &. Just don't want to assume it's always in /etc/init.d unless it in fact always is there.

Way it will work is the first time my program is executed it will have a configuration wizard which includes setting it as a service.
 
it differs by distribution.

some use rc.local
some use chkconfig and rc.d/
some use /etc/init.d/
some of them use daemontools even.

I'd hit up the documentation on your distro.
 
AFAIK /etc/init.d is standard, /etc/rc.d is a legacy symlink on RH stuff and rc.local is in addition to the /etc/init.d stuff. I don't think any distros come with daemontools installed standard, although Ubuntu is moving to upstart.

The only distro that /etc/init.d probably won't cover right now is Slackware because they use BSD-init, but who really cares about Slackware anyway?
 
So I'm pretty safe to just make my program edit/add files to /etc/init.d then? (and /etc/rc3.d and so on - but chkconfig should take care of that)
 
Yea, just drop the script in /etc/init.d and symlink it whever. I wouldn't rely on chkconfig unless you're only supporting RHEL/FC/CentOS hosts though.
 
Back
Top