5

I'm currently packaging a python app with dh_virtualenv, daemonized with systemd.

I use the dh_systemd plugin to automatically install the file my_app.service will install the .deb package, but I'd like to run another process in a different service that schedules tasks for my app, using celery.

So, I created another service file, my_app.scheduler.service, but I don't know how to declare this file/app/service in my debian packaging rules, so that while installing the whole package, both services file will be copied and thus will be launched independently.

Here are my debian conf files for dpkg-buildpackage command :

debian/control

Source: my_app
Section: python
Priority: extra
Maintainer: me
Build-Depends: debhelper (>= 9), python, dh-virtualenv (>= 0.6), dh-systemd (>= 1.5), adduser
Standards-Version: 3.9.5

Package: my_app
Architecture: any
Pre-Depends: dpkg (>= 1.16.1), python2.7, ${misc:Pre-Depends}
Depends: ${python:Depends}, ${misc:Depends}
Description: blabla

debian/rules:

#!/usr/bin/make -f

%:
    dh $@ --with python-virtualenv --with=systemd

debian/install

etc/my_app.config /etc/

debian/dirs:

/var/lib/my_app
/var/log/my_app

And of course the .service files:

debian/my_app.service

[Unit]
Description=APP

[Service]
Type=simple
User=app_user
EnvironmentFile=/etc/my_app.config
ExecStart=/usr/share/python/my_app/bin/gunicorn -w 10 -b 0.0.0.0:6000 -t 600 my_app_python_package:app

[Install]
WantedBy=multi-user.target

debian/my_app.scheduler.service

[Unit]
Description=APP Scheduler

[Service]
Type=simple
User=app_user
EnvironmentFile=/etc/my_app.config
ExecStart=/usr/share/python/my_app/bin/celery worker -A my_app_python_package.tasks 

[Install]
WantedBy=multi-user.targetroot
Braiam
  • 1
  • 11
  • 47
  • 78
pbo
  • 218
  • 2
  • 11

3 Answers3

9

Found the solution here:

override_dh_installinit:
        dh_installinit --name=service1
        dh_installinit --name=service2
Community
  • 1
  • 1
pbo
  • 218
  • 2
  • 11
  • I am struggling with similar situation. I need to create openstack-swift-account package and package multiple service files under this. I tried the dh_installinit but not sure what service name to use and how name my corresponding service files. Can you please elaborate on your solution ? – mittal Feb 24 '17 at 07:36
  • 2
    Never mind, I was finally able to achieve it. For others who might be struggling, name the service file as ..service, ..service, ..service. Then in override section, dh_installinit -p --name= dh_installinit -p --name= dh_installinit -p --name= – mittal Feb 24 '17 at 08:28
  • How does this work with service files? The man page section for the `--name` option only mentions `.upstart`, `.init` and `.default` file types. ---- *Install the init script (and default file) as well as upstart job file using the filename name instead of the default filename, which is the package name. When this parameter is used, dh_installinit looks for and installs files named 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.* – Wimateeka Feb 07 '18 at 18:48
3
#!/usr/bin/make -f

%:
        dh $@ --with-systemd, python2

override_dh_installinit:
        dh_installinit --name=service1
        dh_installinit --name=service2

override_dh_systemd_enable:
        dh_systemd_enable --name=service1
        dh_systemd_enable --name=service2

override_dh_systemd_start:
        dh_systemd_start --name=service1
        dh_systemd_start --name=service2

Save service name as 'packagename.service1.service' and 'packagename.service2.service' under 'debian/ ' directory

0

See Yd Ahhrk's answer (in StackExchange):

Starting from compatibility level 11, dh_installinit no longer handles systemd services. Use dh_installsystemd instead:

override_dh_installsystemd:
  dh_installsystemd --name=service1
  dh_installsystemd --name=service2

(The above assumes that you have two service files: debian/<package-name>.service1.service and debian/<package-name>.service2.service.)

emi
  • 2,786
  • 1
  • 16
  • 24