GNU/Linux >> Tutoriales Linux >  >> Ubuntu

¿Cómo empaquetar un servicio Systemd?

Estoy tratando de empaquetar una aplicación mono para que se ejecute como un servicio systemd.

He seguido las instrucciones aquí:
https://wiki.debian.org/Teams/pkg-systemd/Packaging

Agregué dh-systemd (>=1.5) a la compilación de mi archivo de control de Debian.

Agregué –with=systemd a mi archivo de reglas de la siguiente manera:

%:
    dh [email protected] --with=cli --with=systemd

Agregué mi archivo de servicio a mi carpeta de Debian llamada mypackage.service con el siguiente contenido:

[Unit]
Description=My Service Description
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/mono /usr/lib/mypackage/myservice.exe

[Install]
WantedBy=multi-user.target

Sin embargo, la construcción da las siguientes advertencias y errores lintian:

Now running lintian...
E: mypackage: postrm-does-not-call-updaterc.d-for-init.d-script     etc/init.d/mypackage
W: mypackage: init.d-script-not-marked-as-conffile etc/init.d/mypackage
E: mypackage: init.d-script-not-included-in-package etc/init.d/mypackage

Esto me confunde por varias razones

  1. Estas advertencias son sobre init.d, que es el sistema antiguo que se reemplaza por systemd, ¿son estos errores y advertencias simplemente incorrectos? ¿Piensa debuild que estoy usando init.d porque configuré mal mi paquete?
  2. Tenía la impresión de que –with=systemd crearía estos scripts para mí.

Actualizar

El archivo postrm generado es el siguiente:

#!/bin/sh
set -e
# Automatically added by dh_systemd_start
if [ -d /run/systemd/system ]; then
    systemctl --system daemon-reload >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_systemd_enable
if [ "$1" = "remove" ]; then
    if [ -x "/usr/bin/deb-systemd-helper" ]; then
        deb-systemd-helper mask mypackage.service >/dev/null
    fi
fi

if [ "$1" = "purge" ]; then
     if [ -x "/usr/bin/deb-systemd-helper" ]; then
        deb-systemd-helper purge mypackage.service >/dev/null
        deb-systemd-helper unmask mypackage.service >/dev/null
    fi
fi
# End automatically added section

el archivo prerm generado es el siguiente:

#!/bin/sh
set -e
# Automatically added by dh_systemd_start
if [ -d /run/systemd/system ]; then
    deb-systemd-invoke stop mypackage.service >/dev/null
fi
# End automatically added section
# Automatically added by dh_installinit
if [ -x "/etc/init.d/mypackage" ] || [ -e "/etc/init/mypackage.conf" ]; then
    invoke-rc.d mypackage stop || exit $?
fi
# End automatically added section

El paquete realmente se instala bien y el servicio se inicia correctamente. Los errores de Lintian son preocupantes y me gustaría llegar al fondo de ellos.

Respuesta aceptada:

Me encontré con este problema también. Esto es lo que se me ocurrió:

Querrá anular dh_installinit y dh_systemd_start, este es un ejemplo de mi servicio de puente de red:

#!/usr/bin/make -f

PKGDIR=debian/tmp

%:
    dh [email protected] --with systemd

override_dh_installinit:
    dh_systemd_enable -popenstack --name=openstack openstack.service
    dh_installinit -popenstack --no-start --noscripts
    dh_systemd_start -popenstack --no-restart-on-upgrade

override_dh_systemd_start:
    echo "Not running dh_systemd_start"

El código fuente completo de mi paquete se puede encontrar aquí:https://github.com/Ubuntu-Solutions-Engineering/openstack-deb/tree/master/debian

Relacionado:¿Qué herramientas de administración de tareas y tiempo están disponibles?

También usé https://github.com/lxc/lxd-pkg-ubuntu/blob/dpm-xenial/debian/rules como referencia.

Espero que esto te ayude, ya que me tomó un poco de tiempo resolverlo.


Ubuntu
  1. Cómo administrar los servicios de Systemd con Systemctl en Linux

  2. ¿Cómo escribir un script de inicio para Systemd?

  3. ¿Cómo instalar termitas?

  4. Cómo establecer valores ulimit para un servicio systemd

  5. ¿Cómo enviar un correo electrónico si se reinicia un servicio systemd?

Cómo ejecutar contenedores como servicio Systemd con Podman

Cómo habilitar o deshabilitar servicios en Ubuntu Systemd/Upstart

Cómo ejecutar Shell Script como servicio Systemd en Linux

Cómo aprendí a dejar de preocuparme y amar systemd

Cómo configurar la ejecución automática de un script de Python usando Systemd

Cómo ejecutar Shell Script como servicio SystemD en Linux