<?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 Samax Patel on Medium]]></title>
        <description><![CDATA[Stories by Samax Patel on Medium]]></description>
        <link>https://medium.com/@patelsamax?source=rss-bf60a1c2a26a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FHYf3Lf-S2yxkry8LmRxlg.png</url>
            <title>Stories by Samax Patel on Medium</title>
            <link>https://medium.com/@patelsamax?source=rss-bf60a1c2a26a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 11:49:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@patelsamax/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[Kong + Konga Gateway Installation with Docker]]></title>
            <link>https://medium.com/@patelsamax/kong-konga-gateway-installation-with-docker-93c4e5558e04?source=rss-bf60a1c2a26a------2</link>
            <guid isPermaLink="false">https://medium.com/p/93c4e5558e04</guid>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[kong]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kong-api-gateway]]></category>
            <category><![CDATA[konga]]></category>
            <dc:creator><![CDATA[Samax Patel]]></dc:creator>
            <pubDate>Tue, 08 Apr 2025 05:14:50 GMT</pubDate>
            <atom:updated>2025-04-08T05:14:50.764Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3FrdRGXDt3a3P_-lroXPQ.jpeg" /></figure><p>In this guide, we will walk through the installation of the Kong API Gateway along with the Konga UI using Docker.</p><h3>What is Kong?</h3><p>Kong is an open-source, scalable API Gateway. It allows clients to access services through a single endpoint. Instead of calling services directly, clients interact with the Kong endpoint, which routes requests to the correct service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/0*PryKFn5epR4_Vr4M.png" /></figure><h3>Installation with Docker</h3><h4>Docker Compose File Analysis</h4><p>We use Docker Compose to set up the following services:</p><p>1. <strong>kong-database</strong></p><ul><li>Image: postgres:9.6</li><li>Stores all database information.</li></ul><p>2. <strong>kong-migrations</strong></p><ul><li>Image: kong:latest</li><li>Performs database migrations.</li><li>Uses the command kong migrations bootstrap to initialize the database.</li><li>For Kong versions below 0.15, use kong migrations up instead.</li></ul><p>3. <strong>kong</strong></p><ul><li>Image: kong:latest</li><li>Main Kong service.</li><li>Configured with environment variables for PostgreSQL.</li><li>Exposed ports: 8000, 8001, 8443, and 8444.</li></ul><p>4. <strong>konga-prepare</strong></p><ul><li>Image: pantsel/konga</li><li>Prepares the Konga database.</li></ul><p>5. <strong>konga</strong></p><ul><li>Image: pantsel/konga</li><li>Konga UI for managing Kong.</li><li>Uses TOKEN_SECRET for signing JWT tokens.</li></ul><p><strong><em>Note: Konga is not officially affiliated with Kong.</em></strong></p><h3>Full docker-compose.yml File</h3><pre>version: &quot;3&quot;<br><br>networks:<br> kong-net:<br>  driver: bridge<br><br>services:<br>  #######################################<br>  # Postgres: The database used by Kong<br>  #######################################<br>  kong-database:<br>    image: postgres:11.6<br>    restart: always<br>    networks:<br>      - kong-net<br>    environment:<br>      POSTGRES_PASSWORD: kong<br>      POSTGRES_USER: kong<br>      POSTGRES_DB: kong<br>    ports:<br>      - &quot;5432:5432&quot;<br>    healthcheck:<br>      test: [&quot;CMD&quot;, &quot;pg_isready&quot;, &quot;-U&quot;, &quot;kong&quot;]<br>      interval: 5s<br>      timeout: 5s<br>      retries: 5<br><br>  #######################################<br>  # Kong database migration<br>  #######################################<br>  kong-migration:<br>    image: kong:2.8<br>    command: &quot;kong migrations bootstrap&quot;<br>    networks:<br>      - kong-net<br>    restart: on-failure<br>    environment:<br>      KONG_PG_HOST: kong-database<br>      KONG_DATABASE: postgres<br>      KONG_PG_PASSWORD: kong<br>    links:<br>      - kong-database<br>    depends_on:<br>      - kong-database<br><br>  #######################################<br>  # Kong: The API Gateway<br>  #######################################<br>  kong:<br>    image: kong:2.8<br>    restart: always<br>    networks:<br>      - kong-net<br>    environment:<br>      KONG_DATABASE: postgres<br>      KONG_PG_HOST: kong-database<br>      KONG_PG_USER: kong<br>      KONG_PG_PASSWORD: kong<br>      KONG_PROXY_LISTEN: 0.0.0.0:8000<br>      KONG_PROXY_LISTEN_SSL: 0.0.0.0:8443<br>      KONG_ADMIN_LISTEN: 0.0.0.0:8001<br>      KONG_PROXY_ACCESS_LOG: /dev/stdout<br>      KONG_ADMIN_ACCESS_LOG: /dev/stdout<br>      KONG_PROXY_ERROR_LOG: /dev/stderr<br>      KONG_ADMIN_ERROR_LOG: /dev/stderr<br>    depends_on:<br>      - kong-migration<br>      - kong-database<br>    healthcheck:<br>      test: [&quot;CMD&quot;, &quot;curl&quot;, &quot;-f&quot;, &quot;http://kong:8001&quot;]<br>      interval: 5s<br>      timeout: 2s<br>      retries: 15<br>    ports:<br>      - &quot;8001:8001&quot;<br>      - &quot;8000:8000&quot;<br><br>  #######################################<br>  # Konga database prepare<br>  #######################################<br>  konga-prepare:<br>    image: pantsel/konga:latest<br>    command: &quot;-c prepare -a postgres -u postgresql://kong:kong@kong-database:5432/konga_db&quot;<br>    environment:<br>      DB_ADAPTER: postgres<br>      DB_HOST: kong-database<br>      DB_USER: kong<br>      DB_PASSWORD: kong<br>    networks:<br>      - kong-net<br>    restart: on-failure<br>    links:<br>      - kong-database<br>    depends_on:<br>      - kong-database<br><br>  #######################################<br>  # Konga: Kong GUI<br>  #######################################<br>  konga:<br>    image: pantsel/konga:latest<br>    restart: always<br>    networks:<br>        - kong-net<br>    environment:<br>      DB_ADAPTER: postgres<br>      DB_HOST: kong-database<br>      DB_USER: kong<br>      DB_PASSWORD: kong<br>      TOKEN_SECRET: 4b5ffb1b86049479d7bc875bcaf0a9b4fcfd1b16<br>      DB_DATABASE: konga_db<br>      NODE_ENV: production<br>    depends_on:<br>      - kong-database<br>    ports:<br>      - &quot;1337:1337&quot;<br><br></pre><h3>Starting Services</h3><p>Use the command below to start the services:</p><pre>docker-compose up -d</pre><p>Check the running services with:</p><pre>docker-compose ps</pre><p>Note: kong-migrations and konga-prepare containers will exit after initializing the database.</p><h3>Verifying the Setup</h3><p>Check the database setup:</p><pre>docker-compose exec kong-database bash<br>psql -U kong<br>\l - list databases<br>\dt+ - list tables<br>\c database_name - switch to kong database<br>\dt - list tables in kong database</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JQd94T93Sz5i60yA" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oefZ0mkX_sr-ts1q" /></figure><h3>Accessing the Kong Admin API and Konga UI</h3><ul><li>Kong Admin API: <a href="http://192.168.1.249:8001/">http://192.168.1.249:8001</a></li><li>Konga UI: <a href="http://192.168.1.249:1337/">http://192.168.1.249:1337</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JMjcUvrQApKJa91Q" /></figure><p>After accessing the Konga UI:</p><ul><li>Register with a username and password.</li><li>Create a new connection:</li><li>Name: admin</li><li>Kong Admin URL: <a href="http://kong:8001/">http://kong:8001/</a> or <a href="http://kong:8001/">http://</a><a href="http://192.168.1.249:8001/">192.168.1.249</a><a href="http://kong:8001/">:8001/</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*11q8zoJ73OTG0yoS" /></figure><p>This completes the setup.</p><h3>Conclusion</h3><p>This guide demonstrated the installation of Kong and Konga using Docker. Further content will explore practical use cases and industry applications.</p><h3>References</h3><ul><li>Kong — Official Image | Docker Hub</li><li>Docker Hub</li><li>Postgres — Official Image | Docker Hub</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93c4e5558e04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up YOURLS on Ubuntu VM with Docker, MariaDB, and Apache2]]></title>
            <link>https://medium.com/@patelsamax/setting-up-yourls-on-ubuntu-vm-with-docker-mariadb-and-apache2-eec2f5f23dbd?source=rss-bf60a1c2a26a------2</link>
            <guid isPermaLink="false">https://medium.com/p/eec2f5f23dbd</guid>
            <category><![CDATA[apache2-configuration]]></category>
            <category><![CDATA[ubuntu-docker-guide]]></category>
            <category><![CDATA[yourls-docker-setup]]></category>
            <category><![CDATA[self-hosted-yourls]]></category>
            <dc:creator><![CDATA[Samax Patel]]></dc:creator>
            <pubDate>Fri, 07 Mar 2025 06:59:54 GMT</pubDate>
            <atom:updated>2025-03-07T07:04:11.463Z</atom:updated>
            <content:encoded><![CDATA[<p>In this guide, you’ll learn how to set up <strong>YOURLS (Your Own URL Shortener)</strong> on an <strong>Ubuntu virtual machine</strong> using <strong>Docker</strong>, <strong>MariaDB</strong>, and <strong>Apache2</strong>. We will expose:</p><ul><li><strong>YOURLS</strong> on 192.168.1.151:9090</li><li><strong>MariaDB</strong> on 192.168.1.151:4040</li></ul><p>We will also build a custom Docker image that includes Apache2 without using SSL.</p><h3>Prerequisites</h3><p>Ensure your Ubuntu VM is updated and Docker + Docker Compose are installed.</p><h3>✅Step 1: Update and Install Dependencies</h3><pre># Update and upgrade Ubuntu packages<br>sudo apt update &amp;&amp; sudo apt upgrade -y<br><br># Install Docker and Docker Compose<br>sudo apt install docker.io docker-compose -y<br><br># Enable Docker service<br>sudo systemctl enable docker<br>sudo systemctl start docker<br><br># Verify installation<br>docker --version<br>docker-compose --version</pre><h3>📦 Step 2: Project Structure</h3><p>Create a dedicated directory for your YOURLS Docker setup.</p><pre>mkdir -p ~/yourls-docker<br>cd ~/yourls-docker<br><br># Create Dockerfile, Docker Compose, and Apache configuration<br>touch Dockerfile docker-compose.yml yourls_apache.conf</pre><p>This structure helps keep your configuration organized:</p><pre>~/yourls-docker/<br>├── Dockerfile<br>├── docker-compose.yml<br>└── yourls_apache.conf</pre><h3>🐳 Step 3: Dockerfile</h3><p>The Dockerfile will extend the official <strong>YOURLS</strong> image and install <strong>Apache2</strong>.</p><p>Create and edit the Dockerfile:</p><pre># Use the official YOURLS image as the base<br>FROM yourls:latest<br><br># Install necessary packages (Apache2) without SSL<br>RUN apt-get update &amp;&amp; \<br>    apt-get install -y apache2 &amp;&amp; \<br>    a2enmod rewrite &amp;&amp; \<br>    apt-get clean<br><br># Copy YOURLS Apache configuration<br>COPY yourls_apache.conf /etc/apache2/sites-available/yourls_apache.conf<br><br># Create symlink to enable site<br>RUN ln -s /etc/apache2/sites-available/yourls_apache.conf /etc/apache2/sites-enabled/yourls_apache.conf<br><br># Set permissions for YOURLS directory<br>RUN chown -R www-data:www-data /var/www/html<br><br># Start Apache in the foreground<br>CMD [&quot;apache2ctl&quot;, &quot;-D&quot;, &quot;FOREGROUND&quot;]</pre><h3>📜 Step 4: Apache Configuration</h3><p>Configure Apache to serve YOURLS traffic without SSL.</p><p>Create and edit the yourls_apache.conf:</p><pre>&lt;VirtualHost *:80&gt;<br>    ServerAdmin admin@yourls.local<br>    DocumentRoot /var/www/html<br>    ServerName 192.168.1.151<br><br>    &lt;Directory /var/www/html&gt;<br>        Options FollowSymLinks<br>        AllowOverride All<br>        Require all granted<br>    &lt;/Directory&gt;<br><br>    ErrorLog ${APACHE_LOG_DIR}/yourls_error.log<br>    CustomLog ${APACHE_LOG_DIR}/yourls_access.log combined<br>&lt;/VirtualHost&gt;</pre><h3>📊 Step 5: Docker Compose Configuration</h3><p>Create and edit the docker-compose.yml file to define both <strong>YOURLS</strong> and <strong>MariaDB</strong> services.</p><pre>version: &#39;3.8&#39;<br><br>services:<br>  yourls:<br>    build: .<br>    container_name: yourls<br>    ports:<br>      - &quot;9090:80&quot;<br>    environment:<br>      YOURLS_DB_USER: yourls_user<br>      YOURLS_DB_PASS: yourls_password<br>      YOURLS_DB_NAME: yourls_db<br>      YOURLS_DB_HOST: mariadb<br>      YOURLS_SITE: http://192.168.1.151:9090<br>      YOURLS_USER: admin<br>      YOURLS_PASS: admin123<br>    depends_on:<br>      - mariadb<br>    restart: always<br><br>  mariadb:<br>    image: mariadb:latest<br>    container_name: mariadb<br>    ports:<br>      - &quot;4040:3306&quot;<br>    environment:<br>      MYSQL_ROOT_PASSWORD: root_password<br>      MYSQL_DATABASE: yourls_db<br>      MYSQL_USER: yourls_user<br>      MYSQL_PASSWORD: yourls_password<br>    volumes:<br>      - mariadb_data:/var/lib/mysql<br>    restart: always<br><br>volumes:<br>  mariadb_data:</pre><p>In this setup:</p><ul><li><strong>YOURLS</strong> is available on port 9090</li><li><strong>MariaDB</strong> is available on port 4040</li><li>Persistent data is stored in the mariadb_data volume</li></ul><h3>🚀 Step 6: Build and Start the Containers</h3><p><strong>1. Navigate to your project directory</strong>:</p><pre>cd ~/yourls-docker</pre><p><strong>2. Build the Docker image and start the services</strong>:</p><pre>docker-compose up -d --build</pre><p><strong>3. Check if containers are running</strong>:</p><pre>docker ps</pre><p>Expected output:</p><pre>CONTAINER ID   IMAGE           COMMAND                 PORTS                  NAMES<br>abc12345       yourls:latest   &quot;apache2ctl -D FOR...&quot;  0.0.0.0:9090-&gt;80/tcp   yourls<br>xyz67890       mariadb:latest  &quot;docker-entrypoint...&quot;  0.0.0.0:4040-&gt;3306/tcp mariadb</pre><h3>🌐 Step 7: Access the YOURLS Dashboard</h3><p>Open your browser and navigate to:</p><pre>http://192.168.1.151:9090/admin</pre><p>Use the credentials you defined in docker-compose.yml:</p><ul><li><strong>Username:</strong> admin</li><li><strong>Password:</strong> admin123</li></ul><h3>🛠️ Step 8: Managing Containers</h3><p>Here are some common Docker Compose commands:</p><h4>Stop the containers:</h4><pre>docker-compose down</pre><h4>Restart the containers:</h4><pre>docker-compose up -d</pre><h4>Check container logs (useful for debugging):</h4><pre>docker-compose logs -f</pre><h3>✅ Conclusion</h3><p>You have successfully deployed <strong>YOURLS</strong> on your Ubuntu VM using Docker, Apache2, and MariaDB. This guide provides a scalable and easily manageable YOURLS setup that you can expand as needed.</p><p>Let me know if you want to enhance the setup with SSL, advanced logging, or further optimizations!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eec2f5f23dbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Run Bitbucket Runner as a Windows Service Using WinSW Wrapper]]></title>
            <link>https://medium.com/@patelsamax/how-to-run-bitbucket-runner-as-a-windows-service-using-winsw-wrapper-55a62abf7a51?source=rss-bf60a1c2a26a------2</link>
            <guid isPermaLink="false">https://medium.com/p/55a62abf7a51</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[winsw-wrapper]]></category>
            <category><![CDATA[background-task]]></category>
            <category><![CDATA[windows-services]]></category>
            <category><![CDATA[bitbucket-runner]]></category>
            <dc:creator><![CDATA[Samax Patel]]></dc:creator>
            <pubDate>Wed, 22 Jan 2025 13:04:58 GMT</pubDate>
            <atom:updated>2025-01-27T12:16:39.426Z</atom:updated>
            <content:encoded><![CDATA[<p>Microsoft provides the Windows service functionality, enabling background tasks and long-running applications to operate continuously without user interaction. These services start automatically during system boot and run in the background, eliminating the need for user input.</p><p>While Bitbucket runners are not currently packaged to run as a Windows service, a feature request (BCLOUD-21928) has been submitted to add this capability. In the meantime, third-party tools like the <strong>WinSW wrapper</strong> can be used to configure the runner’s launch script as a Windows service. This approach ensures that the runner continues to function even if the user logs off.</p><p>Below is a step-by-step guide to setting up Bitbucket runners as a Windows service using the <strong>WinSW.exe </strong>wrapper:</p><h3>Step 1: Download and Prepare the WinSW Wrapper</h3><ol><li>Download the WinSW wrapper from the official repository and place it in the Bitbucket runner folder.<br><a href="https://github.com/winsw/winsw/releases">Download WinSW Wrapper</a></li><li><strong>Rename</strong> the downloaded wrapper to runner.exe.</li></ol><ul><li>For example, save it to C:\Users\your_user_name\atlassian-bitbucket-pipelines-runners\runner.exe</li></ul><h3>Step 2: Create the Runner Configuration File</h3><ol><li><strong>Create a new configuration file</strong> (runner.xml) and place it in the runner folder. The content of the runner.xml file should be as follows for repository-based runners:</li></ol><pre>&lt;service&gt;  <br>      &lt;id&gt;BitbucketRunnerWrapper&lt;/id&gt;  <br>      &lt;name&gt;Bitbucket Runner Wrapper (powered by WinSW)&lt;/name&gt;  <br>      &lt;description&gt;Wrapper for JAVA based Bitbucket Runner&lt;/description&gt;  <br>      &lt;executable&gt;java&lt;/executable&gt;  <br>      &lt;arguments&gt;-jar -Dbitbucket.pipelines.runner.account.uuid={xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx} -Dbitbucket.pipelines.runner.repository.uuid={xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx} -Dbitbucket.pipelines.runner.uuid={xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx} -Dbitbucket.pipelines.runner.environment=PRODUCTION -Dbitbucket.pipelines.runner.oauth.client.id=xxxxxxxxxxxxxx -Dbitbucket.pipelines.runner.oauth.client.secret=xxxxxxxxxxxxxxx -Dbitbucket.pipelines.runner.directory.working=..\temp -Dbitbucket.pipelines.runner.runtime=windows-powershell -Dbitbucket.pipelines.runner.scheduled.state.update.initial.delay.seconds=0 -Dbitbucket.pipelines.runner.scheduled.state.update.period.seconds=30 -Dbitbucket.pipelines.runner.cleanup.previous.folders=false -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 ./bin/runner.jar&lt;/arguments&gt;  <br>      &lt;log mode=&quot;roll&quot;&gt;&lt;/log&gt;  <br>      &lt;logpath&gt;%BASE%\logs&lt;/logpath&gt;  <br>      &lt;stopparentprocessfirst&gt;true&lt;/stopparentprocessfirst&gt;  <br>&lt;/service&gt;</pre><p><strong>Note:</strong></p><ol><li>Replace the placeholders (e.g., {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx}) with the actual values for your Bitbucket repository or workspace.</li><li>For workspace-based runners, you only need the following arguments:</li></ol><ul><li>bitbucket.pipelines.runner.account.uuid</li><li>Dbitbucket.pipelines.runner.uuid</li><li>Dbitbucket.pipelines.runner.oauth.client.id</li><li>Dbitbucket.pipelines.runner.oauth.client.secret</li></ul><h3>Step 3: Verify Folder Structure</h3><p>Ensure your runner folder structure looks like the following:</p><pre>C:\Users\your_user_name\atlassian_runners<br>├── bin<br>├── logs<br>├── target<br>├── README.md<br>├── runner.exe<br>└── runner.xml</pre><h3>Step 4: Install the Runner as a Windows Service</h3><ol><li>Open the Command Prompt (run as Administrator).</li><li>Navigate to the folder containing the runner.exe and runner.xml files.</li><li>Run the following command to install the runner as a Windows service:</li></ol><pre>.\runner.exe install runner.xml</pre><h3>Step 5: Start the Service</h3><ol><li>Open the <strong>Windows Services</strong> application.</li><li>Locate the service named <strong>BitbucketRunnerWrapper</strong>.</li><li>Start the service by right-clicking and selecting <strong>Start</strong>.</li></ol><h3>Additional Information</h3><ul><li>The <strong>WinSW wrapper</strong> is a third-party tool. Be sure to refer to the <a href="https://github.com/winsw/winsw">WinSW tool page</a> for tool maintenance, support, warranty, and licensing details.</li><li>This solution ensures that the Bitbucket runner will continue running in the background even after logging off from the system.</li></ul><h3>Note</h3><h4>During Error :-</h4><pre>We couldn&#39;t clone the repository. Try rerunning the pipeline</pre><ul><li>This solution ensures that for Bitbucket pipeline error run this with powsershell admin</li></ul><pre>Set-ExecutionPolicy RemoteSigned -Scope LocalMachine</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55a62abf7a51" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Fix the GPG Agent Stopping Unexpectedly by Setting Up a Windows Service to Keep It Running.]]></title>
            <link>https://medium.com/@patelsamax/how-to-fix-the-gpg-agent-stopping-unexpectedly-by-setting-up-a-windows-service-to-keep-it-running-6a03a4850b1d?source=rss-bf60a1c2a26a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a03a4850b1d</guid>
            <category><![CDATA[gpg-agent]]></category>
            <category><![CDATA[monitoring-system]]></category>
            <category><![CDATA[windows-services]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[python-scripting]]></category>
            <dc:creator><![CDATA[Samax Patel]]></dc:creator>
            <pubDate>Wed, 22 Jan 2025 06:02:44 GMT</pubDate>
            <atom:updated>2025-02-03T05:15:54.192Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, we’ll walk through the process of creating a Windows service that monitors the status of the GPG agent (gpg-agent.exe) and automatically restarts it if it stops. This approach ensures that your GPG agent remains active without manual intervention.</p><h4>Prerequisites</h4><p>Before we begin, make sure you have the following:</p><ul><li>Python installed on your Windows system.</li><li>The pywin32 package, which enables Python to interact with Windows services.</li></ul><p>To install pywin32, run:</p><pre>pip install pywin32<br>pip install psutil</pre><p>Now, let’s write a Python script gpg_agent_service.py that will create a Windows service to monitor the GPG agent. Below is the full script.</p><pre>import win32service<br>import win32serviceutil<br>import win32event<br>import subprocess<br>import time<br>import os<br>import psutil<br>import logging<br><br># Setup logging<br>logging.basicConfig(filename=&quot;C:\\gpg_agent_service.log&quot;, level=logging.INFO,<br>                    format=&quot;%(asctime)s - %(levelname)s - %(message)s&quot;)<br><br><br>class GpgAgentService(win32serviceutil.ServiceFramework):<br>    _svc_name_ = &quot;GPGAgentMonitorService&quot;<br>    _svc_display_name_ = &quot;GPG Python Agent Monitor Service&quot;<br>    _svc_description_ = &quot;Monitors and restarts the GPG agent if it stops.&quot;<br><br>    def __init__(self, args):<br>        win32serviceutil.ServiceFramework.__init__(self, args)<br>        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)<br>        self.running = True<br><br>    def SvcStop(self):<br>        logging.info(&quot;Service stop requested.&quot;)<br>        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)<br>        self.running = False<br>        win32event.SetEvent(self.hWaitStop)<br><br>    def SvcDoRun(self):<br>        logging.info(&quot;Service started.&quot;)<br>        self.main()<br><br>    def is_gpg_agent_running(self):<br>        &quot;&quot;&quot;Check if the GPG agent process is running&quot;&quot;&quot;<br>        for proc in psutil.process_iter(attrs=[&#39;pid&#39;, &#39;name&#39;]):<br>            try:<br>                if &quot;gpg-agent.exe&quot; in proc.info[&#39;name&#39;].lower():<br>                    return True<br>            except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):<br>                continue<br>        return False<br><br>    def start_gpg_agent(self):<br>        &quot;&quot;&quot;Start the GPG agent if not running&quot;&quot;&quot;<br>        gpg_path = os.path.expandvars(r&quot;C:\Program Files (x86)\gnupg\bin\gpg-agent.exe&quot;)<br>        if os.path.exists(gpg_path):<br>            try:<br>                subprocess.Popen([gpg_path, &quot;--daemon&quot;], creationflags=subprocess.CREATE_NO_WINDOW)<br>                logging.info(&quot;Started GPG agent.&quot;)<br>            except Exception as e:<br>                logging.error(f&quot;Failed to start GPG agent: {e}&quot;)<br>        else:<br>            logging.error(f&quot;GPG agent not found at {gpg_path}&quot;)<br><br>    def main(self):<br>        &quot;&quot;&quot;Main service loop&quot;&quot;&quot;<br>        while self.running:<br>            if not self.is_gpg_agent_running():<br>                logging.warning(&quot;GPG agent is not running! Restarting...&quot;)<br>                self.start_gpg_agent()<br>            else:<br>                logging.info(&quot;GPG agent is running.&quot;)<br>            time.sleep(5)<br><br>if __name__ == &quot;__main__&quot;:<br>    import sys<br>    import servicemanager<br><br>    if len(sys.argv) == 1:<br>        servicemanager.Initialize()<br>        servicemanager.PrepareToHostSingle(GpgAgentService)<br>        servicemanager.StartServiceCtrlDispatcher()<br>    else:<br>        win32serviceutil.HandleCommandLine(GpgAgentService)Explanation:</pre><ul><li><strong>GpgAgentService</strong>: The class inherits from win32serviceutil.ServiceFramework to create a Windows service.</li><li><strong>SvcStop</strong>: Handles stopping the service.</li><li><strong>SvcDoRun</strong>: Runs the main function that monitors the GPG agent.</li><li><strong>is_gpg_agent_running</strong>: Checks if gpg-agent.exe is running by using the tasklist command.</li><li><strong>start_gpg_agent</strong>: Starts the GPG agent if it’s not running by invoking gpg-agent.exe.</li><li><strong>main</strong>: Loops every 5 seconds to check if the GPG agent is running, and if not, it starts the agent.</li></ul><h3>Step 2: Save the Script</h3><p>Save the script as gpg_agent_service.py on your system.</p><h3>Step 3: Install the Service</h3><p>Once the script is ready, you can install the service by running the following command in the command prompt:</p><pre>python gpg_agent_service.py install</pre><p>This command will install the service, allowing it to run automatically in the background.</p><h3>Step 4: Start the Service</h3><p>Now that the service is installed, start it with this command:</p><pre>python gpg_agent_service.py start</pre><p>The service will now monitor the GPG agent and restart it if it stops.</p><h3>Step 5: How It Works</h3><p>The script runs as a Windows service, and every 5 seconds it checks if gpg-agent.exe is running. If the agent is not found, the service will automatically start it using the default path: C:\Program Files (x86)\gnupg\bin\gpg-agent.exe.</p><h4>Custom Path:</h4><p>If you have a custom installation of GPG, you can adjust the gpg_path variable to the correct location of gpg-agent.exe.</p><h3>Step 6: Uninstalling the Service</h3><p>To remove the service from your system, run:</p><pre>python gpg_agent_service.py remove</pre><h3>Conclusion</h3><p>With this setup, your GPG agent will always be running. You no longer have to worry about manually restarting it if it crashes or stops. This ensures that your GPG keys are always available for use.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a03a4850b1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Migrate Your GPG Keys Between Machines to Resolve Commit Errors and Maintain Consistency in…]]></title>
            <link>https://medium.com/@patelsamax/how-to-migrate-your-gpg-keys-between-machines-to-resolve-commit-errors-and-maintain-consistency-in-5e507212bfb0?source=rss-bf60a1c2a26a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e507212bfb0</guid>
            <category><![CDATA[gpg]]></category>
            <category><![CDATA[gpg-error]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[gpg-key]]></category>
            <category><![CDATA[gpgpu]]></category>
            <dc:creator><![CDATA[Samax Patel]]></dc:creator>
            <pubDate>Fri, 03 Jan 2025 12:07:25 GMT</pubDate>
            <atom:updated>2025-01-03T12:07:25.544Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Migrate Your GPG Keys Between Machines to Resolve Commit Errors and Maintain Consistency in the Same Repository</h3><h3>Migrating GPG Keys to a New Machine</h3><p>GPG (GNU Privacy Guard) is an essential tool for encrypting files, signing Git commits, and securing communications. If you’re moving to a new machine, migrating your GPG keys is crucial to maintaining your workflows. This guide outlines two methods to migrate your GPG keys effectively: migrating all keys and configurations or migrating specific keys.</p><h3>Method 1: Migrate All Keys and Configurations</h3><p>This method is ideal if you’re setting up a new machine with no existing GPG keys or configurations.</p><p><strong>1-Locate the GPG directory:</strong> The GPG configuration files are usually located in the directory ~/.gnupg.</p><p><strong>2-Backup the directory:</strong> On your current machine, compress the ~/.gnupg folder:</p><pre>tar -czvf gpg-backup.tar.gz ~/.gnupg</pre><p><strong>3-Transfer the backup:</strong> Move the gpg-backup.tar.gz file to your new machine using a secure method (e.g., USB stick, SSH, or cloud storage).</p><p><strong>4-Restore the backup:</strong> On your new machine, extract the backup:</p><pre>tar -xzvf gpg-backup.tar.gz -C ~/</pre><p><strong>5-Set appropriate permissions:</strong> Ensure the .gnupg directory has the correct permissions to maintain security:</p><pre>chmod 700 ~/.gnupg</pre><p>This method transfers all your keys, configurations, and trust levels.</p><h3>Method 2: Migrate Specific Keys</h3><p>This method allows you to transfer only specific GPG keys if you want to avoid overwriting existing configurations on the new machine.</p><h4>Step 1: Identify the Key(s) to Migrate</h4><p>Run the following command on your current machine to list your secret keys:</p><pre>gpg --list-secret-keys --keyid-format LONG</pre><p>Example output:</p><pre>sec   rsa4096/ABCDEFG1234567890 2024-03-30 [SC]<br>      ABCDEFGHIJKLMNOPQRSTUVWXYZ<br>uid                 [ unknown] John Doe (KEY NAME) &lt;john.doe@example.com&gt;<br>ssb   rsa4096/1234ABCD5678EFGH 2024-03-30 [E]</pre><p>The key ID is the string after rsa4096/ (e.g., ABCDEFG1234567890).</p><h4>Step 2: Export the Public Key</h4><p>Export the public key to a file:</p><pre>gpg --export -a [KEY_ID] &gt; gpg-pub.asc</pre><h4>Step 3: Export the Secret Key</h4><p>Export the secret key, entering your passphrase if prompted:</p><pre>gpg --export-secret-keys -a [KEY_ID] &gt; gpg-sc.asc</pre><h4>Step 4: Transfer the Keys</h4><p>Move the gpg-pub.asc and gpg-sc.asc files to your new machine using a secure method (e.g., USB stick, encrypted email, or SCP).</p><h4>Step 5: Import the Keys on the New Machine</h4><p>On your new machine, import the keys:</p><p>1-Import the public key:</p><pre>gpg --import gpg-pub.asc</pre><p>2-Import the secret key:</p><pre>gpg --import gpg-sc.asc</pre><p>3-Verify the keys have been imported:</p><pre>gpg --list-secret-keys --keyid-format LONG<br><br><br><br></pre><p>4-Set the trust level of the key (optional but recommended):</p><pre>gpg --edit-key [KEY_ID] trust quit</pre><p>. Select level 5 for ultimate and yes</p><p>Follow the prompts to assign a trust level.</p><h3>Notes</h3><ul><li>Always ensure your GPG directory and exported key files are securely stored and transferred.</li><li>Use strong passwords for your secret keys to prevent unauthorized access.</li><li>After migration, test your setup by encrypting a file or signing a Git commit.</li></ul><p>By following these steps, you can seamlessly transition your GPG setup to your new machine without losing functionality or compromising security.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e507212bfb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>