Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install multiple .service files with dh_systemd packaging

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
like image 856
pbo Avatar asked Dec 15 '22 03:12

pbo


1 Answers

Found the solution here:

override_dh_installinit:
        dh_installinit --name=service1
        dh_installinit --name=service2
like image 51
pbo Avatar answered Feb 11 '23 20:02

pbo