1

I need to build a package for a program that should be deployed as a service. I have added a debian/helloworld.service and my package is built, installed and works correctly, i have a /lib/systemd/system/helloworld.service on the target host.

However, users may be able to run several instance of the service, each one with their own config files and i have seen here that i need a template service file in the form helloworld@.service.

But when i try to build the package using debian/helloworld@.service, i don't have the templated service file in the package anymore (dpkg -c shows that there is no helloworld@.service in the .deb)

Note that i am building a binary package using fakeroot debian/rules binary.

What is the best way to do that ? Should i use postinst scripts (but https://www.debian.org/doc/manuals/maint-guide/dother.en.html#maintscripts seems to discourage their use) ?

Thank you.

Fryz
  • 111
  • 3

2 Answers2

0

After having looked at apache2 which is installed with a templated service, it seems that one need to add a debian/helloworld.service along with the template debian/helloworld@.service to see the templated file in the .deb file.

Now i can see the helloworld@.service with dpkg -c.

Fryz
  • 111
  • 3
-1

You can add a script in the postinst that would create the template service file on the target host. However, it is discouraged as it goes against the principle of declarative packaging.

A better approach would be to provide a script along with your package, which can be run by the user to create the required instance of the service with the desired configuration. The script can be run on demand and can generate the required service file and start the service instance.