calibre-web: run under systemd, not docker restart policy
Testbed for systemd-owned containers; gains boot, crash, and
docker-restart recovery that restart_policy lacks. Not yet deploying —
systemd reports the unit not-found, under investigation.
Assisted-by: Claude Opus 4.7 (1M context) via Claude Code
diff --git a/lotus-land-story/calibre-web.yml b/lotus-land-story/calibre-web.yml
index 6892f1f..1cd6055 100644
--- a/lotus-land-story/calibre-web.yml
+++ b/lotus-land-story/calibre-web.yml
@@ -1,36 +1,39 @@
- name: Set up Calibre-web
hosts: lotus-land-story
+ vars:
+ version: 0.6.26-ls383
+ volumes:
+ /mnt/lotus-land-story/calibre-web/books: /books
+ /mnt/lotus-land-story/calibre-web/config: /config
tasks:
- name: Create directories for volume mounting
ansible.builtin.file:
- path: /mnt/lotus-land-story/calibre-web/{{ item }}
+ path: "{{ item }}"
state: directory
mode: "0755"
- loop:
- - books
- - config
+ loop: "{{ volumes.keys() | list }}"
- # https://github.com/linuxserver/docker-calibre-web#docker-compose-recommended-click-here-for-more-info
- - name: Run Calibre-web
- community.docker.docker_container:
+ # https://github.com/linuxserver/docker-calibre-web
+ - name: Install calibre-web systemd unit
+ ansible.builtin.template:
+ src: templates/systemd/calibre-web.service
+ dest: /etc/systemd/system/calibre-web.service
+ mode: "0644"
+ notify: Restart calibre-web
+
+ - name: Enable and start calibre-web
+ ansible.builtin.systemd_service:
name: calibre-web
- image: lscr.io/linuxserver/calibre-web:latest
- restart: true
- env:
- PUID: "0"
- PGID: "0"
- TZ: Etc/UTC
- DOCKER_MODS: linuxserver/mods:universal-calibre
- volumes:
- - /mnt/lotus-land-story/calibre-web/books:/books
- - /mnt/lotus-land-story/calibre-web/config:/config
- restart_policy: unless-stopped
- networks:
- - name: lotus_land_story
+ enabled: true
+ state: started
+ daemon_reload: true
handlers:
- - name: Import restarts
- ansible.builtin.import_tasks: restarts.yml
+ - name: Restart calibre-web
+ ansible.builtin.systemd_service:
+ name: calibre-web
+ state: restarted
+ daemon_reload: true
# vim: ft=yaml.ansible
diff --git a/lotus-land-story/templates/systemd/calibre-web.service b/lotus-land-story/templates/systemd/calibre-web.service
new file mode 100644
index 0000000..3b126f8
--- /dev/null
+++ b/lotus-land-story/templates/systemd/calibre-web.service
@@ -0,0 +1,23 @@
+[Unit]
+Description=Calibre-web container
+Requires=docker.service
+After=docker.service
+PartOf=docker.service
+
+[Service]
+Restart=always
+RestartSec=5s
+ExecStartPre=-/usr/bin/docker rm -f calibre-web
+ExecStartPre=-/usr/bin/docker pull lscr.io/linuxserver/calibre-web:{{ version }}
+ExecStart=/usr/bin/docker run --rm --name calibre-web \
+ --network lotus_land_story \
+ -e PUID=0 -e PGID=0 -e TZ=Etc/UTC \
+ -e DOCKER_MODS=linuxserver/mods:universal-calibre \
+{% for host_path, container_path in volumes.items() %}
+ -v {{ host_path }}:{{ container_path }} \
+{% endfor %}
+ lscr.io/linuxserver/calibre-web:{{ version }}
+ExecStop=/usr/bin/docker stop calibre-web
+
+[Install]
+WantedBy=multi-user.target