0

How can I create a service with a name different from the name of the package?

I'm preparing a package that provides also a service file (systemd config) that should have a name different from the package.

Currently I added a file debian/pkg_name.service and it works but the name does not reflect the service started.

I already noticed that dh_installinit has a --name option but tha man page lists

debian/package.name.init, debian/package.name.default and debian/package.name.upstart instead of the usual debian/package.init, debian/package.default and debian/package.upstart

but not package.service. Moreover I haven't really understood where I should place the line. Currently my debian/rules has

%:
        dh  $@ --with bash-completion --with systemd
5
  • I don't see a clearly defined question here
    – Thomas Ward
    Feb 4, 2016 at 1:59
  • See the --name option of dh_installinit.
    – muru
    Feb 4, 2016 at 2:20
  • What? Does the manpage have to exhaustively list examples? As for where you should place the line, see joeyh.name/blog/entry/debhelper_dh_overrides
    – muru
    Feb 4, 2016 at 8:34
  • I thought ot was limiting to named examples... So I changed my debian/rules as follows: %: dh $@ --with bash-completion --with systemd --with python2 override_dh_installinit: dh_installinit -p thunder-buildout-prod --name oooctl.service But I get an error I can't really understand: Use of uninitialized value $filename in concatenation (.) or string at /usr/share/perl5/Debian/Debhelper/Dh_Lib.pm line 410. I get this error even if I use an absolute path Feb 5, 2016 at 10:40
  • I'm conviced that *.service file are not hadled by dh_installinit, they're not listed in man page and I've not been able to find a solution with it. See below for my answer. Feb 6, 2016 at 1:23

2 Answers 2

1

At last I solved it with the following configuration:

  1. package name is thunder-buildout-prod

  2. debian/oooctl.service as in question

  3. in debian/rules:

%:
  dh  $@ --with bash-completion --with systemd --with python2

override_dh_systemd_enable:
  dh_systemd_enable -p thunder-buildout-prod debian/oooctl.service

override_dh_systemd_start:
  dh_systemd_start -p thunder-buildout-prod debian/oooctl.service

As a last note. Having a script in /etc/init.d/oooctl (note: same name as the service) that sources /lib/lsb/init-functions, this is enought to make it just work as a call to systemctl start/stop/status oooctl.service ignoring the rest of the script

1
  • (no "t" at the end of "enough") Apr 28, 2019 at 3:33
1

According to the dh_systemd_enable manual https://manpages.debian.org/testing/debhelper/dh_systemd_enable.1.en.html:

--name=name
    Install the service file as name.service instead of the default 
    filename, which is the package.service. When this parameter is 
    used, dh_systemd_enable looks for and installs files named 
    debian/package.name.service instead of the usual debian/package.service.

I found that you also need to pass the name to dh_installinit. For example, if your package was amed "mytool" but you want your service file to be mytoolsrv.service instead of mytool.service, you would create the file debian/tool.toolsrv.service and put the following in you debian/rules file:

#!/usr/bin/make -f

%:
    dh $@

override_dh_systemd_enable:
    dh_systemd_enable --name=mytoolsrv

override_dh_installinit:
    dh_installinit --name=mytoolsrv

Tested with debhelper compatibility level 10.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .