Using variable with ConditionEnvironment in systemd service

I am using the following systemd service file:


ExecStart=/usr/bin/cifscloak mount -a -r 6
ExecStop=/usr/bin/cifscloak mount -u -a


ConditionEnvironment should evaluate the homeNetwork variable and start the service if the value is 1.
The problem is, how can I create an instance of this variable in the way the systemd service can read it?
I would like to use something like the following:

gw=$(ip r | grep default | head -1 | awk ' {print $3;}')
if [ "$gw" == "" ]; then export officeNetwork=1; else export officeNetwork=0; fi
if [ "$gw" == "" ]; then export homeNetwork=1; else export homeNetwork=0; fi

The problem is: how can I run this script before the systemd service runs?

I have solved creating two systemd services, the first checks the network and the second depends on the success of the first. It works.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.