Skip to content

About

A GitHub Actions workflow to prevent free-tier services on popular hosting platforms from spinning down or going to sleep.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Keep Services Alive

A GitHub Actions workflow to prevent free-tier services on popular hosting platforms from spinning down or going to sleep.

Problem

Many hosting providers offer free tiers that automatically scale down or spin down services after periods of inactivity to conserve resources:

  • Vercel: Serverless functions can cold start after inactivity
  • Render: Free web services spin down after 5 minutes of inactivity
  • Netlify: Serverless functions can cold start
  • Railway: Free tier spins down after 5 minutes
  • Fly.io: Free apps scale to zero after inactivity
  • Heroku: Free dynos sleep after 30 minutes of inactivity
  • Glitch: Projects can sleep after inactivity

This project sends periodic HTTP requests to your services to keep them awake.

Features

  • Multiple platform support: Built-in support for Vercel, Render, Netlify, Railway, Fly.io, Heroku, Glitch, GitHub Pages, and custom services
  • Configurable schedules: Set how often to ping your services
  • Flexible configuration: Custom endpoints, HTTP methods, headers, and delays
  • Detailed logging: Clear output showing which services responded successfully
  • Minimal dependencies: Only requires the requests library

Setup

1. Create a GitHub Repository

Create a new repository for this project or add it to an existing one.

2. Add the Workflow

The GitHub Actions workflow is already configured in .github/workflows/keep-alive.yml. It runs every 6 hours by default.

3. Configure Your Services

Create a JSON configuration with your services and add it as a GitHub secret:

  1. Go to your repository Settings > Secrets > Actions
  2. Click New repository secret
  3. Name it SERVICE_CONFIGS
  4. Paste your JSON configuration (see examples below)

4. You're Done!

The workflow will automatically run on the configured schedule and ping all your services.

Configuration Examples

Basic Configuration

{
  "services": [
    {
      "type": "vercel",
      "url": "https://your-app.vercel.app",
      "label": "My Vercel App"
    },
    {
      "type": "render",
      "url": "https://your-app.onrender.com",
      "label": "My Render Service"
    },
    {
      "type": "netlify",
      "url": "https://your-site.netlify.app",
      "label": "My Netlify Site"
    }
  ]
}

Advanced Configuration

{
  "services": [
    {
      "type": "vercel",
      "url": "https://api.vercel.app",
      "label": "Vercel API",
      "ping_path": "/api/health",
      "method": "GET",
      "delay_after": 2
    },
    {
      "type": "render",
      "url": "https://my-app.onrender.com",
      "label": "Main Render App",
      "ping_path": "/api/heartbeat",
      "method": "POST",
      "headers": {
        "Authorization": "Bearer your-token",
        "Content-Type": "application/json"
      },
      "data": {"action": "ping"}
    },
    {
      "type": "custom",
      "url": "https://any-service.com",
      "label": "Custom Service",
      "ping_path": "/api/keep-alive",
      "method": "HEAD",
      "headers": {
        "User-Agent": "KeepServicesAlive-Bot"
      }
    },
    {
      "type": "health-check",
      "health_check_url": "https://status.your-service.com/health",
      "label": "Health Check Endpoint"
    }
  ]
}

Configuration Options

Option Required Default Description
type Yes - Platform type: vercel, render, netlify, railway, flyio, heroku, glitch, github-pages, custom, health-check
url Yes - Base URL of your service
label No Auto-generated Friendly name for logging
ping_path No / Path to ping (relative to url)
method No GET HTTP method: GET, POST, HEAD
headers No Browser-like headers Custom HTTP headers
data No - Request body for POST requests
delay_after No 0 Seconds to wait after pinging this service
health_check_url No - Full URL for health check (alternative to url + ping_path)

Supported Platforms

Platform Spin-down Time Type Notes
Vercel ~10-15 min vercel Serverless functions
Render 5 min render Free web services
Netlify ~10-15 min netlify Serverless functions
Railway 5 min railway Free tier
Fly.io ~5-10 min flyio or fly.io Scales to zero
Heroku 30 min heroku Free dynos
Glitch Variable glitch Can sleep
GitHub Pages N/A github-pages For monitoring
Custom - custom Any HTTP endpoint
Health Check - health-check Specific health endpoints

Customizing the Schedule

To change how often the workflow runs, edit the cron schedule in .github/workflows/keep-alive.yml:

on:
  schedule:
    - cron: "0 */6 * * *"   # Every 6 hours

Cron syntax examples:

  • 0 * * * * - Every hour
  • 0 */2 * * * - Every 2 hours
  • 0 */30 * * * - Every 30 minutes
  • 0 0 * * * - Daily at midnight UTC

Note: GitHub Actions has schedule limits. Free repositories can run scheduled workflows at most once per hour.

Running Manually

You can trigger the workflow manually:

  1. Go to your repository's Actions tab
  2. Select the Keep Free Services Alive workflow
  3. Click Run workflow dropdown
  4. Click Run workflow button

Local Testing

You can test the script locally:

# Install dependencies
pip install requests

# Set environment variable with your config
export SERVICE_CONFIGS='{"services": [{"type": "custom", "url": "https://httpbin.org/get", "label": "Test Service"}]}'

# Run the script
python ping.py

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

License

MIT License

About

A GitHub Actions workflow to prevent free-tier services on popular hosting platforms from spinning down or going to sleep.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages