You are not logged in.

#1 2013-11-01 21:15:13

From: WA, USA
Registered: 2013-07-24
Posts: 94

Creating a service for a daemon

I'm working on a specialized server daemon in Google's Go language, and have a makefile that I want to have an "install" directive for, that would pu the compiled binary, the document root, the logfile directory, etc, in /opt/gochan/*, and create a service that can be started by running

systemctl start  gochan

in distros using systemd

service gochan

in distros using Upstart, etc.

How would I go about doing this? What is the best way to make a catch-all method of starting it as a service?


#2 2013-11-01 21:31:43

Inspector Parrot
Registered: 2011-11-29
Posts: 20,459

Re: Creating a service for a daemon

Why install to /opt?  Why not use the distro's prefered $PREFIX and/or $BINDIR?

As for systemd service files, there is a wiki page or a man page for that - they are pretty simple.  The upstart equivalent may be in the *buntoo documentation.

Is the real question here just how to detect which init is used from within a Makefile?  Autotools would probably be the best way.  But a check of /proc/1/comm would be an effective shortcut.

EDIT: from another perspective, though, distro specific things should be handled by the packaging for that distro.  Your makefile should just allow for different options.  So the systemd service file could be installed via a PKGBUILD or the *buntoo equivalent, or perhaps with different install directives like `make install.systemd` and `make install.upstart`.

Last edited by Trilby (2013-11-01 21:35:17)

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman


#3 2013-11-02 12:02:50

From: Netherlands, Europe
Registered: 2005-10-04
Posts: 6,434

Re: Creating a service for a daemon

rodaz143, (developed by graysky) can be build for systemd , upstart and openrc using build-time options .

It might serve as an example of how to do what you want.

Multi-init booting with apg Openrc and systemd coexisting
Automounting : not needed, i prefer pmount
Aur helpers : makepkg + my own local repo === rarely need them


Board footer

Powered by FluxBB