Re: [systemd-devel] How does systemd discover template instances?

2015-10-16 Thread Ansgar Burchardt
Michael Chapman  writes:
> On Thu, 15 Oct 2015, Stuart Longland wrote:
>> Assuming I have a few files distributed in the base package:
>>  /lib/systemd/system/comms-drivers.service
>>  /lib/systemd/system/comms-drivers@.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?
>
> One approach you might want to consider is using a systemd generator
> [1] to create the instance symlinks automatically at boot, e.g.:

This was done for OpenVPN in Debian. As Stuart said he based his
sysvinit script on Debian's openvpn script, the systemd integration
might also help him.

The generator can be found at [2], the .service files at [3] and [4].

Ansgar

  [2] 

  [3] 

  [4] 

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] How does systemd discover template instances?

2015-10-15 Thread Erik Haller

  
  
You can also create a /lib/systemd/systemd/my_main_script.service
and use "ln -s /lib/systemd/system/my_main_script.service
/etc/systemd/system/uniq1.service". Then use "mkdir
/etc/systemd/system/uniq1.service.d" and create a
/etc/systemd/system/uniq1.service.d/blah.conf that has systemd.unit
things that override the main my_main_script.service.

On 10/14/15 9:01 PM, Stuart Longland
  wrote:


  On 15/10/15 13:23, Andrei Borzenkov wrote:

  
15.10.2015 00:30, Stuart Longland пишет:


  Assuming I have a few files distributed in the base package:
/lib/systemd/system/comms-drivers.service
/lib/systemd/system/comms-drivers@.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@.service exists and it is
attempted to start foo@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.

  
  
Okay, that's useful to know.  So in order to start foo@bar.service, I
don't need to create any files.

Question is, how does systemd find out about the existence of
foo@bar.service without a file being present?

The idea being that the service foo.service acts as a means of
starting/stopping/querying all instances.  I would guess that
stopping/restarting/querying, systemd is smart enough to look at what's
presently running, however what about starting?

  
  
  
  ___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel



  

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] How does systemd discover template instances?

2015-10-15 Thread Michael Chapman

On Thu, 15 Oct 2015, Stuart Longland wrote:

Assuming I have a few files distributed in the base package:
/lib/systemd/system/comms-drivers.service
/lib/systemd/system/comms-drivers@.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?


Hi Stuart,

One approach you might want to consider is using a systemd generator [1] 
to create the instance symlinks automatically at boot, e.g.:


  ARGV[1]/comms-driver@some-instance.service
 -> /lib/systemd/system/comms-drivers@.service

The ARGV[1] argument passed to your generator is likely to be 
"/run/systemd/generator".


Your generator can use any mechanism it likes to decide which instances 
should be created. Note, however, the generator is run very early on in 
boot (and whenever systemd's configuration is reloaded), so it should be 
lightweight and not need any other system services to be operational.


If you have particular instances you want started at boot, you can link 
them in to the appropriate target's .wants directory, e.g.:


  ARGV[1]/multi-user.target.wants/comms-driver@some-instance.service
 -> /lib/systemd/system/comms-drivers@.service

Hope this is of assistance.

Regards,
Michael


[1] http://www.freedesktop.org/software/systemd/man/systemd.generator.html
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] How does systemd discover template instances?

2015-10-14 Thread 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@.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?
-- 
Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind...
  ...it's backed up on a tape somewhere.



signature.asc
Description: OpenPGP digital signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] How does systemd discover template instances?

2015-10-14 Thread Stuart Longland
On 15/10/15 13:23, Andrei Borzenkov wrote:
> 15.10.2015 00:30, Stuart Longland пишет:
>> Assuming I have a few files distributed in the base package:
>> /lib/systemd/system/comms-drivers.service
>> /lib/systemd/system/comms-drivers@.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@.service exists and it is
> attempted to start foo@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.

Okay, that's useful to know.  So in order to start foo@bar.service, I
don't need to create any files.

Question is, how does systemd find out about the existence of
foo@bar.service without a file being present?

The idea being that the service foo.service acts as a means of
starting/stopping/querying all instances.  I would guess that
stopping/restarting/querying, systemd is smart enough to look at what's
presently running, however what about starting?
-- 
Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind...
  ...it's backed up on a tape somewhere.



signature.asc
Description: OpenPGP digital signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] How does systemd discover template instances?

2015-10-14 Thread Andrei Borzenkov

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@.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@.service exists and it is 
attempted to start foo@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.

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] How does systemd discover template instances?

2015-10-14 Thread Andrei Borzenkov


Отправлено с iPhone

> 15 окт. 2015 г., в 7:01, Stuart Longland  
> написал(а):
> 
>> On 15/10/15 13:23, Andrei Borzenkov wrote:
>> 15.10.2015 00:30, Stuart Longland пишет:
>>> Assuming I have a few files distributed in the base package:
>>>/lib/systemd/system/comms-drivers.service
>>>/lib/systemd/system/comms-drivers@.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@.service exists and it is
>> attempted to start foo@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.
> 
> Okay, that's useful to know.  So in order to start foo@bar.service, I
> don't need to create any files.
> 
> Question is, how does systemd find out about the existence of
> foo@bar.service without a file being present?
> 

Any access to foo@bar.service will cause it to appear (be instanted from 
template).


> The idea being that the service foo.service acts as a means of
> starting/stopping/querying all instances.  I would guess that
> stopping/restarting/querying, systemd is smart enough to look at what's
> presently running, however what about starting?
> -- 
> Stuart Longland (aka Redhatter, VK4MSL)
> 
> I haven't lost my mind...
>  ...it's backed up on a tape somewhere.
> 
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel