Thread View: linux.dev.c-programming
3 messages
3 total messages
Started by Herr Fieldmarshall
Tue, 21 Sep 2004 15:00
Creating Daemons: Best Practice?
Author: Herr Fieldmarshall
Date: Tue, 21 Sep 2004 15:00
Date: Tue, 21 Sep 2004 15:00
27 lines
2052 bytes
2052 bytes
Hello, I've created a program that runs as a daemon, but my question now is, what is the best practice concerning distributing and installing it. The executable needs access to some config file, and some other data files. I assume it's best practice to place the executable in /usr/local/bin and all the rest in /usr/local/etc. My question now is, how can I assure that the executable will always find the config file? (I don't like hard-coding ../etc/configfile.conf). I've also read that it is for security reasons best to use chroot to run the deamon, but how do I do this in such a way that my data and config files remain accessible? My last point is how do I get the daemon neatly installed in init.d ? Is there some script for it? Briefly said, my question is: I've created a daemon application, but what now? Greetz, Arnout
Re: Creating Daemons: Best Practice?
Author: Dances With Crows
Date: Tue, 21 Sep 2004 16:05
Date: Tue, 21 Sep 2004 16:05
52 lines
3319 bytes
3319 bytes
["Followup-To:" header set to comp.os.linux.misc.] On Tue, 21 Sep 2004 17:00:34 +0200, Herr Fieldmarshall staggered into the Black Sun and said: > I've created a program that runs as a daemon, but my question now is, > what is the best practice concerning distributing and installing it? Put the source in a tarball, make sure there's a README in the tarball. If you haven't used the autotools to make yourself a configure script, you probably need to if you want this to have any sort of wide distribution. > The executable needs access to some config file, and some other data > files. I assume it's best practice to place the executable in > /usr/local/bin and all the rest in /usr/local/etc. That'll work for now. If you use the autotools, you can pass "--prefix=/usr" and the executable will go in /usr/bin . There isn't a /usr/etc though, so think about another location for these mysterious "other files". > how can I assure that the executable will always find the config file? > (I don't like hard-coding ../etc/configfile.conf). Many daemons take a -C option like so: daemon -C /foo/bar/config.conf . Have your daemon do a getopt() on C, look for that file first, if it's not there, look in 1 or 2 hardcoded paths, if nothing is found, write informational messages to stderr and the logfile and exit(1). Like so: mydaemon: could not find config file in /etc/mydaemon.conf or /etc/mydaemon/mydaemon.conf , no -C option given. Exiting because there's no point in running without a config file. > I've also read that it is for security reasons best to use chroot to > run the deamon, but how do I do this in such a way that my data and > config files remain accessible? That's up to the person who sets up the chroot. Remember that any shared libraries your program links to must also be in the chroot environment. If I were you, I'd get the thing working properly before worrying about chroot. > My last point is how do I get the daemon neatly installed in init.d ? > Is there some script for it? You'll have to write your own init script. Take a look at what's already there for some guidance. HTH, -- Matt G|There is no Darkness in Eternity/But only Light too dim for us to see Brainbench MVP for Linux Admin / mail: TRAP + SPAN don't belong http://www.brainbench.com / Hire me! -----------------------------/ http://crow202.dyndns.org/~mhgraham/resume
Re: Creating Daemons: Best Practice?
Author: Menno Duursma
Date: Tue, 21 Sep 2004 19:11
Date: Tue, 21 Sep 2004 19:11
64 lines
3635 bytes
3635 bytes
On Tue, 21 Sep 2004 17:00:34 +0200, Herr Fieldmarshall wrote:
> Hello,
>
> I've created a program that runs as a daemon, but my question now is, what
> is the best practice concerning distributing and installing it.
That depends, "man hier" ie:
If it's a binary blob - a tarball for extraction under /opt .
If it's source - default to /usr/local prefix.
If you plan on providing TGZ/RPM/DEB packages, stick with disro guidelines.
In either case put some INSTALL and README files in the archive, and
create MD5 checksum(s) - and preverably GPG signature too - of that.
> The executable needs access to some config file, and some other data files.
> I assume it's best practice to place the executable in /usr/local/bin and
> all the rest in /usr/local/etc.
Read above, or better yet:
http://www.pathname.com/fhs/
> My question now is, how can I assure that
> the executable will always find the config file? (I don't like hard-coding
> ../etc/configfile.conf).
Parce command-line option, and/or environment variable, before trying any
hardcoded path, ie: getenv() , getopt() - err out on failing all.
> I've also read that it is for security reasons best to use chroot to run the
> deamon,
Yes. However i'd leave it up to the administrator to actually set it up
that way. You'd do good providing the option - and some documentation on
how to go about running it that way though.
Be sure to drop privileges - ie: suid() , setgid() - after doing what
you need root for ie: chroot() , chdir("/") , etc.
And/or have a read through "man capabilities" (which i haven't used, but
read someware "pureftpd" and "named" use that, to drop anything but:
CAP_NET_BIND_SERVICE after start-up.)
> but how do I do this in such a way that my data and config files
> remain accessible?
They have to reside inside the jail, allong with anything else your deamon
needs to properly function ( such as /dev/log , /var/run , or whatever. )
> My last point is how do I get the daemon neatly installed in init.d ? Is
> there some script for it?
I'd just base my script(s) on the ones provided with given distro for
start/stop/restart of other services. Note, on some distros (like
Slackware) they reside in /etc/rc.d/ .
> Briefly said, my question is: I've created a daemon application, but what
> now?
Have a look at how others packaged something like it?
http://freshmeat.net/
--
-Menno.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads