[opensuse] passing variables to a systemd service unit?
I am slowly beginning to migrate a system with multiple postfix instances to 13.1 and therefore also systemd. What is the best way of running multiple instances of postfix with systemd? Basically every "postfix start|stop|reload|whatever" needs a '-c' argument indicating the instance, for example: postfix -c number4 start The service.unit is the same, except for the <instance> argument. Can I somehow pass the <instance> as an argument or do I need just create separate service units? -- Per Jessen, Zürich (21.2°C) http://www.dns24.ch/ - your free DNS host, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
В Wed, 13 Aug 2014 18:00:19 +0200
Per Jessen
I am slowly beginning to migrate a system with multiple postfix instances to 13.1 and therefore also systemd. What is the best way of running multiple instances of postfix with systemd? Basically every "postfix start|stop|reload|whatever" needs a '-c' argument indicating the instance, for example:
postfix -c number4 start
The service.unit is the same, except for the <instance> argument. Can I somehow pass the <instance> as an argument or do I need just create separate service units?
One possibility is to use templates. postfix@.service as template and then simply ln -s postfix@.service postfix@<whatever>.service Inside unit definition you refer to part after @ as %i or %I (should be the same in your case). See man systemd.unit. So start command will become postfix -c %I start -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Andrei Borzenkov wrote:
В Wed, 13 Aug 2014 18:00:19 +0200 Per Jessen
пишет: I am slowly beginning to migrate a system with multiple postfix instances to 13.1 and therefore also systemd. What is the best way of running multiple instances of postfix with systemd? Basically every "postfix start|stop|reload|whatever" needs a '-c' argument indicating the instance, for example:
postfix -c number4 start
The service.unit is the same, except for the <instance> argument. Can I somehow pass the <instance> as an argument or do I need just create separate service units?
One possibility is to use templates.
postfix@.service as template and then simply
ln -s postfix@.service postfix@<whatever>.service
Inside unit definition you refer to part after @ as %i or %I (should be the same in your case). See man systemd.unit. So start command will become
postfix -c %I start
Thanks Andrei and Cristian - much appreciated! -- Per Jessen, Zürich (17.0°C) http://www.hostsuisse.com/ - virtual servers, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 El 2014-08-14 a las 11:45 +0200, Per Jessen escribió:
postfix -c %I start
Thanks Andrei and Cristian - much appreciated!
I wanted to know about that trick, so thanks from me, too :-) - -- Cheers Carlos E. R. (from 13.1 x86_64 "Bottle" (Minas Tirith)) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iF4EAREIAAYFAlPsiuYACgkQja8UbcUWM1wNeQD/WMpzqPdVYRtC9gt5wqGwHVj/ y5LyhbGnfXEqGyzl7rgA/RsjJzg4efI4NPFGOFMlTAkGCjKJWTyMFhYUQhuN/cvJ =nc9R -----END PGP SIGNATURE-----
Per Jessen wrote:
Andrei Borzenkov wrote:
В Wed, 13 Aug 2014 18:00:19 +0200 Per Jessen
пишет: I am slowly beginning to migrate a system with multiple postfix instances to 13.1 and therefore also systemd. What is the best way of running multiple instances of postfix with systemd? Basically every "postfix start|stop|reload|whatever" needs a '-c' argument indicating the instance, for example:
postfix -c number4 start
The service.unit is the same, except for the <instance> argument. Can I somehow pass the <instance> as an argument or do I need just create separate service units?
One possibility is to use templates.
postfix@.service as template and then simply
ln -s postfix@.service postfix@<whatever>.service
Inside unit definition you refer to part after @ as %i or %I (should be the same in your case). See man systemd.unit. So start command will become
postfix -c %I start
Thanks Andrei and Cristian - much appreciated!
And it worked really well, brilliant! I created /etc/systemd/system/postfix@.service based on /usr/lib/systemd/system/postfix.service: [Unit] Description=Postfix Mail Transport Agent (%i) Requires=var-run.mount nss-lookup.target network.target remote-fs.target time-sync.target After=var-run.mount nss-lookup.target network.target remote-fs.target time-sync.target After=amavis.service mysql.service cyrus.service ldap.service openslp.service ypbind.service Conflicts=sendmail.service exim.service [Service] Type=forking PIDFile=/var/spool/%i/pid/master.pid ExecStartPre=-/bin/echo 'Starting mail service (%i)' EnvironmentFile=-/etc/sysconfig/postfix ExecStartPre=/etc/postfix/system/config_postfix ExecStartPre=/etc/postfix/system/update_chroot ExecStartPre=/etc/postfix/system/update_postmaps ExecStart=/usr/sbin/postfix -c /etc/%i start ExecStartPost=/etc/postfix/system/wait_qmgr 60 ExecStartPost=/etc/postfix/system/cond_slp register ExecReload=/usr/sbin/postfix -c /etc/%i reload ExecReload=/usr/sbin/postfix -c /etc/%i flush ExecStop=/usr/sbin/postfix -c /etc/%i stop ExecStopPost=/etc/postfix/system/cond_slp deregister [Install] WantedBy=multi-user.target -- Per Jessen, Zürich (17.5°C) http://www.hostsuisse.com/ - dedicated server rental in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
El 13/08/14 a las #4, Per Jessen escribió:
I am slowly beginning to migrate a system with multiple postfix instances to 13.1 and therefore also systemd. What is the best way of running multiple instances of postfix with systemd? Basically every "postfix start|stop|reload|whatever" needs a '-c' argument indicating the instance, for example:
postfix -c number4 start
The service.unit is the same, except for the <instance> argument. Can I somehow pass the <instance> as an argument or do I need just create separate service units?
That's what instantiated services are all about..see http://0pointer.de/blog/projects/instances.html or as examples all the the units containing the character "@" in /usr/lib/systemd/system Cheers. -- Cristian "I don't know the key to success, but the key to failure is trying to please everybody." -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (4)
-
Andrei Borzenkov
-
Carlos E. R.
-
Cristian Rodríguez
-
Per Jessen