[systemd-devel] How does systemd discover template instances?
Andrei Borzenkov
arvidjaar at gmail.com
Wed Oct 14 20:23:53 PDT 2015
15.10.2015 00:30, Stuart Longland пишет:
> Hi all,
>
> First up, I'm rather new to systemd, having been more or less forced
> into it by the decisions of the Ubuntu and Debian projects, which have
> both gone that way.
>
> (I know the default can be changed, but upstream have chosen this init
> system, so I as a software developer must learn to use it.)
>
> I have a SysV init script which I based on the Debian init script for
> OpenVPN. The service I'm starting up is a collection of device drivers
> for a data acquisition system. (Think: SCADA-style application.)
>
> These drivers run as daemon processes in userspace, and communicate with
> devices out in the field by various means (we've got drivers that talk
> Modbus and EDMI, we're planning a BACNet driver, etc) and they talk with
> the rest of the system over AMQP (RabbitMQ).
>
> The drivers can be written in any language (most are in Python, some may
> be done in C++), and may not necessarily take the same command line
> arguments. I'd like to be able to write a set of systemd unit files
> that can either selectively, or all together, bring the driver instances
> up and down.
>
> The existing script permits this, and under Debian Wheezy, works well.
> Under Jessie with systemd however, the systemd wrappers get in the way
> and we lose the ability to control individual instances. I also feel
> there are some features of systemd which would be useful (auto-restart
> on crash for example).
>
> For that reason, I'm looking at how to write some unit files to achieve
> this aim.
>
> I feel I can probably achieve most of this with some simple wrapper
> scripts that make the drivers all react the same (in the eyes of
> systemd), which brings me to the problem of instances. (In fact, I can
> probably use my existing init script.)
>
> Assuming I have a few files distributed in the base package:
> /lib/systemd/system/comms-drivers.service
> /lib/systemd/system/comms-drivers at .service
>
> Ordinarily, one would tell systemd about template instances by creating
> symbolic links.
>
> Suppose however I wanted to not do this, but instead, provide some
> automatic discovery mechanism for systemd, so it could run a script that
> would tell it what instances exist.
>
> Is there a mechanism for doing this in systemd?
>
>
I'm not sure if I actually understand the question, but - templates are
instantiated on the fly. If template foo at .service exists and it is
attempted to start foo at bar.service, systemd will create it internally.
It is full fledged unit that is visible in status, can be stopped, is
part of dependency resolution etc.
More information about the systemd-devel
mailing list