Register a program as a service

Red Squirrel

No Lifer
May 24, 2003
67,904
12,374
126
www.anyf.ca
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.
 

Reel

Diamond Member
Jul 14, 2001
4,484
0
76
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.
 

Red Squirrel

No Lifer
May 24, 2003
67,904
12,374
126
www.anyf.ca
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.
 

yoda291

Diamond Member
Aug 11, 2001
5,079
0
0
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.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
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?
 

Red Squirrel

No Lifer
May 24, 2003
67,904
12,374
126
www.anyf.ca
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)
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
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.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |