Re: Creating Daemons: Best Practice?

From: Menno Duursma (menno_at_desktop.lan)
Date: 09/21/04


Date: Tue, 21 Sep 2004 19:11:53 GMT

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.


Relevant Pages

  • Re: Creating Daemons: Best Practice?
    ... > is the best practice concerning distributing and installing it. ... They have to reside inside the jail, allong with anything else your deamon ... I'd just base my scripton the ones provided with given distro for ... Slackware) they reside in /etc/rc.d/. ...
    (comp.os.linux.misc)
  • Linux & MSI K8N Neo2 Platinum (nForce3 Ultra) questions...
    ... I will be installing both on whatever distro so don't even bother trying ... better software manager would help a lot. ... I am also trying to set up a firewall and intrusion detection. ...
    (alt.linux)
  • Re: wpa supplicant/ipw3945, ESSID last char missing
    ... but who want to upgrade to a newer 2.6 kernel? ... I'd point out here that one is not breaking the _distro_, ... We've _got_ to accept that somebody installing their own stuff has ... and no new interface is introduced without thinking very ...
    (Linux-Kernel)
  • Re: Problems with Fedora? Use Mandriva (Mandrake)
    ... I've used Mandrake/iva for my main distro since v8.0, ... I want to stay with a rpm-based system and urpmi ... is the best package handler for rpms I've ever used. ... very good and make installing from online sources a snap. ...
    (alt.os.linux)
  • Re: LILO and my MBR
    ... If I uninstall Mandrake, though, it'll uninstall Lilo with it ... > Windows start disks with fdisk on them lying around). ... You don't typically uninstall a distro. ... installing the new distro and have it format the partition before ...
    (comp.os.linux.setup)