---
type: "Source File"
title: "!/usr/bin/env python3"
description: "#!/usr/bin/env python3 \"\"\"Deploy copecheck-layoffs to VPS\"\"\" import subprocess, os APP_DIR = \"/home/ben/infra/copecheck-layoffs\" SERVICE = \"copecheck-layoffs\" PORT = 5021 # 1. Create venv and install deps print(\"[1/4]."
resource: "https://layoffs.copecheck.com"
tags: ["copecheck", "layoffs", "source-file", "py"]
timestamp: "2026-05-07T22:42:50Z"
site: "layoffs"
source_path: "copecheck-layoffs/deploy.py"
---

# !/usr/bin/env python3

Source path: `copecheck-layoffs/deploy.py`  
Index snapshot generated: `2026-11-24T13:27:52Z`  
File modified: `2026-05-07T22:42:50Z`

```py
#!/usr/bin/env python3
"""Deploy copecheck-layoffs to VPS"""
import subprocess, os

APP_DIR = "/home/ben/infra/copecheck-layoffs"
SERVICE = "copecheck-layoffs"
PORT = 5021

# 1. Create venv and install deps
print("[1/4] Setting up venv...")
subprocess.run(["python3", "-m", "venv", f"{APP_DIR}/venv"], check=True)
subprocess.run([f"{APP_DIR}/venv/bin/pip", "install", "-r", f"{APP_DIR}/requirements.txt", "-q"], check=True)

# 2. Create systemd service
print("[2/4] Creating systemd service...")
service_content = f"""[Unit]
Description=CopeCheck Layoffs (layoffs.copecheck.com)
After=network.target

[Service]
Type=simple
User=ben
WorkingDirectory={APP_DIR}
ExecStart={APP_DIR}/venv/bin/gunicorn -c gunicorn_config.py app:app
Restart=always
RestartSec=10
Environment=PYTHONUNBUFFERED=1

[Install]
WantedBy=multi-user.target
"""
with open(f"/etc/systemd/system/{SERVICE}.service", "w") as f:
    f.write(service_content)

# 3. Add to cloudflared config
print("[3/4] Adding to tunnel config...")
config_path = "/etc/cloudflared/config.yml"
with open(config_path) as f:
    config = f.read()

ingress_line = f"  - hostname: layoffs.copecheck.com\n    service: http://localhost:{PORT}\n"
if "layoffs.copecheck.com" not in config:
    # Insert before catch-all
    config = config.replace("  - service: http_status:404", f"{ingress_line}  - service: http_status:404")
    with open(config_path, "w") as f:
        f.write(config)
    print("  Added ingress rule")
else:
    print("  Ingress rule already exists")

# 4. Reload and start
print("[4/4] Starting services...")
subprocess.run(["systemctl", "daemon-reload"], check=True)
subprocess.run(["systemctl", "enable", "--now", SERVICE], check=True)
subprocess.run(["systemctl", "restart", "cloudflared"], check=True)

print(f"\nDone! {SERVICE} running on port {PORT}")
print("URL: https://layoffs.copecheck.com/")
```
