1

I would like add some parameters into my .service file such hostname, IP, username, password, during debian package installation.

I created a debian package installion for my python script but I do not know how to get parameters from user and pass the arguments into the .service file or create a .service with arguments.

AdminBee
  • 21,637
  • 21
  • 47
  • 71

1 Answers1

1

See How to pass parameters for Debian installer (.deb) for information on how to ask questions during package installation.

Once you have the values you want, passing them into the .service file can be done in a variety of ways. One of these is to write the values to a drop-in file, typically in /etc/systemd/system/yourservice.d/parameters.conf (yourservice must match your service; parameters can be anything, the significant part is the .conf extension). Such drop-in files are read after the unit file and their contents are added to it; see systemd.unit for details (or man systemd.unit on your system).

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Would you consider the question a duplicate of the one you linked? – AdminBee Aug 12 '20 at 07:52
  • Not quite, because there seem to be two questions: one about asking questions during package installation (which is a dupe), and one about passing the information to the service. Thanks for asking! – Stephen Kitt Aug 12 '20 at 07:55
  • Yeah, the second point was what made me hesitant to flag it as duplicate. So I guess while technically "it lacks focus", we can leave it as it is ... – AdminBee Aug 12 '20 at 08:00
  • Sorry for my late answer and thanks for the reply. I used `preinst` which is automatically executed before installation starts. You can check the [link](https://github.com/eminaktas/get-of-metrics/blob/v1/get-of-metrics/DEBIAN/preinst) to see my solution. – Emin AKTAŞ Aug 23 '20 at 15:45
  • That’s a shame, but it’s your package ;-). Your approach works but you’ll have trouble dealing with upgrades. – Stephen Kitt Aug 23 '20 at 17:18