Skip to main content

Sleep/Wake Functionality

Overview

Targetly's sleep/wake system helps optimize VPS resources while maintaining deployment availability. This guide explains how it works and how to use it effectively.

How Auto-Idle Works

Targetly monitors deployment activity and automatically stops idle containers:

Activity Monitoring

Targetly tracks HTTP requests to each deployment

Idle Detection

If no requests are received for 15 minutes, the deployment is marked idle

Graceful Shutdown

Container is gracefully stopped to free resources

Status Update

Deployment status changes from "Running" to "Stopped"

info

The 15-minute timeout can be configured per deployment in future versions.

Why Auto-Idle?

Auto-idle shutdown provides several benefits:

  • Resource Optimization Multiple deployments can share limited VPS resources efficiently

  • Cost Savings Reduces compute costs by stopping unused containers

  • Stability Prevents resource exhaustion from zombie containers

  • On-Demand Deployments available when needed, idle when not

Manual Wake

Wake a sleeping deployment manually:

tly start abc123def456

The deployment will:

  1. Start the existing container (no rebuild)
  2. Become accessible at its original URL
  3. Resume exactly where it left off
warning

tly start does NOT redeploy your code. To update code, use tly deploy instead.

Wake vs. Redeploy

ActionCommandWhen to Use
Waketly start <id>Resume a stopped deployment without changes
Redeploytly deployDeploy new code or configuration changes

Checking Deployment Status

See which deployments are sleeping:

tly list

Output shows status for each deployment:

┌─────────────┬──────────┬─────────┬─────────────────────────────┐
│ ID │ Name │ Status │ URL │
├─────────────┼──────────┼─────────┼─────────────────────────────┤
│ abc123 │ weather │ Running │ https://abc123.prod.tly.io │
│ xyz789 │ search │ Stopped │ https://xyz789.prod.tly.io │
└─────────────┴──────────┴─────────┴─────────────────────────────┘

Best Practices

For Development

During development, you may want to keep deployments running:

# Deploy
tly deploy

# Keep pinging to prevent sleep (in another terminal)
watch -n 600 curl https://your-deployment.prod.targetly.io/health
tip

For active development, consider running locally with Docker instead of deploying repeatedly.

For Production

In production, embrace auto-idle:

  • ✅ Let infrequently-used tools sleep automatically
  • ✅ Wake on-demand when needed
  • ✅ Monitor with tly list to track usage patterns

Preventing Sleep (Future)

Future versions will support:

# Keep deployment always running
tly deploy --no-sleep

# Set custom idle timeout
tly deploy --idle-timeout 30m

Manual Stop

Stop a running deployment manually:

tly stop abc123def456

Use cases:

  • Free resources immediately
  • Disable a deployment temporarily
  • Perform maintenance

Sleep Workflow Example

Common workflow with sleep/wake:

# Morning: Deploy a tool
tly deploy
# Output: Deployment abc123 created at https://abc123.prod.targetly.io

# Use the tool throughout the day
# (automatically stays running while active)

# After 15 minutes of inactivity: Auto-sleeps
# tly list shows: Status = Stopped

# Later: Need to use it again
tly start abc123
# Wakes immediately, no redeploy needed

# Evening: Check status
tly list
# Shows which tools are active vs. sleeping

Monitoring

Track deployment activity:

# View recent activity in logs
tly logs abc123 --tail 50

# Check if deployment is sleeping
tly list | grep abc123

FAQs

Does sleep delete my deployment?

No. Sleep only stops the Docker container. All your code and configuration remain intact.

How long does wake take?

Typically 2-5 seconds. The container starts with its existing image, no rebuild needed.

Can I disable auto-sleep?

Currently, auto-sleep is enabled for all deployments. Future versions will support opting out.

What happens to in-progress requests when sleeping?

Requests in progress when the idle timer triggers will complete normally. Sleep occurs after timeout.

  • tly start Wake a sleeping deployment

  • tly stop Manually stop a deployment

  • tly list Check deployment status