🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.dev.c-programming
Article #3

Re: Creating Daemons: Best Practice?

#3
From: Menno Duursma
Date: Tue, 21 Sep 2004 19:11
64 lines
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.
Technical Details
Message-ID: <pan.2004.09.21.22.40.01.120127@desktop.lan>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsgate.cistron.nl!amsnews01.chello.com!amsnews04.chello.com!amsnews05.chello.com.POSTED!53ab2750!not-for-mail
References: <cipfmi$9nm$1@snic.vub.ac.be>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1103af,b8ad6e866a257b4
X-Google-Thread: fc9ab,b8ad6e866a257b4
X-Google-Thread: faa64,b8ad6e866a257b4
X-Google-Thread: 100a19,b8ad6e866a257b4
X-Google-Attributes: gid1103af,gidfc9ab,gidfaa64,gid100a19,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsgate.cistron.nl!amsnews01.chello.com!amsnews04.chello.com!amsnews05.chello.com.POSTED!53ab2750!not-for-mail
From: Menno Duursma <menno@desktop.lan>
Subject: Re: Creating Daemons: Best Practice?
User-Agent: Pan/0.14.2.91 (As She Crawled Across the Table)
Message-ID: <pan.2004.09.21.22.40.01.120127@desktop.lan>
Newsgroups: linux.dev.c-programming,comp.os.linux.misc,alt.comp.linux,alt.os.linux,be.comp.os.linux
References: <cipfmi$9nm$1@snic.vub.ac.be>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Lines: 65
Date: Tue, 21 Sep 2004 19:11:53 GMT
NNTP-Posting-Host: 80.56.117.242
X-Complaints-To: abuse@chello.nl
X-Trace: amsnews05.chello.com 1095793913 80.56.117.242 (Tue, 21 Sep 2004 21:11:53 MEST)
NNTP-Posting-Date: Tue, 21 Sep 2004 21:11:53 MEST
Organization: chello broadband