No packages found.
Minecraft server hosting
Honest Minecraft server hosting
Nothing special found.
Gamocosm makes it easy to run cloud Minecraft servers.
Digital Ocean is used as the backend/hosting service, due to cost, reliability, and accessibility.
Gamocosm works well for friends who play together, but not 24/7.
Running a server 14 hours a week (2 hours every day) may cost 40 cents a month, instead of $5.
This README is directed towards developers; if you are a user looking for more information, please check out the wiki or drop by Gitter chat.
The Minecraft Server Wrapper (for lack of a better name) is a light python webserver.
It provides an HTTP API for starting and stopping Minecraft servers, downloading the world, etc.
Please check it out and help improve it too!
The gamocosm-minecraft-flavours repository includes the setup scripts used to install different flavours of Minecraft on a new server.
Read this wiki page for adding support for new flavours, or manually installing something yourself.
Pull requests are welcome!
You should have a Unix/Linux system.
The following instructions were made for Fedora 36 Server, but the steps should be similar on other distributions.
As of 2022 August 28, deployment and CI have been changed to use containers.
For development, containers are more convenient for the PostgreSQL and Redis processes,
but it is still recommended to run the development Rails and Sidekiq server "locally".
(sudo) dnf install openssl-devel perl zlib-devel
.git clone https://github.com/rbenv/rbenv.git ~/.rbenv
.$HOME/.rbenv/bin
to your $PATH
, usually done in ~/.bashrc
.
On recent versions of Fedora, ~/.bashrc
sources any files in the directory ~/.bashrc.d
(if it exists), so you don't have to edit .bashrc
directly.
(To create the directory, run mkdir ~/.bashrc.d
.)
For example, run echo 'PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc.d/rbenv
(you can replace ~/.bashrc.d/rbenv
with ~/.bashrc
to modify .bashrc
directly).eval "$(rbenv init - bash)"
to your shell: echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc.d/rbenv
(again, you may choose to modify .bashrc
directly).mkdir ~/.rbenv/plugins
.git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
.rbenv install --list
.rbenv install
inside this project root directory (it reads .ruby-version
).ruby -v
inside this project gives you version 3.1.2.(sudo) dnf install libpq-devel
.bundle install
.id_gamocosm
private key and an id_gamocosm.pub
public key in the project root. Gamocosm uses this to connect to and set up the servers it creates. Gamocosm officially only supports ed25519
keys; somewhere down the stack, rsa
keys are not supported (ed25519
keys are considered more secure):
ssh-keygen -t ed25519
. The default path saves to ~/.ssh/id_ed25519
. If you leave it here, SSH will automatically try this key when SSHing (e.g. if you need to debug a Digital Ocean droplet created by your Gamocosm). Careful not to overwrite if you already have an existing ~/.ssh/id_ed25519
key!~/.ssh/id_ed25519
, run ln -s ~/.ssh/id_ed25519 id_gamocosm
, and similarly for the corresponding public key (with .pub
extension).
podman
/docker
cannot copy symlinks; use cp
to copy the files instead.id_gamocosm
and id_gamocosm.pub
are ignored in Gamocosm's .gitignore
so you don't have to worry about accidentally committing them.cp template.env gamocosm.env
.chown 600 gamocosm.env
gamocosm.env
. See below for documentation.
DATABASE_HOST
and SIDEKIQ_REDIS_HOST
both to localhost
.source load_env.sh
. You will also need to do this in every new shell you run ruby/rails in.podman
(or docker
): (sudo) dnf install podman
.podman create --name gamocosm-database --env "POSTGRES_USER=$DATABASE_USER" --env "POSTGRES_PASSWORD=$DATABASE_PASSWORD" --publish 127.0.0.1:5432:5432 docker.io/postgres:14.5
.podman create --name gamocosm-sidekiq-redis --publish 127.0.0.1:6379:6379 docker.io/redis:7.0.4
.podman start gamocosm-database gamocosm-sidekiq-redis
.bundle exec rails db:setup
.bundle exec rails s
.bundle exec sidekiq
.bundle exec rails c
.DATABASE_HOST
: May be a directory (for a Unix domain socket), or an IP/hostname (for a TCP connection). See below for more information.DATABASE_PORT
: Required even for Unix domain sockets. The default should work on Fedora provided you didn't change the postgresql settings.DATABASE_USER
: Hmmmm.DATABASE_PASSWORD
: Hmmmm.DIGITAL_OCEAN_API_KEY
: Your Digital Ocean API token.DIGITAL_OCEAN_SSH_PRIVATE_KEY_PASSPHRASE
: You should have generated or linked an id_gamocosm
SSH key in the project root, with an (optional) passphrase.SIDEKIQ_REDIS_HOST
: You can leave this as the default.SIDEKIQ_REDIS_PORT
: You can leave this as the default.SIDEKIQ_ADMIN_USERNAME
: HTTP basic auth for Sidekiq web interface.SIDEKIQ_ADMIN_PASSWORD
: See previous.CLOUDFLARE_API_TOKEN
: Hmmm.CLOUDFLARE_EMAIL
: Hmmm.CLOUDFLARE_ZONE
: Shown on the bottom right of CloudFlare's control panel for the domain.DEVISE_SECRET_KEY
: Only test, production.MAIL_SERVER_*
: See action mailer configuration in the Rails guide.CACHE_REDIS_HOST
: Caching for production. Is disabled/not used in development and test environments (see config/environments/development.rb
and config/environments/test.rb
).CACHE_REDIS_PORT
: See previous.SECRET_KEY_BASE
: Only production.DEVELOPER_EMAILS
: Comma separated list of emails to send exceptions to.BADNESS_SECRET
: Secret to protect /badness
endpoint.Database configuration is greatly simplified if you use a container image as described above.
However, the following information remains for reference, if you want to run PostgreSQL directly on your system.
Locate your postgres data directory.
On Fedora this is /var/lib/pgsql/data/
.
Locate postgresql.conf
in your postgres data directory.
The convention is that commented out settings represent the default values.
For a Unix domain socket connection, DATABASE_HOST
should be one of the values of unix_socket_directories
.
In general, the default is /tmp
.
On Fedora, the default includes both /tmp
and /var/run/postgresql
.
For a TCP connection, DATABASE_HOST
should be one of the values of listen_addresses
(default localhost
).
The value localhost
should work if you're running postgresql locally.
Your DATABASE_PORT
should be the value of port
in this file (default 5432
).
You can read more about connecting to postgresql at postgresql's docs.
Locate pg_hba.conf
in your postgres data directory.
This file tells postgresql how to authenticate users. Read about it on the PostgreSQL docs.
The Rails config config/database.yml
reads from the environment variables which you should have set in and loaded from gamocosm.env
via source load_env.sh
.
The postgres user you use must be a postgres superuser, as rails needs to enable the uuid extension.
To create a postgres user "gamocosm":
postgres
user: (sudo) su --login postgres
.createuser --createdb --pwprompt --superuser gamocosm
(createuser --help
for more info).Depending on what method you want to use, in pg_hba.conf
add the following under the line that looks like # TYPE DATABASE USER ADDRESS METHOD
.
local
(Unix domain socket) or host
(TCP connection)postgres
database (to create new databases?)postgres,gamocosm_development,gamocosm_test,gamocosm_production
gamocosm
local
type127.0.0.1/32
in ipv4 and ::1/128
in ipv6. My system used ipv6 (postgres did not match the entry when I entered localhost ipv4)config/database.yml
specifies the database user to be "gamocosm", using this method is more troublesome, at least in development, because you have to either change that to your OS username and create a postgresql user with your username, or create a new OS account called "gamocosm" and a postgresql user "gamocosm"peer
but for network connectionsExample: local postgres,gamocosm_development,gamocosm_test,gamocosm_production gamocosm md5
.
You will have to restart postgresql ((sudo) systemctl restart postgresql
) for the changes to take effect.
app
: main source codebin
: rails stuff, don't touchconfig
: rails app configurationdb
: rails app database stuff (schema, migrations, seeds)lib
: rails stuff, don't touchlog
: 'nuff saidpublic
: static filessysadmin
: stuff for the Gamocosm server (you can run your own server! This is a true open source project)test-docker
: use docker container to test most of app/workers/setup_server_worker.rb
(more below)test
: pooteeweetvendor
: rails stuff, don't touchHmmmm.
String#error!
to mark a return value is an error
nil
)'API response code not 200'.error!(res)
String#error!
returns an Error
object; Error#to_s
is overridden so the error message can be shown to the user, or the error data (Error#data
) can be further inspected for handling.error?
to check if a return value is an error. Error#error?
is overriden to return true
config/initializers/monkey_patches.rb
server.remote.exists?
: !server.remote_id.nil?
server.remote.error?
: whether there was an error or not retrieving info about a droplet from Digital Ocean
!server.remote.exists?
server.remote
actions (e.g. server.remote.create
)server.running?
: server.remote.exists? && !server.remote.error? && server.remote.status == 'active'
user.digital_ocean.nil?
: Digital Ocean API token missingminecraft.node.error?
: error communicating with Minecraft wrapper on serverminecraft.running?
: server.running? && !node.error? && node.pid > 0
(notice symmetry with server.running?
)ActiveRecord::Base.connection_pool.with_connection do |conn|
if threads (e.g. timeout) access the databaseserver.reset_state
and return
db/seed.rb
): email "[email protected]", password "1234test", has the Digital Ocean api token from env.sh
/sidekiq
/newrelic
bundle exec rails c
bundle exec rake db:reset
Sidekiq::Queue.new.each { |job| job.delete }
in the rails consoleSidekiq::Stats.new.reset
in the rails consolesysadmin/
directoryrake db
commands: Stack Overflowbundle exec rails test
or ./tests.sh
RAILS_ENV=test bundle exec rails <s|c>
to run the server or console (respectively) in test modeWithout a server to connect to, Gamocosm can't try SetupServerWorker or AutoshutdownMinecraftWorker.
"test-docker/" contains a Dockerfile for building a basic Fedora container with an SSH server (simulating a bare Digital Ocean server).
If you set $TEST_DOCKER
to "true", the tests will assume there is a running Docker Gamocosm container to connect to.
tests.sh
will build the image, start the container, and delete the container for you if you specify to use Docker.
Otherwise, it will run the tests normally (equivalent to bundle exec rails test
).
You should have non-root access to Docker.
You could also manage Docker yourself; you can look at the tests.sh
file for reference.
Example: TEST_DOCKER=true ./tests.sh