From 38a2de58589ec00585166920a9a6ebc51b6f9be7 Mon Sep 17 00:00:00 2001 From: lubiana Date: Sun, 23 Jun 2024 08:49:44 +0200 Subject: [PATCH 1/2] add unit files --- deploy/etc/php83/php-fpm.d/www.conf | 7 ++- .../systemd/container-futtern-caddy.service | 43 +++++++++++++++++ deploy/systemd/container-futtern-php.service | 46 +++++++++++++++++++ deploy/systemd/pod-futtern.service | 42 +++++++++++++++++ deploy/update.sh | 8 ++++ 5 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 deploy/systemd/container-futtern-caddy.service create mode 100644 deploy/systemd/container-futtern-php.service create mode 100644 deploy/systemd/pod-futtern.service create mode 100644 deploy/update.sh diff --git a/deploy/etc/php83/php-fpm.d/www.conf b/deploy/etc/php83/php-fpm.d/www.conf index edf975a..e5a895d 100644 --- a/deploy/etc/php83/php-fpm.d/www.conf +++ b/deploy/etc/php83/php-fpm.d/www.conf @@ -1,7 +1,7 @@ [www] -user = nobody -group = nobody +user = root +group = root listen = 9001 pm = dynamic pm.max_children = 5 @@ -10,5 +10,4 @@ pm.min_spare_servers = 1 pm.max_spare_servers = 3 env[APP_ENV]=$APP_ENV env[APP_SECRET]=$APP_SECRET -error_log = /var/log/php-fpm.log -catch_workers_output = yes \ No newline at end of file +catch_workers_output = yes diff --git a/deploy/systemd/container-futtern-caddy.service b/deploy/systemd/container-futtern-caddy.service new file mode 100644 index 0000000..2c7e3f6 --- /dev/null +++ b/deploy/systemd/container-futtern-caddy.service @@ -0,0 +1,43 @@ +# container-futtern-caddy.service +# autogenerated by Podman 4.3.1 +# Sun Jun 23 05:33:51 UTC 2024 + +[Unit] +Description=Podman container-futtern-caddy.service +Documentation=man:podman-generate-systemd(1) +Wants=network-online.target +After=network-online.target +RequiresMountsFor=%t/containers +BindsTo=pod-futtern.service +After=pod-futtern.service + +[Service] +Environment=PODMAN_SYSTEMD_UNIT=%n +Restart=on-failure +TimeoutStopSec=70 +ExecStartPre=/bin/rm \ + -f %t/%n.ctr-id +ExecStart=/usr/bin/podman run \ + --cidfile=%t/%n.ctr-id \ + --cgroups=no-conmon \ + --rm \ + --pod-id-file %t/pod-futtern.pod-id \ + --sdnotify=conmon \ + --replace \ + -d \ + --name futtern-caddy \ + --volume /home/c3h-futtern/etc/caddy/Caddyfile:/etc/caddy/Caddyfile \ + --volume /home/c3h-futtern/futtern-app:/var/www/html \ + --volume caddy_data:/data docker.io/caddy/caddy:alpine +ExecStop=/usr/bin/podman stop \ + --ignore -t 10 \ + --cidfile=%t/%n.ctr-id +ExecStopPost=/usr/bin/podman rm \ + -f \ + --ignore -t 10 \ + --cidfile=%t/%n.ctr-id +Type=notify +NotifyAccess=all + +[Install] +WantedBy=default.target diff --git a/deploy/systemd/container-futtern-php.service b/deploy/systemd/container-futtern-php.service new file mode 100644 index 0000000..cec0498 --- /dev/null +++ b/deploy/systemd/container-futtern-php.service @@ -0,0 +1,46 @@ +# container-futtern-php.service +# autogenerated by Podman 4.3.1 +# Sun Jun 23 05:33:51 UTC 2024 + +[Unit] +Description=Podman container-futtern-php.service +Documentation=man:podman-generate-systemd(1) +Wants=network-online.target +After=network-online.target +RequiresMountsFor=%t/containers +BindsTo=pod-futtern.service +After=pod-futtern.service + +[Service] +Environment=PODMAN_SYSTEMD_UNIT=%n +Restart=on-failure +TimeoutStopSec=70 +ExecStartPre=/bin/rm \ + -f %t/%n.ctr-id +ExecStart=/usr/bin/podman run \ + --cidfile=%t/%n.ctr-id \ + --cgroups=no-conmon \ + --rm \ + --pod-id-file %t/pod-futtern.pod-id \ + --sdnotify=conmon \ + --replace \ + -d \ + --name futtern-php \ + --volume /home/c3h-futtern/etc/php83/php-fpm.d/www.conf:/etc/php83/php-fpm.d/www.conf \ + --volume /home/c3h-futtern/futtern-app:/var/www/html \ + --volume /home/c3h-futtern/var:/var/www/html/var \ + --env APP_ENV=prod \ + --env APP_SECRET=UwUtHiSisNotSecurePlZcHanGeMe \ + git.php.fail/lubiana/container/php:8.3-fpm +ExecStop=/usr/bin/podman stop \ + --ignore -t 10 \ + --cidfile=%t/%n.ctr-id +ExecStopPost=/usr/bin/podman rm \ + -f \ + --ignore -t 10 \ + --cidfile=%t/%n.ctr-id +Type=notify +NotifyAccess=all + +[Install] +WantedBy=default.target diff --git a/deploy/systemd/pod-futtern.service b/deploy/systemd/pod-futtern.service new file mode 100644 index 0000000..3189e8c --- /dev/null +++ b/deploy/systemd/pod-futtern.service @@ -0,0 +1,42 @@ +# pod-futtern.service +# autogenerated by Podman 4.3.1 +# Sun Jun 23 05:33:51 UTC 2024 + +[Unit] +Description=Podman pod-futtern.service +Documentation=man:podman-generate-systemd(1) +Wants=network-online.target +After=network-online.target +RequiresMountsFor=/run/user/1006/containers +Wants=container-futtern-caddy.service container-futtern-php.service +Before=container-futtern-caddy.service container-futtern-php.service + +[Service] +Environment=PODMAN_SYSTEMD_UNIT=%n +Restart=on-failure +TimeoutStopSec=70 +ExecStartPre=/bin/rm \ + -f %t/pod-futtern.pid %t/pod-futtern.pod-id +ExecStartPre=/usr/bin/podman pod create \ + --infra-conmon-pidfile %t/pod-futtern.pid \ + --pod-id-file %t/pod-futtern.pod-id \ + --exit-policy=stop \ + --label io.containers.autoupdate=registry \ + --name futtern \ + -p 8087:8087 \ + --replace +ExecStart=/usr/bin/podman pod start \ + --pod-id-file %t/pod-futtern.pod-id +ExecStop=/usr/bin/podman pod stop \ + --ignore \ + --pod-id-file %t/pod-futtern.pod-id \ + -t 10 +ExecStopPost=/usr/bin/podman pod rm \ + --ignore \ + -f \ + --pod-id-file %t/pod-futtern.pod-id +PIDFile=%t/pod-futtern.pid +Type=forking + +[Install] +WantedBy=default.target diff --git a/deploy/update.sh b/deploy/update.sh new file mode 100644 index 0000000..4d7548a --- /dev/null +++ b/deploy/update.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +systemctl --user stop pod-futtern +systemctl --user start pod-futtern +sleep 2 +podman exec -it futtern-php /var/www/html/bin/console cache:clear +podman exec -it futtern-php /var/www/html/bin/console cache:warmup +echo 'yes' | podman exec -it futtern-php /var/www/html/bin/console doctrine:migrations:migrate From 14bb4a15421fcac9c07c43a6ea6cc9468c389896 Mon Sep 17 00:00:00 2001 From: lubiana Date: Sun, 23 Jun 2024 09:21:20 +0200 Subject: [PATCH 2/2] update deployment paths --- .gitignore | 2 +- deploy/install.sh | 31 ------------------- deploy/prepare-deploy.sh | 2 +- .../systemd/container-futtern-caddy.service | 4 +-- deploy/systemd/container-futtern-php.service | 6 ++-- deploy/systemd/pod-futtern.service | 2 +- 6 files changed, 8 insertions(+), 39 deletions(-) delete mode 100755 deploy/install.sh diff --git a/.gitignore b/.gitignore index 62752be..feabc44 100644 --- a/.gitignore +++ b/.gitignore @@ -20,5 +20,5 @@ ###< phpunit/phpunit ### .idea/ -/deploy/futtern-app/ /deploy/var/ +/deploy/app/ diff --git a/deploy/install.sh b/deploy/install.sh deleted file mode 100755 index d4b64b7..0000000 --- a/deploy/install.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env sh - -if [ ! -d "var" ]; then - mkdir var -fi -podman pod stop futtern -podman pod rm futtern - -podman pod create \ - --label "io.containers.autoupdate=registry" \ - --name futtern \ - -p 8087:8087 - -podman run -d \ - --pod futtern \ - --name futtern-php \ - --volume $(pwd)/etc/php83/php-fpm.d/www.conf:/etc/php83/php-fpm.d/www.conf \ - --volume $(pwd)/futtern-app:/var/www/html \ - --volume $(pwd)/var:/var/www/html/var \ - --env 'APP_ENV=prod' \ - git.php.fail/lubiana/container/php:8.3-fpm - -podman run -d \ - --pod futtern \ - --name futtern-caddy \ - --volume $(pwd)/etc/caddy/Caddyfile:/etc/caddy/Caddyfile \ - --volume $(pwd)/futtern-app:/var/www/html \ - --volume caddy_data:/data \ - docker.io/caddy/caddy:alpine - -echo 'yes' | podman exec -it futtern-php /var/www/html/bin/console doctrine:migrations:migrate diff --git a/deploy/prepare-deploy.sh b/deploy/prepare-deploy.sh index d8c92fa..5bb412a 100755 --- a/deploy/prepare-deploy.sh +++ b/deploy/prepare-deploy.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -TARGETDIR='deploy/futtern-app' +TARGETDIR='deploy/app' if [ -d $TARGETDIR ]; then rm -rf $TARGETDIR diff --git a/deploy/systemd/container-futtern-caddy.service b/deploy/systemd/container-futtern-caddy.service index 2c7e3f6..1067128 100644 --- a/deploy/systemd/container-futtern-caddy.service +++ b/deploy/systemd/container-futtern-caddy.service @@ -26,8 +26,8 @@ ExecStart=/usr/bin/podman run \ --replace \ -d \ --name futtern-caddy \ - --volume /home/c3h-futtern/etc/caddy/Caddyfile:/etc/caddy/Caddyfile \ - --volume /home/c3h-futtern/futtern-app:/var/www/html \ + --volume %h/futtern/etc/caddy/Caddyfile:/etc/caddy/Caddyfile \ + --volume %h/futtern/app:/var/www/html \ --volume caddy_data:/data docker.io/caddy/caddy:alpine ExecStop=/usr/bin/podman stop \ --ignore -t 10 \ diff --git a/deploy/systemd/container-futtern-php.service b/deploy/systemd/container-futtern-php.service index cec0498..e6f139c 100644 --- a/deploy/systemd/container-futtern-php.service +++ b/deploy/systemd/container-futtern-php.service @@ -26,9 +26,9 @@ ExecStart=/usr/bin/podman run \ --replace \ -d \ --name futtern-php \ - --volume /home/c3h-futtern/etc/php83/php-fpm.d/www.conf:/etc/php83/php-fpm.d/www.conf \ - --volume /home/c3h-futtern/futtern-app:/var/www/html \ - --volume /home/c3h-futtern/var:/var/www/html/var \ + --volume %h/futtern/etc/php83/php-fpm.d/www.conf:/etc/php83/php-fpm.d/www.conf \ + --volume %h/futtern/app:/var/www/html \ + --volume %h/futtern/app/var:/var/www/html/var \ --env APP_ENV=prod \ --env APP_SECRET=UwUtHiSisNotSecurePlZcHanGeMe \ git.php.fail/lubiana/container/php:8.3-fpm diff --git a/deploy/systemd/pod-futtern.service b/deploy/systemd/pod-futtern.service index 3189e8c..10a8fb0 100644 --- a/deploy/systemd/pod-futtern.service +++ b/deploy/systemd/pod-futtern.service @@ -7,7 +7,7 @@ Description=Podman pod-futtern.service Documentation=man:podman-generate-systemd(1) Wants=network-online.target After=network-online.target -RequiresMountsFor=/run/user/1006/containers +RequiresMountsFor=/run/user/%U/containers Wants=container-futtern-caddy.service container-futtern-php.service Before=container-futtern-caddy.service container-futtern-php.service