Install multiple .service files with dh_systemd pa

2020-07-20 06:34发布

问题:

I'm currently packaging a python app with dh_virtualenv, to deploy it on Ubuntu 16.04, 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.

Do you have any idea to do that ?

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

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

rules

#!/usr/bin/make -f

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

install

etc/my_app.config /etc/

dirs

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

And of course the .service files :

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

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

Thanks in advance :)

EDIT / SOLUTION

I finally found an answer. For those who might have the same problem, using dh_installinit solves the case :)

回答1:

Found the solution here:

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


回答2:

#!/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