Podman container as systemd service with quadlet

Since podman generate systemd is depracated, here is a way to create container service. Example on Prometheus. Setup:

$ podman --version
podman version 4.9.3
$ cat /etc/os-release | head -n1
PRETTY_NAME="Ubuntu 24.04.1 LTS"

Create system user only to run containers:

$ adduser --system --disabled-login podman
$ cat /etc/passwd | grep podman
podman:x:110:65534::/home/podman:/usr/sbin/nologin

Decide where to make persistent volumes for container. I chose /home/podman/.

$ mkdir -p /home/podman/prometheus/data
$ mkdir -p /home/podman/prometheus/config
$ chown -R podman:nogroup /home/podman/*
$ tree /home/podman/
/home/podman/
└── prometheus
    ├── config
    │   └── prometheus.yml
    └── data

Create .container file in one of locations as stated in documentation podman-systemd.unit. I created in /etc/containers/systemd/.

$ cat /etc/containers/systemd/prometheus.container
[Unit]
Description=Prometheus container

[Container]
Image=docker.io/prom/prometheus #latest image
ContainerName=prometheus
Volume=/home/podman/prometheus/data:/prometheus
Volume=/home/podman/prometheus/config:/etc/prometheus #containing prometheus.yml config
PublishPort=9090:9090
User=110 # UID of user podman I created

[Service]
# Restart service when failed
Restart=always

[Install]
WantedBy=multi-user.target
DefaultInstance=100
$
$ systemctl daemon-reload
$ service prometheus start
Share:

Install Hyper-V guest services on Ubuntu and Debian VM's

Ubuntu:

Add to /etc/initramfs-tools/modules

hv_utils
hv_vmbus
hv_storvsc
hv_blkvsc
hv_netvsc

Install

apt install linux-virtual linux-cloud-tools-virtual linux-tools-virtual

Update initramfs:

update-initramfs -u

Reboot. Done.

Debian:

apt install hyperv-daemons
Share:

Run Gitlab pipeline job on multiple runners - template

.deploy: 		# template to run
  tags:
    - $HOST_TAG
    - prod
  script:
    - ...
deploy-nodes:
  stage: deploy
  only: 		# execute only on main branch
    - main
  needs: 		# run only if test-nodes passed
    - test-nodes
  extends: .deploy 	# exetue script from
  parallel: 		# run jobs in parrallel
    matrix: 		# specify tags to run on
      - HOST_TAG:
        - hostname01
        - hostname02
        - ...

Share:

MySQL databases and tables size.

Databases size:

SELECT table_schema AS "Database",  ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"  FROM information_schema.TABLES  GROUP BY table_schema;

Tables size in database:

SELECT table_name AS "Table", ROUND(((data_length + index_length) / 1024 / 1024 / 1024), 2) AS "Size (GB)" FROM information_schema.TABLES WHERE table_schema = "[database_name]" ORDER BY (data_length + index_length) DESC limit 5;

Share:

It's always DNS

When your server responds too long for some packets and application gets timeout, ask your DNS server if it has reverse proxy zone for that address. If not, for troubleshooting you can try add line in hosts file and see if that resolve issue. 

Share:

'Too many open files' in log file - resolution

Too many open files and service crashes. Edit serivce:

systemctl edit [service_name]

Add in file in correct section:

[Service]
LimitNOFILE=65536
LimitSTACK=infinity
LimitNPROC=16384
TasksMax=8192

Reload systemctl:

systemctl daemon-reload

Restart service:

systemctl restart [service_name]
Share:

Add disk to lvm

List of commands to add new disk to lvm and add storage to /.

Format drive fdisk /dev/sdb:

[root@centos7 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x4507ff75.
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-16777215, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): 
Using default value 16777215
Partition 1 of type Linux and of size 8 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Create pv on sdb1

pvcreate /dev/sdb1

Add to vg

vgextend name_of_vg /dev/sdb1

lvresize -l +100%free path_of_lv

find out file system on partition 

grep root /etc/mtab

case:

    xfs: 

xfs_growfs /dev/mapper/...

    ext4:

 resize2fs /dev/mapper/...

done

Share: