GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — focus-bot/SERVICE_SETUP.md at master · namick/focus-bot

Expand file tree

/

SERVICE_SETUP.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
244 lines (175 loc) · 5.06 KB
/

SERVICE_SETUP.md

Copy path

File metadata and controls

244 lines (175 loc) · 5.06 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Running Focus Bot as a Service

This guide covers running Focus Bot as a persistent background service on Linux (systemd) and macOS (launchd).

Prerequisites

  • Bun installed and working (bun --version)
  • Bot runs successfully in the foreground (bun run start)
  • .env file configured in the project root

Find your Bun path (you'll need it below):

which bun

Linux (systemd user service)

1. Create the service file

mkdir -p ~/.config/systemd/user

Create ~/.config/systemd/user/focus-bot.service with this content:

[Unit]
Description=Focus Bot - Telegram to Obsidian note capture
After=network.target

[Service]
Type=simple
WorkingDirectory=/home/YOUR_USER/code/focus-bot
ExecStart=/home/YOUR_USER/.bun/bin/bun run start
Restart=always
RestartSec=5
EnvironmentFile=/home/YOUR_USER/code/focus-bot/.env

[Install]
WantedBy=default.target

Replace /home/YOUR_USER with your actual home directory path throughout.

2. Enable lingering

This keeps your user services running after you log out:

loginctl enable-linger $USER

3. Start the service

systemctl --user daemon-reload
systemctl --user enable focus-bot.service
systemctl --user start focus-bot.service

4. Verify

systemctl --user status focus-bot

Common commands

# Start / stop / restart
systemctl --user start focus-bot
systemctl --user stop focus-bot
systemctl --user restart focus-bot

# View status
systemctl --user status focus-bot

# Follow logs live
journalctl --user -u focus-bot -f

# Recent logs
journalctl --user -u focus-bot -n 50

# Enable / disable auto-start
systemctl --user enable focus-bot
systemctl --user disable focus-bot

Updating after code changes

systemctl --user restart focus-bot

If you edited the service file itself:

systemctl --user daemon-reload
systemctl --user restart focus-bot

macOS (launchd)

1. Create the plist file

Create ~/Library/LaunchAgents/com.focus-bot.plist with this content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.focus-bot</string>

    <key>WorkingDirectory</key>
    <string>/Users/YOUR_USER/code/focus-bot</string>

    <key>ProgramArguments</key>
    <array>
        <string>/Users/YOUR_USER/.bun/bin/bun</string>
        <string>run</string>
        <string>start</string>
    </array>

    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/Users/YOUR_USER/.bun/bin:/usr/local/bin:/usr/bin:/bin</string>
    </dict>

    <key>RunAtLoad</key>
    <true/>

    <key>KeepAlive</key>
    <true/>

    <key>StandardOutPath</key>
    <string>/Users/YOUR_USER/Library/Logs/focus-bot.log</string>

    <key>StandardErrorPath</key>
    <string>/Users/YOUR_USER/Library/Logs/focus-bot.error.log</string>
</dict>
</plist>

Replace /Users/YOUR_USER with your actual home directory path throughout.

Note: launchd doesn't support EnvironmentFile. You have two options for environment variables:

Option A — Add each variable to the plist's EnvironmentVariables dict:

<key>EnvironmentVariables</key>
<dict>
    <key>PATH</key>
    <string>/Users/YOUR_USER/.bun/bin:/usr/local/bin:/usr/bin:/bin</string>
    <key>TELEGRAM_BOT_TOKEN</key>
    <string>your-token-here</string>
    <key>ALLOWED_USER_IDS</key>
    <string>123456</string>
    <!-- ... other vars ... -->
</dict>

Option B (recommended) — Use a wrapper script that sources .env:

Create run.sh in the project root:

#!/bin/bash
set -a
source "$(dirname "$0")/.env"
set +a
exec bun run start
chmod +x run.sh

Then change the plist's ProgramArguments to:

<key>ProgramArguments</key>
<array>
    <string>/Users/YOUR_USER/code/focus-bot/run.sh</string>
</array>

2. Load and start the service

launchctl load ~/Library/LaunchAgents/com.focus-bot.plist

3. Verify

launchctl list | grep focus-bot

A 0 in the status column means it's running. A non-zero number means it exited with an error.

Common commands

# Start / stop
launchctl load ~/Library/LaunchAgents/com.focus-bot.plist
launchctl unload ~/Library/LaunchAgents/com.focus-bot.plist

# Check status
launchctl list | grep focus-bot

# View logs
tail -f ~/Library/Logs/focus-bot.log
tail -f ~/Library/Logs/focus-bot.error.log

Updating after code changes

launchctl unload ~/Library/LaunchAgents/com.focus-bot.plist
launchctl load ~/Library/LaunchAgents/com.focus-bot.plist

Troubleshooting

Service won't start — Test the bot manually first:

bun run start

If that works but the service doesn't, check that all paths in the service/plist file are absolute and correct.

Linux: service stops after logout — Make sure lingering is enabled:

loginctl enable-linger $USER

macOS: "Operation not permitted" — You may need to grant Full Disk Access to the terminal or bun in System Settings > Privacy & Security.

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.