diff --git a/imageroot/systemd/user/mariadb-app.service b/imageroot/systemd/user/mariadb-app.service new file mode 100644 index 0000000..2c7b3d3 --- /dev/null +++ b/imageroot/systemd/user/mariadb-app.service @@ -0,0 +1,39 @@ +# +# Copyright (C) 2023 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +[Unit] +Description=Podman mariadb-app.service +BindsTo=sogo.service +After=sogo.service + +[Service] +Environment=PODMAN_SYSTEMD_UNIT=%n +EnvironmentFile=%S/state/environment +Restart=always +TimeoutStopSec=70 +ExecStartPre=/bin/rm -f %t/mariadb-app.pid %t/mariadb-app.ctr-id +ExecStart=/usr/bin/podman run --conmon-pidfile %t/mariadb-app.pid \ + --cidfile %t/mariadb-app.ctr-id --cgroups=no-conmon \ + --pod-id-file %t/sogo.pod-id --replace -d --name mariadb-app \ + --env-file=%S/state/environment \ + --volume mysql-data:/var/lib/mysql/:Z \ + --env MARIADB_ROOT_PASSWORD=Nethesis,1234 \ + --env MARIADB_DATABASE=sogo \ + --env MARIADB_USER=sogo \ + --env MARIADB_PASSWORD=Nethesis,1234 \ + --env MARIADB_AUTO_UPGRADE=1 \ + ${MARIADB_IMAGE} \ + --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci +ExecStartPost=/usr/bin/podman exec mariadb-app /bin/bash -c 'printf "[client] \npassword=Nethesis,1234" > /root/.my.cnf' +ExecStartPost=/usr/bin/podman exec mariadb-app /bin/bash -c "while ! mysqladmin ping -h localhost -P 3306 -u root; do sleep 1; done" +ExecStop=/usr/bin/podman stop --ignore --cidfile %t/mariadb-app.ctr-id -t 10 +ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/mariadb-app.ctr-id +ExecReload=/usr/bin/podman kill -s HUP mariadb-app +SyslogIdentifier=%u +PIDFile=%t/mariadb-app.pid +Type=forking + +[Install] +WantedBy=default.target diff --git a/imageroot/systemd/user/sogo-app.service b/imageroot/systemd/user/sogo-app.service new file mode 100644 index 0000000..1f28818 --- /dev/null +++ b/imageroot/systemd/user/sogo-app.service @@ -0,0 +1,42 @@ +# +# Copyright (C) 2023 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +[Unit] +Description=Podman sogo-app.service +BindsTo=sogo.service +After=sogo.service mariadb-app.service + +[Service] +Environment=PODMAN_SYSTEMD_UNIT=%n +EnvironmentFile=%S/state/environment +EnvironmentFile=-%S/state/discovery.env +WorkingDirectory=%S/state +Restart=always +TimeoutStopSec=70 +ExecStartPre=/bin/mkdir -p config +ExecStartPre=/bin/rm -f %t/sogo-app.pid %t/sogo-app.ctr-id +ExecStartPre=runagent discover-ldap +ExecStartPre=/usr/local/bin/runagent discover-service +ExecStart=/usr/bin/podman run --conmon-pidfile %t/sogo-app.pid \ + --cidfile %t/sogo-app.ctr-id --cgroups=no-conmon \ + --pod-id-file %t/sogo.pod-id --replace -d --name sogo-app \ + --volume ./config:/etc/sogo:Z \ + --env=sogo_* \ + --env sogo_DB_TYPE=mysql \ + --env sogo_DB_HOST=127.0.0.1 \ + --env sogo_DB_PORT=3306 \ + --env sogo_DB_USER=sogo \ + --env sogo_DB_PASSWORD=Nethesis,1234 \ + --env sogo_DB_NAME=sogo \ + ${sogo_IMAGE} +ExecStop=/usr/bin/podman stop --ignore --cidfile %t/sogo-app.ctr-id -t 10 +ExecReload=/usr/bin/podman kill -s HUP sogo-app +SyslogIdentifier=%u +ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/sogo-app.ctr-id +PIDFile=%t/sogo-app.pid +Type=forking + +[Install] +WantedBy=default.target diff --git a/imageroot/systemd/user/sogo.service b/imageroot/systemd/user/sogo.service index ac13329..445aab5 100644 --- a/imageroot/systemd/user/sogo.service +++ b/imageroot/systemd/user/sogo.service @@ -7,27 +7,26 @@ # This systemd unit starts a sogo instance using Podman. # Most parts of this file come from podman-generate-systemd. # + [Unit] -Description=sogo server +Description=Podman sogo.service +Requires=mariadb-app.service sogo-app.service +Before=mariadb-app.service sogo-app.service [Service] Environment=PODMAN_SYSTEMD_UNIT=%n -EnvironmentFile=%S/state/environment -WorkingDirectory=%S/state +EnvironmentFile=-%S/state/environment Restart=always -ExecStartPre=/bin/rm -f %t/sogo.pid %t/sogo.ctr-id -ExecStartPre=-runagent discover-smarthost -ExecStart=/usr/bin/podman run \ - --detach \ - --conmon-pidfile=%t/sogo.pid \ - --cidfile=%t/sogo.ctr-id \ - --cgroups=no-conmon \ - --replace --name=%N \ - --publish=127.0.0.1:${TCP_PORT}:8080 \ - --env-file=smarthost.env \ - ${ECHO_SERVER_IMAGE} -ExecStop=/usr/bin/podman stop --ignore --cidfile %t/sogo.ctr-id -t 10 -ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/sogo.ctr-id +TimeoutStopSec=70 +ExecStartPre=/bin/rm -f %t/sogo.pid %t/sogo.pod-id +ExecStartPre=/usr/bin/podman pod create --infra-conmon-pidfile %t/sogo.pid \ + --pod-id-file %t/sogo.pod-id \ + --name sogo \ + --publish 127.0.0.1:${TCP_PORT}:20001 \ + --replace +ExecStart=/usr/bin/podman pod start --pod-id-file %t/sogo.pod-id +ExecStop=/usr/bin/podman pod stop --ignore --pod-id-file %t/sogo.pod-id -t 10 +ExecStopPost=/usr/bin/podman pod rm --ignore -f --pod-id-file %t/sogo.pod-id PIDFile=%t/sogo.pid Type=forking