[systemd-devel] transforming Iptables bash script to systemd service file -help

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Sep 12 03:53:23 PDT 2014


On 12/09/14 09:57, lux-integ wrote:
> The question is;  is there a way of conditionally procesing lines in systemd 
> service files such as the following
> 
> ExecStart=/path/to/executible1
> ExecStart=/path/to/executible2
>   some condition satisfied  ( for example ConditionFileNotEmpty=SomeFile ..... 
> )
> ExecStart=/path/to/executible3
> ..back to  'unconditional processing
> ExecStart=/path/to/executible4

The way to do this is to write a script in the programming language of
your choice (bash is one possibility), and have the systemd service file
run that. There would be little point in systemd reinventing a generic
script interpreter: we already have lots of those (bash, Python, etc.)

For the specific case of iptables, "what Zbigniew said": it would be
better for your script to compose a file or buffer in
iptables-save/iptables-restore syntax, and pipe it to iptables-restore,
so that it can be applied atomically.

    S



More information about the systemd-devel mailing list