I try to start multiple processes with systemd - restart if it terminated included. The only difference is the argument of the processes.
Is there a way to avoid a unit-file per process??
I am looking for a unit-file for all processes together.
Normally I would use a start-skript but - as I said - restart in case of termination should be also included. And I do not see a way to do it with pure systemd and no handmade skriptlets.
Thanks!
Perhaps using a template unit fits your needs. From systemd.unit(5)
Optionally, units may be instantiated from a template file at runtime. This allows creation of multiple units from a single configuration file. If systemd looks for a unit configuration file, it will first search for the literal unit name in the file system. If that yields no success and the unit name contains an "#" character, systemd will look for a unit template that shares the same name but with the instance string (i.e. the part between the "#" character and the suffix) removed. Example: if a service getty#tty3.service is requested and no file by that name is found, systemd will look for getty#.service and instantiate a service from that configuration file if it is found.
To refer to the instance string from within the configuration file you may use the special "%i" specifier in many of the configuration options. See below for details.
So you might create a file myservice#.service that reads something like
[Unit]
Description=MyService component %i
PartOf=myservice.target
[Service]
Type=simple
ExecStart=/usr/local/bin/myservice %i
Restart=on-failure
and the master unit myservice.target as
[Unit]
Description=Myservice
Requires=myservice#a.service myservice#b.service myservice#c.service
The PartOf= specification in myservice#.service ensures that when the target is stopped or restarted each component is as well. With Requires= in myservice.target each component must be started for myservice to have successfully started. I think it should be the case that if any individual component fails any that didn't fail should be terminated; i.e. its all or nothing. If that's not what you want you might use Want= instead of Requires=.
It's a little awkward, but if you need to supply multiple arguments you can introduce an indirection through environment variables. For the template unit add Environment=args=%i and replace %i in the ExecStart with $args. I think it'd be better to find an alternative to that, but without knowing more about your use-case I'm not sure what that solution would be.
Related
I have a Python project where the main file has spaces in the name. I understand that this is not encouraged, but in this case, I think it's necessary. The file is being compiled into a stand alone executable using py2app--which uses the file name for the application name when building the executable (app name, menu references, etc.). This works fine because the base file is not imported anywhere within the project and py2app handles the spaces gracefully. Let's call the file Application Name.py.
In order to run unit tests against Application Name.py, however, I have to eliminate the spaces in order to import the file into unittest. I'm unable to use importlib or __import__ because the file is not constructed as a package, so both approaches fail. My workflow has been to refactor the file name to application_name.py, run the unit tests, and then refactor the name to Application Name.py before compiling it into Application Name.app.
So the options appear to be:
Keep doing what I'm doing (workable, but not ideal),
Create a wrapper called Application Name.py that imports application_name.py where the wrapper doesn't need to be unit tested (seems silly),
Convert Application Name into a package so I can use importlib (seems like overkill), or
Something else entirely.
Is there some way to gracefully handle file names with spaces in unit testing that I'm not seeing or should I just suck it up?
Seems like option 2 probably works best.
Option 1 and 2 are your best bets (yes 3 is a bit overkill), and although 2 seems excessive, it does isolate your python logic from your py2app requirements - now Application Name.py is a "py2app wrapper file", and application_name.py contains your actual logic.
This works better than Option 1 because separation of responsibilities is generally preferred. If you come up with other requirements for your application name, you'd want to have to deal with just the "py2app wrapper file", and not change anything related to actual logic.
Your current workflow works too, but it does mean more manual renaming when you want to run unit tests - what if you want to automate the unit testing process?
is there a way to find out the default values of the parameter which are set in the /etc/systemd/system.conf file?
The manual page of systemd-system.conf just says:
When run as system instance systemd reads the configuration file
system.conf, otherwise user.conf. These configuration files contain a
few settings controlling basic manager operations.
The variables are outcommented (in user.conf + system.conf) and the file /etc/security/limits.conf is ignored by systemd.
So, what are the default values? Are they all set to unlimited?
The answer is:
systemctl show
:)
In the official Puppet docs it says that there are two chaining arrows:
https://docs.puppetlabs.com/puppet/latest/reference/lang_relationships.html
-> (ordering arrow)
Causes the resource on the left to be applied before the resource on the right. Written with a hyphen and a greater-than sign.
~> (notification arrow)
Causes the resource on the left to be applied first, and sends a refresh event to the resource on the right if the left resource changes. Written with a tilde and a greater-than sign.
Can someone clarify the difference between these two?
The document you mentioned has given the best explanation. If you try to understand it by simple way, using the exist sample.
Package['ntp'] -> File['/etc/ntp.conf'] ~> Service['ntpd']
For File['/etc/ntp.conf'], puppet needs to make sure that the package ntp has been installed before it creates or updates the file ntp.conf. There is no restart request.
But for Service['ntpd'], ntp.conf needs to exist first - that's the same order as ->. * But if puppet finds the file ntp.conf has any changes (whether it is created or updated), service ntp needs to be restarted. That's the difference*.
For more reading about ordering in puppet, please see these documents:
Learning Puppet — Resource Ordering
And do some testing by yourself to understand how it works.
set Package['ntp'], File['/etc/ntp.conf'] ,Service['ntpd'] with the order.
run puppet apply to make sure, Package/File/Service are ready on the system.
make a change in the file ntp.conf.
enable the --debug option with the puppet apply command. The debug log will give you detail in the background - for example, you should see that the file gets updated and the ntpd service gets restarted.
Which spring-????-config.xml I should use to star GG nodes so the .net example GridClientApiExample works?
Each GridGain example provides a short description of how to run remote nodes in the example documentation.
Usually there are two ways to run remote nodes for the example. The first and, probably, the most convenient one is to run corresponding *NodeStartup class from IDE in the examples project. The name of startup class is specified in example documentation. The second way is to start a node with ggstart.{sh|bat} script with a configuration file specified in the documentation (if available).
GridClientApiExample works only with node started from IDE with ClientExampleNodeStartup, and there is a reason for it. The example expects a specific task class (org.gridgain.examples.misc.client.api.ClientExampleTask) to be in the node's classpath. Since this is an example-only class, it is not present in node classpath when running ggstart.{sh|bat}.
If for some reason you want to run a node with command line script for this example, you should build examples jar file and drop it to $GRIDGAIN_HOME/libs/ext (startup script will automatically pick up all additional libraries placed in this folder). Then you can use the same config which ClientExampleNodeStartup uses, namely examples/config/example-compute.xml
You can use ClientExampleNodeStartup or start node with ggstart.sh examples/config/example-compute.xml
Context
I'm building my complete debian system configuration,
so I'm modifying the keyboard and console setups.
I prefer not to modify the base files to keep a maximum
commpatibility and modularity. So I want to use VARIANT
(see setupcon (5)) and load them at init.
But not sure I'm doing it right.
Desired Architecture
I will only use keyboard file for the following example.
There is the base file /etc/default/keyboard
And two possible custom files (according to setupcon (5))
~/.keyboard
/etc/default/keyboard.variant
~/.keyboard
It provides a custom behaviour per $HOME (user)
/etc/default/keyboard.variant
A global and default keyboard setup
I would like to use the three at a time.
Problem
The daemon calling setupcon are console-setup and console-setup-mini
(according to the coments in their initd scripts). They are started
before login shell, so won't know ~/.keyboard.
setupcon needs to be called
setupcon variant
or, looking at the sources, with a variable $VARIANT
VARIANT=variant
What is the best solution to adopt, saving a maximum modularity.
Thank you,