<div dir="ltr"><div><div>AFAIK there is no other option in systemd to run this kinda scripting.<br>Here are some examples I found that using shell wrapper for consideration:<br></div><br>## Jenkins docs [1]_<br><br>jenkins.helper<br>

<br>java -jar /home/jenkins_user/jenkins.war &
<br><br><br>jenkins.service<br><pre>[Unit]
Description=Jenkins Daemon
After=syslog.target

[Service]
Type=forking
ExecStart=/usr/bin/sh /home/jenkins_user/jenkins.helper
User=jenkins_user

[Install]
WantedBy=multi-user.target</pre><br><br></div>## CoreOS docs [2]_<br><div><div><pre><code class=""><span class="">[Unit]</span>
<span class="">Description</span><span class="">=</span><span class="">My Advanced Service</span>
<span class="">After</span><span class="">=</span><span class="">etcd.service</span>
<span class="">After</span><span class="">=</span><span class="">docker.service</span>

<span class="">[Service]</span>
<span class="">ExecStart</span><span class="">=</span><span class="">/bin/bash -c '/usr/bin/docker start -a apache || /usr/bin/docker run --name apache -p 80:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND'</span>
<span class="">ExecStartPost</span><span class="">=</span><span class="">/usr/bin/etcdctl set /domains/<a href="http://example.com/10.10.10.123:8081">example.com/10.10.10.123:8081</a> running</span>
<span class="">ExecStop</span><span class="">=</span><span class="">/usr/bin/docker stop apache</span>
<span class="">ExecStopPost</span><span class="">=</span><span class="">/usr/bin/etcdctl rm /domains/<a href="http://example.com/10.10.10.123:8081">example.com/10.10.10.123:8081</a></span>

<span class="">[Install]</span>
<span class="">WantedBy</span><span class="">=</span><span class="">multi-user.target</span></code></pre><br><br></div><div>## discussion on systemd dev maillist [3]_<br></div><div><br><pre>><i> Hi Xiong
</i>><i> 
</i>><i> You can have a script that reads the  /proc/cmdline and then calls
</i>><i> exec with your app.
</i>><i> 
</i>><i> ExecStart=/your/custom/scipt
</i>><i> 
</i>><i> cat /your/custom/script:
</i>><i> 
</i>><i> # Do what ever you want, figure out parameters
</i>><i> 
</i>><i> # Start your application
</i>><i> exec myapp --parameter=xyz
</i>
Yup this looks like the best idea.


There is also ConditionKernelCommandLine= but that would require you
actually have several units for each different option and have the
Condition prevent it from running.

ConditionKernelCommandLine also only does quite simple matching, so it
might not do what you need anyway.

So I think a wrapper script is likely best here. Or some:
  ExecStart=/bin/bash -c '...'
if you can encapsulate it simply enough within the ''.
</pre><br><br><div class="gmail_extra">.. [1]: <a href="https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Unix+daemon">https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Unix+daemon</a><br>

.. [2]: <a href="http://coreos.com/docs/launching-containers/launching/getting-started-with-systemd/">http://coreos.com/docs/launching-containers/launching/getting-started-with-systemd/</a><br></div><div class="gmail_extra">

.. [3]: <a href="http://lists.freedesktop.org/archives/systemd-devel/2014-May/019136.html">http://lists.freedesktop.org/archives/systemd-devel/2014-May/019136.html</a><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Tue, Jul 15, 2014 at 2:44 PM, Thomas Goirand <span dir="ltr"><<a href="mailto:zigo@debian.org" target="_blank">zigo@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<div class=""><div class="h5">On 07/15/2014 01:55 AM, gustavo panizzo <gfa> wrote:<br>
> On 07/14/2014 01:46 PM, stanzgy wrote:<br>
>> Hi zigo, I agreed with Gustavo to use the EnvironmentFile to deal with<br>
>> the logging facility.<br>
>> But after some failed tries I found it seems impossible to use<br>
>> EnvironmentFile to handle this.<br>
>> The syntax EnvironmentFile using[1] is incompatible with bash(especially<br>
>> when dealing with<br>
>> quotes and spaces),<br>
><br>
> newer versions of systemd support shell like quoting in EnvironmentFile,<br>
> 204-14 does it. i just checked with ssh service file<br>
><br>
><br>
>  and seems have no control statements like if or<br>
>> while. So the following<br>
><br>
> :(<br>
><br>
>> code couldn't be done with systemd service file AFAIK.<br>
>><br>
>> [ "x$USE_SYSLOG" = "xyes" ] && DAEMON_ARGS="$DAEMON_ARGS --use-syslog"<br>
>> [ "x$USE_LOGFILE" != "xno" ] && DAEMON_ARGS="$DAEMON_ARGS --log-file<br>
>> /var/log/nova/$NAME.log"<br>
><br>
>><br>
>> IMHO a workaround is to always enable logfile and offer some options in<br>
>> /etc/default<br>
>> to decide whether to enable syslog.<br>
> Agreed<br>
><br>
> i think we could<br>
><br>
> 1) add a postinst script to parse, and modify, /etc/default/openstack<br>
> and /etc/default/nova.<br>
> logging options will end in $DAEMON_ARGS which we could consume from<br>
> service and init.d files<br>
><br>
> 2) launch the service from a shell wrapper :(<br>
><br>
><br>
> both approaches will suit me, i need them because<br>
> <a href="https://github.com/saltstack/salt/issues/11900" target="_blank">https://github.com/saltstack/salt/issues/11900</a><br>
><br>
> i do prefer the postinst path<br>
<br>
</div></div>The postinst path doesn't work, because you should be able to just edit<br>
/etc/default/<name> or /etc/default/openstack, restart the daemon, and<br>
your new option tweaks should be taken care of. Postinst doesn't run<br>
when you start the service.<br>
<br>
So the only option we have remaining is a kind of wrapper somehow. I've<br>
heard that there's an option in systemd to run some kind of scripting,<br>
do you guys know about that? Or is it just writing a wrapper in the<br>
ExecStart?<br>
<br>
Cheers,<br>
<br>
Thomas<br>
<div class=""><div class="h5"><br>
<br>
_______________________________________________<br>
Openstack-devel mailing list<br>
<a href="mailto:Openstack-devel@lists.alioth.debian.org">Openstack-devel@lists.alioth.debian.org</a><br>
<a href="http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/openstack-devel" target="_blank">http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/openstack-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Best Regards,<br><br>Gengyuan Zhang<br>NetEase Inc.
</div></div></div></div>