<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dururustem on Medium]]></title>
        <description><![CDATA[Stories by Dururustem on Medium]]></description>
        <link>https://medium.com/@dururustem68?source=rss-acd15b56347e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YXib2se-DHeC2i9o</url>
            <title>Stories by Dururustem on Medium</title>
            <link>https://medium.com/@dururustem68?source=rss-acd15b56347e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 02:23:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dururustem68/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I spent my mornings reading Wazuh alerts, so I built an on-call companion for it]]></title>
            <link>https://medium.com/@dururustem68/i-spent-my-mornings-reading-wazuh-alerts-so-i-built-an-on-call-companion-for-it-80d4f41ca6d9?source=rss-acd15b56347e------2</link>
            <guid isPermaLink="false">https://medium.com/p/80d4f41ca6d9</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[wazuh]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Dururustem]]></dc:creator>
            <pubDate>Thu, 19 Nov 2026 08:20:16 GMT</pubDate>
            <atom:updated>2026-11-19T08:20:16.579Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Occultera is an open-source tool that watches Wazuh around the clock, pages you when something is urgent, and asks an AI to explain the rest. Personal data is masked before the model sees it.</em></p><p>I look after three Wazuh installations. For a long time my day started the same way: open the dashboard, check that data is still flowing, see which agents dropped off, scroll through the level 7+ alerts, and decide which of them are the usual noise. On a quiet day that took half an hour. On a busy one it took the whole morning, and the one alert that mattered could still sit between two thousand failed SSH logins from a scanner.</p><p>Wazuh is very good at producing alerts. It does not help much with reading them. So I started writing a tool for my own mornings, and after a few months it became Occultera.</p><h3>Two loops</h3><p>The first thing I learned is that urgent alerts and the daily review need different machinery.</p><p><strong>The watch</strong> runs every few minutes and never calls a model. Local rules decide what is urgent: a level 12+ alert, a successful login right after a burst of failures, Active Response firing, a sudden spike for one rule, agents that stop reporting, or a Kubernetes workload sending far more data out than it did all week. These go to Teams, Telegram, Slack, e-mail or a webhook within minutes. Quiet hours hold everything except critical events, and a burst the same rules already produced this week (nightly backups, scheduled scans) stays on the watch page without waking anyone.</p><p><strong>The AI round</strong> runs once or twice a day. The model gets read-only tools (alert search, rule timelines, IP profiles, correlation around an event, logtest) and writes one report: findings with the queries that back them, a verdict on every watch event, questions it could not answer alone, and rule drafts for the noise it found. You can use Claude, OpenAI, Gemini, DeepSeek or a local model through Ollama or vLLM.</p><p>Keeping these apart means an incident at 3 a.m. does not wait for a model, and the model never has to make a decision in a hurry.</p><h3>Nothing changes without a person</h3><p>Occultera reads from Wazuh and writes only to its own indices. When the AI thinks a rule is too noisy, it drafts a child rule. Before anyone approves it, the draft is replayed against two weeks of real alerts, so you can see how many it would have matched and at which levels. It is checked with logtest and deployed with an automatic rollback if the manager does not come back cleanly. After deployment the tool checks that the rule actually fired on live events, and (from the next release) it measures the effect: level 7+ alerts of that rule family per day, before and after.</p><p>Every answer you give and every decision you make goes into a knowledge base that the next round reads. After a couple of weeks the reports stop asking about the backup server.</p><h3>Sending alerts to an LLM is sending personal data</h3><p>This was the part I worried about most. Wazuh alerts contain e-mail addresses in mail logs, national ID numbers in application logs, IBANs in payment errors and the occasional password in a URL. Sending that to a hosted model is a GDPR question, and in Turkey a KVKK question.</p><p>Occultera replaces detected personal data with stable pseudonyms inside your installation before anything leaves it. ayse@firma.com.tr becomes &lt;email:3f9a…&gt; every time, so the model can still see that one account failed 40 logins from three countries without knowing whose account it was. Secrets (passwords, tokens, JWTs, private keys) are removed outright. Reports map the pseudonyms back, so your team reads real values.</p><p>I wanted honest numbers here, so there is a test set of Turkish-first examples in the repository. In the current main branch the default profile masks 14 of 18 personal-data samples, with no false positives on 7 look-alikes such as run IDs and epoch timestamps. Names in free text, usernames, addresses and licence plates are not detected by default, and IP addresses are kept because most of the analysis is about them. You can add your own patterns from the UI and preview what the model would receive. If your data is regulated, use a provider under a data-processing agreement or a local model.</p><h3>Ask your Wazuh from Claude or Cursor</h3><p>The same tools the AI round uses are exposed through a built-in MCP server. Connect Claude Desktop, Claude Code, Cursor or VS Code and ask “what happened on webserver last night?” The answers come from live data and go through the same masking. Nothing in the MCP server can change Wazuh; the most an assistant can do is file a proposal that a person approves in the UI.</p><h3>What it is not</h3><p>It is not a SOAR. It does not block IPs, isolate hosts or run commands on agents. It is not a replacement for Wazuh or for an analyst, and it does not make anyone ISO 27001 or GDPR compliant. It is one container that keeps its data in your own Wazuh indexer, so there is no extra database to run.</p><h3>Try it</h3><p>The demo needs no Wazuh and no API key. To see the MCP tools from any MCP client:</p><pre>docker run -i --rm -e WDT_DEMO=true ghcr.io/occultera/occultera:0.15.0 python -m app.mcp_stdio</pre><p>To see the web UI with synthetic data:</p><pre>git clone https://github.com/occultera/occultera.git<br>cd occultera<br>cp .env.demo .env<br>docker compose up -d --build</pre><p>Then open <a href="http://127.0.0.1:8080/">http://127.0.0.1:8080</a> and sign in with demo-password-change-me. Docker Compose, Helm and Kustomize are supported for real installations.</p><p>Occultera is AGPL-3.0, written in Python, and works with Wazuh 4.x. The interface is available in English, Turkish, Spanish and German; French comes with the next release.</p><ul><li>Website: <a href="https://occultera.dev/">https://occultera.dev</a></li><li>Code: <a href="https://github.com/occultera/occultera">https://github.com/occultera/occultera</a></li><li>Docs: <a href="https://github.com/occultera/occultera/wiki">https://github.com/occultera/occultera/wiki</a></li></ul><p>If you run Wazuh and try it, I would like to hear which alerts it got wrong. Issues are open on GitHub.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80d4f41ca6d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Compose ile Çalışan Harbor Registry’yi Sunucu Restart Sonrası Otomatik Ayağa Kaldırma…]]></title>
            <link>https://medium.com/@dururustem68/docker-compose-ile-%C3%A7al%C4%B1%C5%9Fan-harbor-registryyi-sunucu-restart-sonras%C4%B1-otomatik-aya%C4%9Fa-kald%C4%B1rma-c44e09446e32?source=rss-acd15b56347e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c44e09446e32</guid>
            <category><![CDATA[harbor]]></category>
            <category><![CDATA[harbor-service]]></category>
            <category><![CDATA[harbor-restart]]></category>
            <dc:creator><![CDATA[Dururustem]]></dc:creator>
            <pubDate>Fri, 22 May 2026 13:16:24 GMT</pubDate>
            <atom:updated>2026-05-22T13:16:24.831Z</atom:updated>
            <content:encoded><![CDATA[<p>Docker Compose ile Çalışan Harbor Registry’yi Sunucu Restart Sonrası Otomatik Ayağa Kaldırma<br>=============================================================================================</p><p>Alt başlık: systemd, restart policy ve cron health check ile üç katmanlı koruma</p><p>Giriş<br> — — -</p><p>Harbor, kurumsal ortamlarda yaygın olarak kullanılan bir container registry çözümü. Docker Compose ile kurulduğunda genellikle sorunsuz çalışır, ancak sunucu güncellemeleri, kernel patch’leri veya beklenmedik restart durumlarında Harbor container’ları otomatik olarak ayağa kalkmayabilir. Özellikle production ortamlarında bu durum, CI/CD pipeline’larının veya image pull işlemlerinin kesintiye uğramasına yol açar.</p><p>Bu yazıda Harbor’ın (veya benzer Docker Compose tabanlı servislerin) sunucu restart sonrası otomatik olarak ve güvenilir şekilde ayağa kalkması için üç katmanlı bir çözüm yaklaşımını paylaşacağım:</p><p>1. Docker Compose restart policy<br>2. systemd service<br>3. Cron tabanlı health check (yedek katman)</p><p>Her birinin neden gerekli olduğunu ve birlikte nasıl çalıştıklarını anlatacağım.</p><p>Problem<br> — — — -</p><p>Harbor’ı standart `install.sh` ile kurduğunda, `docker-compose.yml` dosyasındaki container’ların restart policy’si genellikle `always` olarak gelir. Bu policy şu anlama gelir: container hangi sebeple durursa dursun (manuel stop dahil), Docker daemon onu tekrar başlatır.</p><p>Ancak `always` policy’sinin bir sorunu var: bakım amaçlı manuel olarak `docker compose down` çektiğinde bile Docker bir sonraki restart’ta container’ları geri açmaya çalışır. Daha da önemlisi, eğer Docker servisi düzgün şekilde restart edilmediyse veya `docker compose down` ile servisler kapatıldıysa, sunucu yeniden başladığında container’lar ayağa kalkmayabilir.</p><p>İdeal davranış şudur:<br>- Manuel `docker compose down` yapıldıysa container’lar kapalı kalmalı<br>- Sunucu restart olduysa container’lar otomatik açılmalı<br>- Container crash olduysa otomatik restart edilmeli<br>- Bir şekilde hepsi başarısız olursa, bir güvenlik ağı devreye girmeli</p><p>Adım 1: Restart Policy’yi `unless-stopped` Yapmak<br> — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>İlk adım, restart policy’sini `always` yerine `unless-stopped` olarak değiştirmek. Bu policy daha doğru semantiğe sahip: manuel olarak durdurulmadıkça container’lar her zaman çalışsın.</p><p>Harbor compose dosyasındaki tüm `restart: always` satırlarını tek bir sed komutuyla değiştirebilirsin:</p><p># Yedek alarak değiştir<br> sed -i.bak ‘s/restart: always/restart: unless-stopped/g’ /opt/harbor/docker-compose.yml<br> <br> # Değişiklikleri kontrol et<br> grep -n “restart:” /opt/harbor/docker-compose.yml</p><p>Değişiklik sonrası policy’nin çalışan container’larda da uygulanması için iki seçenek var:</p><p>Seçenek 1: Container’ları yeniden oluştur (kısa kesinti)</p><p>cd /opt/harbor<br> docker compose up -d — force-recreate</p><p>Seçenek 2: Çalışan container’ları hiç durdurmadan policy’yi güncelle (kesintisiz)</p><p>docker update — restart=unless-stopped $(docker ps -q — filter “name=harbor-”)</p><p>Production ortamlarında ikinci yöntemi tercih etmek mantıklı çünkü hizmet kesintisine yol açmaz.</p><p>Adım 2: systemd Service Oluşturmak<br> — — — — — — — — — — — — — — — — — -</p><p>Restart policy tek başına yeterli değildir çünkü `docker compose down` ile servisler kapatıldıysa veya Docker daemon’un başlangıç sırası bozulduysa Harbor ayağa kalkmaz. Bu yüzden systemd service kullanarak Harbor’ı sistemin bir parçası haline getirmek gerekir.</p><p>`/etc/systemd/system/harbor.service` dosyasını oluştur:</p><pre>[Unit]<br> Description=Harbor Container Registry<br> After=docker.service network-online.target<br> Requires=docker.service<br> Wants=network-online.target<br> <br> [Service]<br> Type=oneshot<br> RemainAfterExit=yes<br> WorkingDirectory=/opt/harbor<br> ExecStart=/usr/bin/docker compose up -d<br> ExecStop=/usr/bin/docker compose down<br> TimeoutStartSec=300<br> Restart=on-failure<br> RestartSec=30<br> <br> [Install]<br> WantedBy=multi-user.target</pre><p>Önemli noktalar:</p><p>- `After=docker.service network-online.target`: Harbor, Docker ve network tamamen hazır olduktan sonra başlar<br>- `Requires=docker.service`: Docker olmadan Harbor başlayamaz<br>- `Type=oneshot` + `RemainAfterExit=yes`: docker compose up -d komutu tamamlandıktan sonra servis “active” kalır<br>- `TimeoutStartSec=300`: Harbor’ın tüm servislerinin ayağa kalkması için 5 dakika tolerans<br>- `Restart=on-failure`: Başlatma başarısız olursa 30 saniye sonra tekrar dene</p><p>Servisi etkinleştir:</p><pre> systemctl daemon-reload<br> systemctl enable harbor.service<br> systemctl start harbor.service<br> systemctl status harbor.service</pre><p>Artık `systemctl stop harbor` ile Harbor’ı düzgün şekilde durdurabilir, `systemctl start harbor` ile başlatabilirsin. Sunucu restart olduğunda systemd otomatik olarak Harbor’ı ayağa kaldırır.</p><p>Adım 3: Cron ile Health Check Yedek Katmanı<br> — — — — — — — — — — — — — — — — — — — — — —</p><p>systemd ve restart policy çoğu durumda yeterlidir ama bazen Harbor container’ları çalışıyor görünmesine rağmen API yanıt vermeyebilir. Disk dolması, network sorunları veya internal database problemleri buna yol açabilir. Bu tarz durumlar için bir cron tabanlı health check script’i ek bir güvenlik katmanı sağlar.</p><p>`/usr/local/bin/harbor-healthcheck.sh` dosyasını oluştur:</p><pre>#!/bin/bash<br>HARBOR_DIR=&quot;/opt/harbor&quot;<br>HARBOR_URL=&quot;https://harbor.eaglessoft.com/api/v2.0/health&quot;<br>LOG_FILE=&quot;/var/log/harbor-healthcheck.log&quot;<br><br>log() {<br>    echo &quot;[$(date &#39;+%Y-%m-%d %H:%M:%S&#39;)] $1&quot; &gt;&gt; &quot;$LOG_FILE&quot;<br>}<br><br># HTTP health check<br>HTTP_CODE=$(curl -s -o /dev/null -w &quot;%{http_code}&quot; --max-time 10 &quot;$HARBOR_URL&quot;)<br><br>if [ &quot;$HTTP_CODE&quot; = &quot;200&quot; ]; then<br>    exit 0<br>fi<br><br>log &quot;Harbor health check failed (HTTP: $HTTP_CODE). Containers kontrol ediliyor...&quot;<br><br># Container sayısını kontrol et<br>RUNNING=$(cd &quot;$HARBOR_DIR&quot; &amp;&amp; docker compose ps --services --filter &quot;status=running&quot; | wc -l)<br>TOTAL=$(cd &quot;$HARBOR_DIR&quot; &amp;&amp; docker compose config --services | wc -l)<br><br>if [ &quot;$RUNNING&quot; -lt &quot;$TOTAL&quot; ]; then<br>    log &quot;Çalışan: $RUNNING / Toplam: $TOTAL. Harbor başlatılıyor...&quot;<br>    cd &quot;$HARBOR_DIR&quot; &amp;&amp; docker compose up -d &gt;&gt; &quot;$LOG_FILE&quot; 2&gt;&amp;1<br>    log &quot;Harbor up komutu çalıştırıldı.&quot;<br>else<br>    log &quot;Tüm container&#39;lar çalışıyor ama health endpoint yanıt vermiyor. Manuel kontrol gerekli.&quot;<br>fi</pre><p>script’i executable yap ve crontab’a ekle:</p><pre>chmod +x /usr/local/bin/harbor-healthcheck.sh</pre><p># crontab -e ile aç ve ekle:</p><pre>*/5 * * * * /usr/local/bin/harbor-healthcheck.sh</pre><p>Logların disk doldurmaması için logrotate yapılandırması (`/etc/logrotate.d/harbor-healthcheck`):</p><pre>/var/log/harbor-healthcheck.log {<br> weekly<br> rotate 4<br> compress<br> missingok<br> notifempty<br> }</pre><p>Bu script her 5 dakikada bir Harbor’ın health endpoint’ini kontrol eder. Eğer 200 dönmüyorsa ve container’ların bir kısmı down ise otomatik olarak `docker compose up -d` çalıştırır. Eğer tüm container’lar çalışıyor ama health bozuksa sadece log’a yazar (çünkü bu durumda restart işe yaramayabilir, manuel müdahale gerekir).</p><p>Üç Katmanın Birlikte Çalışması<br> — — — — — — — — — — — — — — — -</p><p>Bu üç katmanın birlikte çalışması şu senaryoları kapsar:</p><p>| Senaryo | Hangi Katman Çözer |<br>| — — — — — — — — — — — — — — — — — — — | — — — — — — — — — — -|<br>| Container crash oldu | Restart policy |<br>| Sunucu restart oldu | systemd |<br>| docker compose down sonrası açılmadı | systemd |<br>| Container çalışıyor ama API down | Cron health check |<br>| Disk doldu, container exit oldu | Cron health check |</p><p>Tek başına hiçbir katman tüm senaryoları çözmez. Beraber kullanıldığında ise Harbor neredeyse hiç manuel müdahale gerektirmeden ayakta kalır.</p><p>Test Etmek<br> — — — — —</p><p>Yapılandırmayı test etmek için:</p><p>1. Container restart testi:<br> docker kill harbor-core<br> # Birkaç saniye sonra container otomatik ayağa kalkmalı<br> docker ps | grep harbor-core</p><p>2. systemd testi:<br> systemctl stop harbor<br> systemctl start harbor<br> systemctl status harbor</p><p>3. Sunucu reboot testi (production’da dikkatli yap):<br> reboot<br> # Sunucu açıldıktan sonra<br> systemctl status harbor<br> curl <a href="https://harbor.example.com/api/v2.0/health">https://harbor.example.com/api/v2.0/health</a></p><p>4. Health check testi:<br> /usr/local/bin/harbor-healthcheck.sh<br> tail -f /var/log/harbor-healthcheck.log</p><p>Sonuç<br> — — -</p><p>Production ortamlarında Harbor gibi kritik servislerin otomatik olarak ayakta kalması, ekibin gece yarısı uyandırılmaması için şart. Tek bir mekanizmaya güvenmek yerine birden fazla katman kullanmak, edge case’leri yakalama şansını artırır.</p><p>Bu yaklaşım sadece Harbor için değil; GitLab, Nextcloud, Jenkins gibi Docker Compose ile çalışan diğer servisler için de aynı şekilde uygulanabilir. Sadece systemd servis adını, working directory’sini ve health check endpoint’ini ilgili servise göre uyarlamak yeterli.</p><p>Bir sonraki adım olarak, bu health check script’ini Prometheus exporter ile entegre edip Grafana üzerinden Harbor uptime’ını izlemeyi de değerlendirebilirsin. Ama o ayrı bir yazının konusu.</p><p>Etiketler: docker, harbor, devops, systemd, container-registry, linux, sysadmin</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c44e09446e32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Carbonio LetsEncript ssl deploy on ubuntu 24.4]]></title>
            <link>https://medium.com/@dururustem68/carbonio-letsencript-ssl-deploy-on-ubuntu-24-4-9c99b0e52f6d?source=rss-acd15b56347e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c99b0e52f6d</guid>
            <category><![CDATA[zextra]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[carbonio]]></category>
            <category><![CDATA[zimbra]]></category>
            <dc:creator><![CDATA[Dururustem]]></dc:creator>
            <pubDate>Tue, 14 Apr 2026 13:43:28 GMT</pubDate>
            <atom:updated>2026-05-04T14:08:09.271Z</atom:updated>
            <content:encoded><![CDATA[<p>mkdir -p /etc/letsencrypt/cloudflare<br>vi /etc/letsencrypt/cloudflare/credentials.ini</p><p>dns_cloudflare_api_token = YOUR_CLOUDFLARE_API_TOKEN</p><p>chmod 600 /etc/letsencrypt/cloudflare/credentials.ini</p><p>apt install certbot</p><p>apt install python3-certbot-dns-cloudflare -y</p><blockquote>certbot certonly \<br> — dns-cloudflare \<br> — dns-cloudflare-credentials /etc/letsencrypt/cloudflare/credentials.ini \<br> — dns-cloudflare-propagation-seconds 30 \<br> -d “example.com” \<br> -d “*.example.com” \<br> — email system@example.com \<br> — agree-tos \<br> — non-interactive</blockquote><pre>#!/usr/bin/env bash<br>#<br># carbonio-deploy-if-cert-changed.sh   (Ubuntu 24.04 / yeni Carbonio)<br># -----------------------------------------------------------------------------<br># 1) Live sertifikanin kalan suresine bakar; &lt;= RENEW_THRESHOLD_DAYS ise<br>#    zextras kullanicisi ile `certbot renew` calistirir.<br># 2) Live ile deploy edilmis sertifikayi fingerprint uzerinden karsilastirir.<br># 3) Farkliysa Carbonio&#39;ya deploy eder.<br># 4) systemd target&#39;lari ile tum bilesenleri yeniden baslatir<br>#    (komple sunucu reboot etmeden).<br># 5) Her servis icin port uzerinden SHA-256 fingerprint dogrulamasi yapar;<br>#    eslesmeyen olursa hedefli restart dener; hala olmuyorsa hata kodu ile cikar.<br>#<br># Onerilen cron: 10 3 * * * /opt/scripts/carbonio-deploy-if-cert-changed.sh \<br>#                              &gt;&gt; /var/log/carbonio-cert-deploy.log 2&gt;&amp;1<br># -----------------------------------------------------------------------------<br><br>set -euo pipefail<br><br># ---- AYARLAR ----------------------------------------------------------------<br>DOMAIN=&quot;mail.example.com&quot;<br>LIVE_DIR=&quot;/opt/zextras/common/certbot/etc/letsencrypt/live/${DOMAIN}&quot;<br>LIVE_CERT=&quot;${LIVE_DIR}/cert.pem&quot;<br><br># zmcertmgr deploycrt&#39;in fiilen yazdigi dosyalardan birini referans al.<br>DEPLOYED_PEM=&quot;/opt/zextras/conf/nginx.crt&quot;<br><br>COMM_KEY_DST=&quot;/opt/zextras/ssl/carbonio/commercial/commercial.key&quot;<br>TMP_DIR=&quot;/tmp&quot;<br><br># Certbot<br>CERTBOT_BIN=&quot;/opt/zextras/common/bin/certbot&quot;<br>RENEW_THRESHOLD_DAYS=5<br><br>ISRG_URL=&quot;https://letsencrypt.org/certs/isrgrootx1.pem.txt&quot;<br>LOCK_FILE=&quot;/var/lock/carbonio-deploy-if-cert-changed.lock&quot;<br><br># Carbonio systemd target&#39;lari (Ubuntu 24.04)<br>UMBRELLA_TARGET=&quot;carbonio.target&quot;<br>LDAP_TARGET=&quot;carbonio-directory-server.target&quot;<br>MTA_TARGET=&quot;carbonio-mta.target&quot;<br>PROXY_TARGET=&quot;carbonio-proxy.target&quot;<br>APPSERVER_TARGET=&quot;carbonio-appserver.target&quot;<br><br># Dogrulanacak (port|label|openssl-extra) listesi<br>declare -a VERIFY_TARGETS=(<br>  &quot;443|HTTPS-proxy|&quot;<br>  &quot;993|IMAPS|&quot;<br>  &quot;995|POP3S|&quot;<br>  &quot;465|SMTPS|&quot;<br>  &quot;25|SMTP-STARTTLS|-starttls smtp&quot;<br>  &quot;587|Submission-STARTTLS|-starttls smtp&quot;<br>  &quot;389|LDAP-STARTTLS|-starttls ldap&quot;<br>)<br><br># Restart sonrasi dogrulamadan once beklenecek sure (saniye)<br>SETTLE_SECONDS=30<br># -----------------------------------------------------------------------------<br><br>log() { echo &quot;[$(date -u &#39;+%Y-%m-%d %H:%M:%S UTC&#39;)] $*&quot;; }<br><br># ---- Lock + on kontroller --------------------------------------------------<br>exec 9&gt;&quot;$LOCK_FILE&quot;<br>flock -n 9 || { log &quot;Baska bir kopya calisiyor, cikiliyor.&quot;; exit 0; }<br><br>if [[ $EUID -ne 0 ]]; then<br>  log &quot;HATA: Bu script root olarak calismali.&quot;<br>  exit 1<br>fi<br><br>[[ -f &quot;$LIVE_CERT&quot;    ]] || { log &quot;HATA: Live cert yok: $LIVE_CERT&quot;; exit 1; }<br>[[ -f &quot;$DEPLOYED_PEM&quot; ]] || { log &quot;HATA: Deployed cert yok: $DEPLOYED_PEM&quot;; exit 1; }<br>[[ -x &quot;$CERTBOT_BIN&quot;  ]] || { log &quot;HATA: certbot bulunamadi: $CERTBOT_BIN&quot;; exit 1; }<br><br># ---- Yardimci fonksiyonlar -------------------------------------------------<br>fp_of_file() {<br>  openssl x509 -in &quot;$1&quot; -noout -fingerprint -sha256 2&gt;/dev/null \<br>    | awk -F= &#39;{print $2}&#39; | tr -d &#39;:&#39;<br>}<br><br>fp_of_port() {<br>  local port=&quot;$1&quot; extra=&quot;$2&quot;<br>  echo | timeout 8 openssl s_client ${extra} -connect &quot;127.0.0.1:${port}&quot; \<br>    -servername &quot;$DOMAIN&quot; 2&gt;/dev/null \<br>    | openssl x509 -noout -fingerprint -sha256 2&gt;/dev/null \<br>    | awk -F= &#39;{print $2}&#39; | tr -d &#39;:&#39;<br>}<br><br>dates_of_port() {<br>  local port=&quot;$1&quot; extra=&quot;$2&quot;<br>  echo | timeout 8 openssl s_client ${extra} -connect &quot;127.0.0.1:${port}&quot; \<br>    -servername &quot;$DOMAIN&quot; 2&gt;/dev/null \<br>    | openssl x509 -noout -dates -subject 2&gt;/dev/null<br>}<br><br>restart_target() {<br>  local tgt=&quot;$1&quot;<br>  if systemctl list-unit-files &quot;$tgt&quot; --quiet 2&gt;/dev/null | grep -q &quot;$tgt&quot;; then<br>    log &quot;  systemctl restart $tgt&quot;<br>    systemctl restart &quot;$tgt&quot; || { log &quot;  HATA: $tgt restart edilemedi&quot;; return 1; }<br>  else<br>    log &quot;  $tgt bulunamadi, atlaniyor&quot;<br>  fi<br>  return 0<br>}<br><br># ---- 1) Sure kontrolu + gerekirse certbot renew ----------------------------<br>NOT_AFTER_EPOCH=$(date -d &quot;$(openssl x509 -in &quot;$LIVE_CERT&quot; -noout -enddate | cut -d= -f2)&quot; +%s)<br>NOW_EPOCH=$(date -u +%s)<br>DAYS_LEFT=$(( (NOT_AFTER_EPOCH - NOW_EPOCH) / 86400 ))<br><br>log &quot;Live cert son gecerlilik: $(date -d &quot;@${NOT_AFTER_EPOCH}&quot; -u &#39;+%Y-%m-%d %H:%M:%S UTC&#39;)  (${DAYS_LEFT} gun kaldi)&quot;<br><br>if (( DAYS_LEFT &lt;= RENEW_THRESHOLD_DAYS )); then<br>  log &quot;Esik (${RENEW_THRESHOLD_DAYS} gun) altinda. zextras ile certbot renew calistiriliyor...&quot;<br>  if su - zextras -c &quot;${CERTBOT_BIN} renew --non-interactive&quot;; then<br>    log &quot;certbot renew tamamlandi.&quot;<br>  else<br>    log &quot;UYARI: certbot renew basarisiz. Yine de deploy karsilastirmasina devam ediliyor.&quot;<br>  fi<br>else<br>  log &quot;Sure yeterli (${DAYS_LEFT} &gt; ${RENEW_THRESHOLD_DAYS}). certbot renew atlandi.&quot;<br>fi<br><br># ---- 2) Fingerprint karsilastirmasi ----------------------------------------<br>LIVE_FP=$(fp_of_file &quot;$LIVE_CERT&quot;)<br>DEPLOYED_FP=$(fp_of_file &quot;$DEPLOYED_PEM&quot;)<br><br>[[ -n &quot;${LIVE_FP:-}&quot;     ]] || { log &quot;HATA: Live fingerprint okunamadi&quot;;     exit 1; }<br>[[ -n &quot;${DEPLOYED_FP:-}&quot; ]] || { log &quot;HATA: Deployed fingerprint okunamadi&quot;; exit 1; }<br><br>log &quot;LIVE     FP: $LIVE_FP&quot;<br>log &quot;DEPLOYED FP: $DEPLOYED_FP&quot;<br><br>if [[ &quot;$LIVE_FP&quot; == &quot;$DEPLOYED_FP&quot; ]]; then<br>  log &quot;Sertifika ayni, deploy gerekmez. Cikiliyor.&quot;<br>  exit 0<br>fi<br><br>log &quot;Sertifika farkli! Deploy islemi basliyor...&quot;<br><br># ---- 3) Dosya hazirligi ----------------------------------------------------<br>for f in &quot;$LIVE_DIR/privkey.pem&quot; &quot;$LIVE_DIR/cert.pem&quot; &quot;$LIVE_DIR/fullchain.pem&quot;; do<br>  [[ -f &quot;$f&quot; ]] || { log &quot;HATA: Kaynak dosya yok: $f&quot;; exit 1; }<br>done<br><br>cp -fL &quot;$LIVE_DIR/privkey.pem&quot;   &quot;$COMM_KEY_DST&quot;<br>chown zextras:zextras            &quot;$COMM_KEY_DST&quot;<br>chmod 600                        &quot;$COMM_KEY_DST&quot;<br><br>cp -fL &quot;$LIVE_DIR/cert.pem&quot;      &quot;$TMP_DIR/commercial.pem&quot;<br>chown zextras:zextras            &quot;$TMP_DIR/commercial.pem&quot;<br><br>cp -fL &quot;$LIVE_DIR/fullchain.pem&quot; &quot;$TMP_DIR/fullchain.pem&quot;<br>chown zextras:zextras            &quot;$TMP_DIR/fullchain.pem&quot;<br><br>wget --no-check-certificate -q -O &quot;$TMP_DIR/ISRG-X1.pem&quot; &quot;$ISRG_URL&quot; \<br>  || { log &quot;HATA: ISRG Root indirilemedi&quot;; exit 1; }<br><br>cat &quot;$TMP_DIR/fullchain.pem&quot; &quot;$TMP_DIR/ISRG-X1.pem&quot; &gt; &quot;$TMP_DIR/zextras_ca.pem&quot;<br>chown zextras:zextras &quot;$TMP_DIR/zextras_ca.pem&quot;<br><br># ---- 4) Deploy -------------------------------------------------------------<br>su - zextras -c &quot;cd /tmp &amp;&amp; /opt/zextras/bin/zmcertmgr verifycrt comm \<br>  /opt/zextras/ssl/carbonio/commercial/commercial.key \<br>  /tmp/commercial.pem \<br>  /tmp/zextras_ca.pem&quot;<br><br>su - zextras -c &quot;cd /tmp &amp;&amp; /opt/zextras/bin/zmcertmgr deploycrt comm \<br>  /tmp/commercial.pem \<br>  /tmp/zextras_ca.pem&quot;<br><br># mailboxd.pem deploycrt tarafindan guncellenMEZ; tutarlilik icin elle senkronla<br>cp -fL &quot;$LIVE_DIR/fullchain.pem&quot; /opt/zextras/mailboxd/etc/mailboxd.pem<br>chown zextras:zextras            /opt/zextras/mailboxd/etc/mailboxd.pem<br>chmod 644                        /opt/zextras/mailboxd/etc/mailboxd.pem<br><br># ---- 5) TUM Carbonio bilesenlerini yeniden baslat --------------------------<br># Onerilen: umbrella target&#39;i restart et -- tum alt target&#39;lari (ldap, mta,<br># proxy, appserver) systemd dogru bagimlilik sirasinda yeniden baslatir.<br># Bu, sunucu reboot&#39;una en yakin temiz yontemdir.<br>log &quot;Tum Carbonio bilesenleri yeniden baslatiliyor (${UMBRELLA_TARGET})...&quot;<br><br>if systemctl list-unit-files &quot;$UMBRELLA_TARGET&quot; --quiet 2&gt;/dev/null | grep -q &quot;$UMBRELLA_TARGET&quot;; then<br>  if systemctl restart &quot;$UMBRELLA_TARGET&quot;; then<br>    log &quot;${UMBRELLA_TARGET} restart tamamlandi.&quot;<br>  else<br>    log &quot;UYARI: ${UMBRELLA_TARGET} restart hata verdi. Tek tek deniyorum...&quot;<br>    restart_target &quot;$LDAP_TARGET&quot;      || true<br>    restart_target &quot;$MTA_TARGET&quot;       || true<br>    restart_target &quot;$PROXY_TARGET&quot;     || true<br>    restart_target &quot;$APPSERVER_TARGET&quot; || true<br>  fi<br>else<br>  log &quot;${UMBRELLA_TARGET} bulunamadi. Alt target&#39;lar tek tek restart ediliyor...&quot;<br>  restart_target &quot;$LDAP_TARGET&quot;      || true<br>  restart_target &quot;$MTA_TARGET&quot;       || true<br>  restart_target &quot;$PROXY_TARGET&quot;     || true<br>  restart_target &quot;$APPSERVER_TARGET&quot; || true<br>fi<br><br># ---- 6) Settle bekle -------------------------------------------------------<br>log &quot;Servislerin oturmasi icin ${SETTLE_SECONDS} sn bekleniyor...&quot;<br>sleep &quot;$SETTLE_SECONDS&quot;<br><br># ---- 7) Port bazinda fingerprint dogrulamasi -------------------------------<br>log &quot;Port bazinda fingerprint dogrulamasi:&quot;<br><br>ALL_OK=1<br>declare -a FAILED_PORTS=()<br><br>for entry in &quot;${VERIFY_TARGETS[@]}&quot;; do<br>  IFS=&#39;|&#39; read -r port label extra &lt;&lt;&lt; &quot;$entry&quot;<br>  port_fp=$(fp_of_port &quot;$port&quot; &quot;$extra&quot; || true)<br>  if [[ -z &quot;$port_fp&quot; ]]; then<br>    log &quot;  [$label :$port] BAGLANTI YOK / cert okunamadi (servis kapali olabilir, atlaniyor)&quot;<br>    continue<br>  fi<br>  if [[ &quot;$port_fp&quot; == &quot;$LIVE_FP&quot; ]]; then<br>    log &quot;  [$label :$port] OK&quot;<br>  else<br>    log &quot;  [$label :$port] HATALI: port=$port_fp&quot;<br>    log &quot;    $(dates_of_port &quot;$port&quot; &quot;$extra&quot;)&quot;<br>    FAILED_PORTS+=(&quot;$entry&quot;)<br>    ALL_OK=0<br>  fi<br>done<br><br># ---- 8) Eslesmeyenler icin ikinci tur hedefli restart ----------------------<br>if (( ALL_OK == 0 )); then<br>  log &quot;Eslesmeyen portlar var. Hedefli ikinci tur restart deneniyor...&quot;<br><br>  # Eslesmeyen portlara gore hangi target&#39;lari restart edecegimizi belirle<br>  declare -A NEED_RESTART=()<br>  for entry in &quot;${FAILED_PORTS[@]}&quot;; do<br>    IFS=&#39;|&#39; read -r port _ _ &lt;&lt;&lt; &quot;$entry&quot;<br>    case &quot;$port&quot; in<br>      25|465|587)  NEED_RESTART[&quot;$MTA_TARGET&quot;]=1 ;;<br>      443)         NEED_RESTART[&quot;$PROXY_TARGET&quot;]=1 ;;<br>      993|995)     NEED_RESTART[&quot;$APPSERVER_TARGET&quot;]=1 ;;<br>      389)         NEED_RESTART[&quot;$LDAP_TARGET&quot;]=1 ;;<br>    esac<br>  done<br><br>  for tgt in &quot;${!NEED_RESTART[@]}&quot;; do<br>    log &quot;  -&gt; $tgt&quot;<br>    restart_target &quot;$tgt&quot; || true<br>  done<br><br>  log &quot;Ikinci settle bekleyisi: ${SETTLE_SECONDS} sn...&quot;<br>  sleep &quot;$SETTLE_SECONDS&quot;<br><br>  log &quot;Yeniden dogrulama:&quot;<br>  ALL_OK=1<br>  for entry in &quot;${FAILED_PORTS[@]}&quot;; do<br>    IFS=&#39;|&#39; read -r port label extra &lt;&lt;&lt; &quot;$entry&quot;<br>    port_fp=$(fp_of_port &quot;$port&quot; &quot;$extra&quot; || true)<br>    if [[ &quot;$port_fp&quot; == &quot;$LIVE_FP&quot; ]]; then<br>      log &quot;  [$label :$port] OK&quot;<br>    else<br>      log &quot;  [$label :$port] HALA HATALI&quot;<br>      ALL_OK=0<br>    fi<br>  done<br>fi<br><br># ---- 9) Sonuc --------------------------------------------------------------<br>NEW_DEPLOYED_FP=$(fp_of_file &quot;$DEPLOYED_PEM&quot;)<br>log &quot;Yeni DEPLOYED FP: $NEW_DEPLOYED_FP&quot;<br><br>if (( ALL_OK == 1 )); then<br>  log &quot;BASARILI: Tum servisler yeni sertifikayi serve ediyor.&quot;<br>  exit 0<br>else<br>  log &quot;KRITIK: Bazi servisler hala eski sertifikayi serve ediyor!&quot;<br>  log &quot;        Onerilen: &#39;systemctl stop ${UMBRELLA_TARGET} &amp;&amp; systemctl start ${UMBRELLA_TARGET}&#39;&quot;<br>  log &quot;        veya son care olarak sunucu reboot.&quot;<br>  # Opsiyonel uyari kanali (mail/webhook) buraya eklenebilir.<br>  # echo &quot;Carbonio cert deploy basarisiz: $DOMAIN&quot; | mail -s &quot;ALERT&quot; admin@example.com<br>  exit 2<br>fi<br></pre><p>chmod u+x /opt/scripts/carbonio-deploy-if-cert-changed.sh</p><p>crontab -e</p><pre>10 3 * * * /opt/scripts/carbonio-deploy-if-cert-changed.sh &gt;&gt; /var/log/carbonio-cert-deploy.log 2&gt;&amp;1<br><br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c99b0e52f6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>