tango systemd integration

Felipe Sateler fsateler at debian.org
Sun Jul 19 18:56:43 BST 2015


On 17 July 2015 at 18:50, PICCA Frederic-Emmanuel
<frederic-emmanuel.picca at synchrotron-soleil.fr> wrote:
>> Great!
>
> will see if I can do something ;)
>
>> We need a bit more detail on what your init scripts currently do. Most
>> of the time the conversion is fairly simple (ie, just invoke the
>> program with the correct options).
>
> Let's do it slowly and start with tango-db
> I put here a cut and past of the curren tinit script of tango-db
>
> ---8<-----
>
> PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/tango
> DESC="Tango Control System - database"
> NAME=tango-db
> NAME_REAL=DataBaseds
> CONFFILE=/etc/tangorc
> PORT=`grep TANGO_HOST $CONFFILE | awk -F ":" '{print $2}'`
> HOST=`grep TANGO_HOST $CONFFILE | awk -F ":" '{print $1}' | awk -F "=" '{print $2}'`
> CANON_HOST=`grep TANGO_HOST $CONFFILE | awk -F ":" '{print $1}' | awk -F "=" '{print $2}' | awk -F "." '{print $1}'`
> DAEMON=/usr/lib/tango/$NAME_REAL
> DAEMON_USER=tango
> DAEMON_GROUP=tango
> PIDFILE=/var/run/$NAME.pid
>
> # Exit if the package is not installed
> [ -x "$DAEMON" ] || exit 0
>
> # Read configuration variable file if it is present
> [ -r /etc/default/$NAME ] && . /etc/default/$NAME
>
> # Load the VERBOSE setting and other rcS variables
> . /lib/init/vars.sh
> # Define LSB log_* functions.
> # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
> . /lib/lsb/init-functions
>
> #
> # Function that starts the daemon/service
> #
> do_start()
> {
>         # Return
>         #   0 if daemon has been started
>         #   1 if daemon was already running
>         #   2 if daemon could not be started
>
>         # to start this daemon need a working network
>         if [ $CANON_HOST = "localhost" ]
>         then
>                 DAEMON_ARGS="2 -ORBendPoint giop:tcp:$HOST:$PORT"
>         else
>                 DAEMON_ARGS="2 -ORBendPoint giop:tcp::$PORT"
>                 tango_admin --ping-network 40 || return 2
>         fi
>         start-stop-daemon --start --quiet --chuid $DAEMON_USER:$DAEMON_GROUP --background \
>             --make-pidfile --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
>             || return 1
>         start-stop-daemon --start --quiet --chuid $DAEMON_USER:$DAEMON_GROUP --background \
>             --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS \
>             || return 2
>         # Add code here, if necessary, that waits for the process to be ready
>         # to handle requests from services started subsequently which depend
>         # on this one.  As a last resort, sleep for some time.
>         tango_admin --ping-database 6 || return 2
> }
>
> first I change the PATH to add /usr/lib/tango where the daemon executable can be found

The executable is specified with a full path in systemd units so this
should be unnecessary.

>
> as you can see there is some black magie in the do_start and a few constant at the begining of the code
> the daemon args depends on the nameof the host

I think you will have to either have the user manually configure that
or refactor this part into a script to be invoked via systemd.

> tango_admin is a tool which allow to check that the network is up and ready in order to start the daemon

Doesn't the daemon handle temporary network downtime? If so, this
should be unnecessary.
If this is still required, you can add an Wants/After=network-online.target

> then we start the daemon as a tango user instead of root.

Use the User/Group directives to accomplish this.

>
> at the end the tango_admin is used to check that the daemonis up and running
>  tango_admin --ping-database 6 || return 2 (6 is for the number of retry)

I think you can use ExecStartPost for this.

>
>> Also, what do you mean require a running mysql server? tango-db does
>> not depend on mysql-server...
>
> you are right
>
> Package: tango-db
> Source: tango
> Version: 8.1.2c+dfsg-5
> Installed-Size: 810
> Maintainer: Debian Science Maintainers <debian-science-maintainers at lists.alioth.debian.org>
> Architecture: i386
> Depends: debconf (>= 0.5) | debconf-2.0, libc6 (>= 2.4), libcos4-1 (>= 4.1.6), libgcc1 (>= 1:4.1.1), liblog4tango5, libmysqlclient18 (>= 5.5.24+dfsg-1), libomniorb4-1 (>= 4.1.6), libomnithread3c2 (>= 4.0.6), libstdc++6 (>= 4.4.0), libtango8, libzmq3 (>= 3.2.3+dfsg), zlib1g (>= 1:1.1.4), dbconfig-common, libtango-tools, lsb-base
> Recommends: mysql-client
>
> but I rely on dbconfig-common in order to setup the sql datatbase when installing the package. (this is another story)
> What is true is that the tango-db "daemon" can not start if it can not connect to a running database.
> Which can be on the same host or another one (different topologies of network)

Use After/Wants=mysql.service then, because if the server is in
another host you cannot Require it.


Hope this helps


-- 

Saludos,
Felipe Sateler




More information about the Pkg-systemd-maintainers mailing list