[PKG-Openstack-devel] systemd support for OpenStack

stanzgy stan.zgy at gmail.com
Tue Jul 15 08:06:04 UTC 2014


AFAIK there is no other option in systemd to run this kinda scripting.
Here are some examples I found that using shell wrapper for consideration:

## Jenkins docs [1]_

jenkins.helper

java -jar /home/jenkins_user/jenkins.war &


jenkins.service

[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



## CoreOS docs [2]_

[Unit]Description=My Advanced ServiceAfter=etcd.serviceAfter=docker.service
[Service]ExecStart=/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'ExecStartPost=/usr/bin/etcdctl set
/domains/example.com/10.10.10.123:8081 runningExecStop=/usr/bin/docker
stop apacheExecStopPost=/usr/bin/etcdctl rm
/domains/example.com/10.10.10.123:8081
[Install]WantedBy=multi-user.target



## discussion on systemd dev maillist [3]_

>* Hi Xiong
*> >* You can have a script that reads the  /proc/cmdline and then calls
*>* exec with your app.
*> >* ExecStart=/your/custom/scipt
*> >* cat /your/custom/script:
*> >* # Do what ever you want, figure out parameters
*> >* # Start your application
*>* exec myapp --parameter=xyz
*
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 ''.



.. [1]:
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Unix+daemon
.. [2]:
http://coreos.com/docs/launching-containers/launching/getting-started-with-systemd/
.. [3]:
http://lists.freedesktop.org/archives/systemd-devel/2014-May/019136.html


On Tue, Jul 15, 2014 at 2:44 PM, Thomas Goirand <zigo at debian.org> wrote:

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



-- 
Best Regards,

Gengyuan Zhang
NetEase Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/openstack-devel/attachments/20140715/fda13986/attachment.html>


More information about the Openstack-devel mailing list