autosleep

command module
v0.0.0-...-433e874 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 13 Imported by: 0

README

Autosleep inactive Docker Containers

I have many projects running on my linode slice, unfortunately they are not as popular as I hoped for! May be upto 10 users per day. They keep running consuming RAM and other resources with no work to do.

Couple of weeks back Docker got me interested, I wanted to get the free tier Heroku feature, sleeping off the inactive apps and activate them whenever someone accesses them. The result is autosleep!

How does that work?

Autosleep creates a reverse proxy in front of nginx. It has all the bells and whistles to check if a Docker container is running or not, pass on the requests if it's running otherwise start it and then pass on the request. It stops the containers if they are inactive for about 30 mins.

Installation

go get github.com/girishso/autosleep

(cd to github.com/girishso/autosleep)

godep go build autosleep.go

sudo ./autosleep

Usage

Start containers with a VIRTUAL_HOST env variable (similar to docker-gen):

docker run -e VIRTUAL_HOST=foo.local.info -t ...

Autosleep also works with the stopped containers as well, but they must be created with VIRTUAL_HOST env. In case multiple containers with the same VIRTUAL_HOST exist, autosleep uses the most recently run container.

Make sure config exists for foo.local.info in nginx.conf. Note nginx listens on port 8080.

upstream foo.local.info {
    server 127.0.0.1:3000;
}

server {
	listen 8080;
    gzip_types text/plain text/css application/json application/x-javascript
               text/xml application/xml application/xml+rss text/javascript;

    server_name foo.local.info;

    location / {
        proxy_pass http://foo.local.info;
        include /etc/nginx/proxy_params;
    }
}

Start autosleep

sudo ./autosleep

Have fun!

TODO

  • Create docker image
  • Update instructions for using with docker-gen
  • Demonize the process
  • Upload binaries

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Godeps
_workspace/src/github.com/fsouza/go-dockerclient
Package docker provides a client for the Docker remote API.
Package docker provides a client for the Docker remote API.
_workspace/src/github.com/fsouza/go-dockerclient/external/github.com/docker/docker/pkg/parsers
Package parsers provides helper functions to parse and validate different type of string.
Package parsers provides helper functions to parse and validate different type of string.
_workspace/src/github.com/fsouza/go-dockerclient/external/github.com/docker/docker/pkg/pools
Package pools provides a collection of pools which provide various data types with buffers.
Package pools provides a collection of pools which provide various data types with buffers.
_workspace/src/github.com/fsouza/go-dockerclient/external/github.com/docker/docker/pkg/ulimit
Package ulimit provides structure and helper function to parse and represent resource limits (Rlimit and Ulimit, its human friendly version).
Package ulimit provides structure and helper function to parse and represent resource limits (Rlimit and Ulimit, its human friendly version).
_workspace/src/github.com/fsouza/go-dockerclient/external/github.com/docker/docker/pkg/units
Package units provides helper function to parse and print size and time units in human-readable format.
Package units provides helper function to parse and print size and time units in human-readable format.
_workspace/src/github.com/fsouza/go-dockerclient/external/github.com/gorilla/context
Package context stores values shared during a request lifetime.
Package context stores values shared during a request lifetime.
_workspace/src/github.com/fsouza/go-dockerclient/external/github.com/gorilla/mux
Package gorilla/mux implements a request router and dispatcher.
Package gorilla/mux implements a request router and dispatcher.
_workspace/src/github.com/fsouza/go-dockerclient/testing
Package testing provides a fake implementation of the Docker API, useful for testing purpose.
Package testing provides a fake implementation of the Docker API, useful for testing purpose.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL