HomeTom - CS

Wednesday, June 17, 2026

Daemonsize a service

To daemonize a Linux process means to run a program continuously in the background so that it detaches from your terminal and stays alive after you log out. [1, 2]

The industry-standard approach is to let systemd handle the service lifecycle. However, you can also do this directly via the command line or within your application code.

Method 1: Using systemd (Recommended)
This is the standard and most reliable method for modern Linux systems. [1, 2, 3]
  1. Create a service configuration file:
    Open a new terminal and create a systemd configuration file:
    bash
    sudo nano /etc/systemd/system/my_python_daemon.service
    

  2. Add the service definition:
    Paste the configuration template below. Replace the absolute paths, user, and script names with your project parameters:
    ini
    [Unit]
    Description=My Python Daemon App
    After=network.target
    
    [Service]
    Type=simple
    User=your_linux_username
    WorkingDirectory=/home/your_linux_username/my_project
    ExecStart=/home/your_linux_username/my_project/venv/bin/python /home/your_linux_username/my_project/main.py
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    

  3. Reload and start your new daemon:
    Run these commands sequentially to register, initiate, and verify your background process:
    bash
    sudo systemctl daemon-reload
    sudo systemctl enable my_python_daemon.service
    sudo systemctl start my_python_daemon.service
    sudo systemctl status my_python_daemon.service
    

Method 2: Using Supervisor (Alternative Process Manager)
If you do not have root (sudo) privileges to systemd, or prefer a dedicated application-level manager, use Supervisor. [1]
  1. Add a program configuration:
    Create a configuration file within the Supervisor configuration directory:
    bash
    sudo nano /etc/supervisor/conf.d/my_python_daemon.conf
    

  2. Add the tracking parameters:
    Provide the exact path to your venv binary inside the command argument:
    ini
    [program:my_python_daemon]
    command=/home/your_linux_username/my_project/venv/bin/python /home/your_linux_username/my_project/main.py
    directory=/home/your_linux_username/my_project
    autostart=true
    autorestart=true
    user=your_linux_username
    stderr_logfile=/var/log/my_python_daemon.err.log
    stdout_logfile=/var/log/my_python_daemon.out.log
    

  3. Update Supervisor:
    Tell Supervisor to look for new configurations and start the daemon:
    bash
    sudo supervisorctl reread
    sudo supervisorctl update
    

Crucial Best Practices
  • Avoid Relative Paths: Inside your daemonized Python scripts, avoid using relative file lookups like open("config.json"). Daemons often run relative to the root directory / or system folders unless explicitly specified by WorkingDirectory. [1]
  • Reading Logs: Since the script runs invisibly in the background, you can inspect your print statements or unhandled tracebacks via the system journal:
    bash
    journalctl -u my_python_daemon.service -n 50 -f
    

 

Tuesday, June 16, 2026

Train text to image model, to generate images of certain styles

To train a text-to-image model to generate consistent visual styles, you cannot use the OpenAI API. OpenAI's DALL-E 3 does not support fine-tuning, LoRA training, or style customization through their developer platform. While OpenAI allows vision fine-tuning for GPT-4o, that is strictly for image understanding (like analyzing medical scans or OCR), not image generation. [1, 2, 3, 4, 5]
To train a model on a specific artistic style (e.g., watercolor, corporate vector illustrations, 90s anime), you must use open-weights diffusion models like FLUX.1 or Stable Diffusion XL (SDXL). The standard industry method is training a LoRA (Low-Rank Adaptation). [1, 2, 3, 4, 5]

1. Gather and Prepare Your Dataset
A LoRA learns style by looking at images and reading descriptive text captions. [1, 2, 3, 4]
  • Images: Gather 20 to 50 high-quality images that perfectly capture the target style. Ensure the images feature diverse subjects (e.g., buildings, people, animals) so the model learns the style rather than a single repeating object. [1, 2, 3, 4, 5]
  • Captions: Create a text file (.txt) with the exact same name for every image file (e.g., img_01.jpg and img_01.txt). [1, 2, 3]
  • Trigger Word: Choose a unique keyword that doesn't exist in standard language (e.g., 3dglitchstyle or retrolineart). Place this word at the beginning of every single caption file. [1, 2]
Caption Example (img_01.txt):
"In the style of retrolineart, a sleek sports car driving through a neon-lit futuristic city grid, sharp clean lines, minimalist color palette."

2. Choose Your Training Method
Because training takes massive GPU power, most developers utilize one of these accessible platforms to run the training scripts: [1]
Option A: No-Code Platforms (Easiest)
If you do not want to write code, you can use specialized cloud-based platforms designed for AI training: [1]
  • Replicate: Upload a .zip file of your images/captions, select ostris/flux-dev-lora-trainer, and click train. It costs roughly $1 to $2 per training run.
  • Fal.ai: Offers a highly optimized FLUX LoRA training pipeline. You simply drag and drop your dataset into their web interface. [1, 2, 3, 4, 5]
Option B: Open-Source Code (Advanced)
If you own a powerful desktop GPU (with 16GB+ VRAM) or use Google Colab, you can train a LoRA for free using specialized github repositories:
  • Kohya_ss: The most widely used graphical interface for training Stable Diffusion and FLUX models locally.
  • Ai-toolkit by Ostris: The go-to command-line training environment optimized explicitly for FLUX models. [1, 2]

3. Deploy and Generate Images [1]
Once training completes (usually taking 20 to 45 minutes on cloud GPUs), you will receive a small file called your_style.safetensors (typically 20MB to 100MB). [1, 2]
You can load this file into any popular UI like Automatic1111, ComfyUI, or cloud APIs to start generating images. To activate your style, you simply invoke your unique trigger word in your text prompt: [1, 2]
Prompt: "A majestic owl sitting on a tree branch, retrolineart style."

If you want to map out your training workflow, let me know:
  • Do you want to use FLUX.1 (hyper-realistic/modern) or Stable Diffusion XL (fast/lightweight)?
  • Do you prefer a no-code web dashboard or running Python/Colab code?
  • What specific style are you trying to train (e.g., architectural sketch, oil painting, logo style)?

Blog Archive

Followers