aws_minecraft 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b2ac622c911990d68a2392c6e8f5ba779420a40
4
+ data.tar.gz: 5463cc914cb80dd64576b1984e7e49f2b2eac973
5
+ SHA512:
6
+ metadata.gz: e0e76fe8c5691fcb5dc8c541152b5f8acdc8111c1d64bf0d6c19dee444b981590438b875156b0dc650c421269983df4b9021fda9518355b32adf1fd5bbaeb027
7
+ data.tar.gz: a6016d147a7f053addf791ebb7304cc76fa784935b5de75a98b56314f263a5d7380d9b6e23f8fa00fc40911fcd3e33f891f05a8a73acb246dfc94457405e35b8
@@ -0,0 +1,7 @@
1
+ *.db
2
+ .tags*
3
+ pkg/
4
+ drop/*
5
+ .DS_Store
6
+ cfg/minecraft.key
7
+ coverage
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 2.3.1
3
+ env:
4
+ - AWS_REGION=eu-central-1
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec', require: 'spec'
4
+ gem 'thor'
5
+ gem 'aws-sdk', '~> 2'
6
+ gem 'rubocop'
7
+ gem 'rake'
8
+ gem 'sqlite3'
9
+ gem 'net-ssh'
10
+ gem 'net-scp'
11
+ gem 'fakefs', require: 'fakefs/safe'
@@ -0,0 +1,61 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ast (2.3.0)
5
+ aws-sdk (2.6.2)
6
+ aws-sdk-resources (= 2.6.2)
7
+ aws-sdk-core (2.6.2)
8
+ jmespath (~> 1.0)
9
+ aws-sdk-resources (2.6.2)
10
+ aws-sdk-core (= 2.6.2)
11
+ diff-lcs (1.2.5)
12
+ fakefs (0.9.1)
13
+ jmespath (1.3.1)
14
+ net-scp (1.2.1)
15
+ net-ssh (>= 2.6.5)
16
+ net-ssh (3.2.0)
17
+ parser (2.3.1.4)
18
+ ast (~> 2.2)
19
+ powerpack (0.1.1)
20
+ rainbow (2.1.0)
21
+ rake (11.2.2)
22
+ rspec (3.5.0)
23
+ rspec-core (~> 3.5.0)
24
+ rspec-expectations (~> 3.5.0)
25
+ rspec-mocks (~> 3.5.0)
26
+ rspec-core (3.5.3)
27
+ rspec-support (~> 3.5.0)
28
+ rspec-expectations (3.5.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.5.0)
31
+ rspec-mocks (3.5.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.5.0)
34
+ rspec-support (3.5.0)
35
+ rubocop (0.43.0)
36
+ parser (>= 2.3.1.1, < 3.0)
37
+ powerpack (~> 0.1)
38
+ rainbow (>= 1.99.1, < 3.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (~> 1.0, >= 1.0.1)
41
+ ruby-progressbar (1.8.1)
42
+ sqlite3 (1.3.11)
43
+ thor (0.19.1)
44
+ unicode-display_width (1.1.1)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ aws-sdk (~> 2)
51
+ fakefs
52
+ net-scp
53
+ net-ssh
54
+ rake
55
+ rspec
56
+ rubocop
57
+ sqlite3
58
+ thor
59
+
60
+ BUNDLED WITH
61
+ 1.13.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016-infinity Gergely Brautigam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,171 @@
1
+ Minecraft Server In The Cloud
2
+ =============================
3
+
4
+ This is a fully provisinable Minecraft server on a configurable EC2 instance under AWS. This Gem
5
+ provides the ability to manage both, an EC2 instance and a Minecraft server which is executed on
6
+ that EC2 instance.
7
+
8
+ # Reasons
9
+
10
+ I have a fully operational Minecraft server at home running on my laptop. My problem was, that
11
+ I don't have the infrastructure or the processing power, neither the networking capabilities to host
12
+ a server which can handle more than 2 people. All the other solutions out there, costed a lot of
13
+ money and investment.
14
+
15
+ All I needed was a good enough server for at least 5-6 hours / week. This is a rough estimate.
16
+ With this kind of usage, my cost, with an t2.large EC2 instance would be around ~3-5 USD / month!
17
+ This is a price none of the services currently providing could beat any time soon. A t2.large can
18
+ handle a fair amount of people without breaking a sweat. I can shut it down, and start it up again
19
+ at any given time. If I'm not using it for a week, it just sits there, and will not incur any costs.
20
+ This is again, something that no competitors would be able to match.
21
+
22
+ The only thing that competitors are matching is maybe ease of usage. And hence, the reason for this
23
+ Gem. This CLI ruby gem, will make it so that it's easy, and straightforward to manage an instance
24
+ from the command line and to manage a Minecraft server from the command line as well. And here is
25
+ how you do that.
26
+
27
+ # Setup
28
+
29
+ ## AWS
30
+
31
+ In order for this to work, you'll have to set up an AWS account, which you can do here:[AWS Account Creation](Create Account - Amazon Web Services).
32
+ Once that is done, you will need to save your api creds. After that, you'll need to set up the CLI
33
+ tool of AWS in order for your environment to be correctly configured for this Gem's CLI tool. To
34
+ do that, run through this document: [AWS CLI Setup Runbook](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html).
35
+
36
+ TL;DR; => Run `aws configure` and enter your `AWS Access Key ID`, `AWS Secret Access Key`, and default
37
+ `region` to use. The region should be a place near you so latency won't be an issue. If you are using
38
+ multiple profiles, please set the environment property accordingly `export AWS_DEFAULT_PROFILE=user2`.
39
+
40
+ Test your CLI by running an AWS command like this one: `aws ec2 describe-instances --output table --region us-east-1`.
41
+
42
+ ## AWS Minecraft Gem
43
+
44
+ ### Instance
45
+
46
+ The instance configuration that is used can be found here: [ec2_config](cfg/ec2_config.json). This
47
+ will configure and create an EC2 instance for you. Couple of things to note here. The instance uses
48
+ an ssh key import which is than used to execute commands on the instance. So in order for this to work
49
+ you'll have to create an SSH key with `ssh-keygen`. Enter your **PUBLIC** key, something like `/Users/youruser/.ssh/ida_rsa.pub`,
50
+ into the file called `Minecraft.key` as a *base64* encoded string.
51
+
52
+ AWS Minecraft uses tmux to run a Minecraft server in the background. The tmux is a multiplexer client
53
+ and will allow us to attach to it later on, if the user would like to run some commands on the server.
54
+
55
+ All this is pre installed on the starting server by this script: [user_data](cfg/user_data.sh).
56
+
57
+ ### AWS Minecraft
58
+
59
+ AWS Minecraft uses a sqlite3 database to store some information about the instance that the user just
60
+ created. This is so, that it's readily available should any query occur so as to not continuously
61
+ query amazon for information about the instance.
62
+
63
+ The [config.yml](cfg/config.yml) file configures this gem. Currently, two settings are available. A
64
+ Logger level setting information which can be overridden any time. And second, it's the location from
65
+ where files will be uploaded to the instance like, Minecraft.jar or craftbukkit.jar. These than will
66
+ be executed during starting a Minecraft server.
67
+
68
+ ### DB
69
+
70
+ The database also needs to be initialised, for this, there is a cli command called init-db. To
71
+ initialise the database, run `bundle exec ./bin/aws_Minecraft.rb init-db`. This will create a
72
+ Minecraft.db file. In case there is anything wrong and you would like to create a new instance, and
73
+ you are sure that the one which is saved, is not the correct one, just delete this file and run
74
+ `init-db` again.
75
+
76
+ # Usage
77
+
78
+ The following commands are available from the CLI tool:
79
+ ```
80
+ Commands:
81
+ aws_minecraft.rb attach-to-server # Attach to a Minecraft server.
82
+ aws_minecraft.rb create-instance # Creates an EC2 instance.
83
+ aws_minecraft.rb help [COMMAND] # Describe available commands or one specific command
84
+ aws_minecraft.rb init-db # Initialize the databse.
85
+ aws_minecraft.rb ssh # SSH into a running EC2 instance.
86
+ aws_minecraft.rb start-instance # Starts an EC2 instance.
87
+ aws_minecraft.rb start-server NAME # Starts a Minecraft server.
88
+ aws_minecraft.rb stop-instance # Stops an EC2 instance.
89
+ aws_minecraft.rb stop-server # Stops a Minecraft server.
90
+ aws_minecraft.rb terminate-instance # Terminates an EC2 instance.
91
+ aws_minecraft.rb upload-files # Uploads everything from drop, not just the world.
92
+ aws_minecraft.rb upload-world # Upload world.
93
+ ```
94
+
95
+ * `attach_to_server` will attach you to a running Minecraft server which you than can control and run
96
+ commands on.
97
+ * `create-instance` this will create your bare bone EC2 instance with some installed packages.
98
+ * `init-db` is explained above
99
+ * `ssh` this will ssh into your instance. For this to work, you'll have to load your private key
100
+ into the ssh agent which belongs to the public key in your instance. To do this, run ssh-add like this:
101
+ `ssh-add ~/.ssh/minecraft_rsa`. **NOTE**: This is an important part. SSH needs to be able to work for
102
+ uploading your files and the world as well.
103
+ * `start-instance` will start a stopped EC2 instance.
104
+ * `start-server NAME` this will start a Minecraft server. NAME here will be the jar you'll upload with
105
+ `upload-files`. For example, if you upload `minecraft-server-1.9.jar` than this would be
106
+ `aws_minecraft.rb start-server minecraft-server-1.9.jar`.
107
+ * `stop-instance` stops your EC2 instance. This is recommended after a session ends, since it would
108
+ generate more usage cost if you left it running. **WARNING**: Do NOT forget to stop your EC2 instance.
109
+ I'm not responsible for you forgetting to do that. :P
110
+ * `stop-server` this stops your running Minecraft server. There is no need for NAME here, since it's
111
+ running in a tmux session for which the name is predefined.
112
+ * `terminate-instance` this will kill off your EC2 instance. **WARNING**: If you do this, you will loose
113
+ all data! There is a prompt before terminate which asks you if you are sure about that.
114
+ * `upload-files` this uploads files from a designated location. You would configure this to be a
115
+ folder in which your world, and minecraft.jar resides in. Once the upload completes, you can start
116
+ your server.
117
+ * `upload-world` in order to avoid re-uploading everything, in case you have a new world you'd like
118
+ to use, you would only run this and point it at the worlds folder. *NOTE*: Incomplete feature.
119
+
120
+ ## Typical use case
121
+
122
+ A typical use case would be to install this gem with `gem install aws_minecraft`. Than setup your
123
+ AWS creds. Next, create your SSH key and copy the base64 encoded public key under cfg/minecraft.key
124
+ (this file is ignored so it won't show up in your repository if you are doing a git clone). Proceed
125
+ with creating the database by running `init-db` and than you are ready to create your first EC2 instance.
126
+ Run `start-instance`. Once the instance is ready, run `upload-files`. The uploads progress is shown.
127
+ When that is finished, you are ready to start your server with `start-server`. This will also give
128
+ you the server's ip address which you will need to enter into Minecraft in order to log in. Play.
129
+ When you are done playing, don't forget to issue a `stop-server` command.
130
+
131
+ If you would like to resume playing on the same server, you would call `start-server` and again,
132
+ enjoy a nice session of Minecraft.
133
+
134
+ # Examples
135
+
136
+ Created the instance
137
+
138
+ ![create](img/create.png)
139
+
140
+ Creation in progress with a progress bar showing that it's working
141
+
142
+ ![create_in_progress](img/create_in_progress.png)
143
+
144
+ Terminating an instance
145
+
146
+ ![terminate](img/terminate.png)
147
+
148
+ Upload files
149
+
150
+ ![upload](img/upload.png)
151
+
152
+ Attach to a running Minecraft server
153
+
154
+ ![attached_session](img/attached_session.png)
155
+
156
+ Attach-Detach to a running session
157
+
158
+ ![attach_detach](img/attach-detach.png)
159
+
160
+ Trying to attach to a not running session
161
+
162
+ ![invalid_attach](img/attach_no_session.png)
163
+
164
+ Stopping a minecraft server
165
+
166
+ ![stop_server](img/stop_server.png)
167
+
168
+ # Contribution
169
+
170
+ Any contributions are very welcomed. Please don't hesitate to open an issue even if it is a question only.
171
+ The Roadmap outlines things that are missing and would be nice to have.
@@ -0,0 +1,46 @@
1
+ Roadmap for aws_minecraft
2
+ =========================
3
+
4
+ 0.2.0
5
+ -----
6
+
7
+ * Working on coverage is important. Adding unit tests for ssh, uploader and negative scenarios for
8
+ aws_helper would be Next.
9
+ * Some of the error cases are not handled really well at the moment. They just raise an error.
10
+ * Upload world is not working yet.
11
+ * Everything Minecraft related could be extracted.
12
+ * Would be nice if it wouldn't re-upload.
13
+ * start-server doesn't tell you if starting the tmux session was successful or not.
14
+
15
+ 0.1.0
16
+ -----
17
+
18
+ * This is an MVP at this stage, with everything working and the most important parts have unit tests.
19
+
20
+
21
+ 0.0.4
22
+ -----
23
+
24
+ * Stopping minecraft server
25
+ * Attaching to PID to see output and to run commands
26
+ * Investiage tmux to run minecraft and attach to later (This would save a lot of trouble)
27
+ * Use tmux like this:
28
+ ```bash
29
+ # runs a tmux session and detaches from it
30
+ tmux new -d -s minecraft 'java -jar minecraft_server.jar nogui'
31
+ # can attach to the running session so that we can control minecraft
32
+ tmux attach -t minecraft
33
+ ```
34
+
35
+ 0.0.3
36
+ -----
37
+
38
+ * Ready the CLI for starting a minecraft server
39
+ * Includes uploading a minecraft jar
40
+ * Remote execution on the host
41
+ * Saving PID id of the minecraft process
42
+
43
+ 0.0.2
44
+ -----
45
+
46
+ * Ready the CLI for starting, stopping, terminating, creating ec2 instance
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
8
+ rescue LoadError => le
9
+ puts "There was a problem loading RSpec. #{le}."
10
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), 'lib', 'aws_minecraft', 'version')
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'aws_minecraft'
7
+ s.version = AWSMine::AWSMine::VERSION
8
+ s.required_rubygems_version =
9
+ Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
+ s.authors = ['Gergely Brautigam']
11
+ s.summary = 'A minecraft server provisioner on an AWS EC2 instance.'
12
+ s.description = 'Provisions an EC2. Uploads a world, and deploys it.'
13
+ s.email = 'skarlso777@gmail.com'
14
+ s.extra_rdoc_files = ['README.md']
15
+ s.files = `git ls-files`.split("\n")
16
+ s.files << './cfg/minecraft.key'
17
+ s.homepage = 'https://github.com/Skarlso/aws_minecraft'
18
+ s.rdoc_options = ['--charset=UTF-8']
19
+ s.require_paths = ['lib']
20
+ s.rubygems_version = '2.6.6'
21
+ s.test_files = `git ls-files`.split("\n").select { |f| f =~ /^specs/ }
22
+ s.rubyforge_project = 'aws_minecraft'
23
+ s.executables = `git ls-files -- bin/*`.split("\n")
24
+ .map { |f| File.basename(f) }
25
+ s.licenses = ['MIT']
26
+
27
+ # dependencies
28
+ s.add_development_dependency 'code_stats'
29
+ s.add_development_dependency 'rake'
30
+ s.add_development_dependency 'rspec'
31
+ s.add_development_dependency 'bundler'
32
+ end
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'aws_minecraft'
5
+
6
+ # Providing a binary for AWSMine.
7
+ class AWSMineCli < Thor
8
+ def initialize(*args)
9
+ super
10
+ @aws_mine = AWSMine::AWSMine.new
11
+ end
12
+
13
+ desc 'create-instance', 'Creates an EC2 instance.'
14
+ def create_instance
15
+ @aws_mine.create_instance
16
+ end
17
+
18
+ desc 'start-instance', 'Starts an EC2 instance.'
19
+ def start_instance
20
+ @aws_mine.start_instance
21
+ end
22
+
23
+ desc 'stop-instance', 'Stops an EC2 instance.'
24
+ def stop_instance
25
+ @aws_mine.stop_instance
26
+ end
27
+
28
+ desc 'terminate-instance', 'Terminates an EC2 instance.'
29
+ def terminate_instance
30
+ @aws_mine.terminate_instance
31
+ end
32
+
33
+ desc 'ssh', 'SSH into a running EC2 instance.'
34
+ def ssh
35
+ # @aws_mine.remote_exec('ls -l')
36
+ @aws_mine.ssh
37
+ end
38
+
39
+ # Handle minecraft server version here.
40
+ desc 'start-server NAME', 'Starts a minecraft server.'
41
+ def start_server(name = 'minecraft_server.jar')
42
+ @aws_mine.start_server(name)
43
+ end
44
+
45
+ desc 'stop-server', 'Stops a minecraft server.'
46
+ def stop_server
47
+ @aws_mine.stop_server
48
+ end
49
+
50
+ desc 'attach-to-server', 'Attach to a minecraft server.'
51
+ def attach_to_server
52
+ @aws_mine.attach_to_server
53
+ end
54
+
55
+ desc 'upload-world', 'Upload world.'
56
+ def upload_world
57
+ end
58
+
59
+ desc 'upload-files', 'Uploads everything from drop, not just the world.'
60
+ def upload_files
61
+ @aws_mine.upload_files
62
+ end
63
+
64
+ desc 'init-db', 'Initialize the databse.'
65
+ def init_db
66
+ @aws_mine.init_db
67
+ end
68
+ end
69
+
70
+ AWSMineCli.start