itamae-plugin-recipe-minecraft 0.0.1

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: 9ff41cbdf8f095f88a114722b7b9d684777496ad
4
+ data.tar.gz: bfb0dba1711e7e13a97f6ffafbdd6a314dbd14ba
5
+ SHA512:
6
+ metadata.gz: 471662ccb1b43f1a69a94cc709ac568da1097dfef4f46c7eea500e87a487ec69fa916689923558e687831c3e8c1b3801d3ea5c781bd85c2b17e92abf18d45244
7
+ data.tar.gz: 9de780d8349cb62a0ce587a3df53d370134182d3aa35f5eace340b11db2eabc589b5df6c2537c593cb4965e5c3de911a9c048d1c84b64d0a66f3f0b2942623e4
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in itamae-plugin-recipe-minecraft.gemspec
4
+ gemspec
@@ -0,0 +1,49 @@
1
+ # Itamae::Plugin::Recipe::Minecraft
2
+
3
+ original startup script: [Tutorials/Server startup script - Minecraft Wiki](http://minecraft.gamepedia.com/Tutorials/Server_startup_script)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'itamae-plugin-recipe-minecraft'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install itamae-plugin-recipe-minecraft
20
+
21
+ ## Usage
22
+
23
+ include_recipe 'minecraft'
24
+
25
+ service 'minecraft' do
26
+ action :enable
27
+ end
28
+
29
+ service 'minecraft' do
30
+ action :start
31
+ end
32
+
33
+ ### attributes
34
+
35
+ {
36
+ "minecraft": {
37
+ "user": "minecraft",
38
+ "max_heap": 2048,
39
+ "min_heap": 1024
40
+ }
41
+ }
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/hanachin/itamae-plugin-recipe-minecraft/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'itamae/plugin/recipe/minecraft/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "itamae-plugin-recipe-minecraft"
8
+ spec.version = Itamae::Plugin::Recipe::Minecraft::VERSION
9
+ spec.authors = ["Seiei Higa"]
10
+ spec.email = ["hanachin@gmail.com"]
11
+ spec.summary = %q{itamae recipe for minecraft.}
12
+ spec.homepage = "https://github.com/hanachin/itamae-plugin-recipe-minecraft"
13
+ spec.license = "CC BY-NC-SA 3.0"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,181 @@
1
+ #!/bin/bash
2
+ # /etc/init.d/minecraft
3
+ # version 0.3.9 2012-08-13 (YYYY-MM-DD)
4
+
5
+ ### BEGIN INIT INFO
6
+ # Provides: minecraft
7
+ # Required-Start: $local_fs $remote_fs screen-cleanup
8
+ # Required-Stop: $local_fs $remote_fs
9
+ # Should-Start: $network
10
+ # Should-Stop: $network
11
+ # Default-Start: 2 3 4 5
12
+ # Default-Stop: 0 1 6
13
+ # Short-Description: Minecraft server
14
+ # Description: Starts the minecraft server
15
+ ### END INIT INFO
16
+
17
+ #Settings
18
+ SERVICE='minecraft_server.jar'
19
+ OPTIONS='nogui'
20
+ USERNAME='<%= @user %>'
21
+ WORLD='world'
22
+ MCPATH='/opt/minecraft'
23
+ BACKUPPATH='/opt/minecraft/backups'
24
+ MAXHEAP=<%= @max_heap || 2048 %>
25
+ MINHEAP=<%= @min_heap || 1024 %>
26
+ HISTORY=1024
27
+ CPU_COUNT=1
28
+ INVOCATION="java -Xmx${MAXHEAP}M -Xms${MINHEAP}M -XX:+UseConcMarkSweepGC \
29
+ -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts \
30
+ -jar $SERVICE $OPTIONS"
31
+
32
+ ME=`whoami`
33
+ as_user() {
34
+ echo "as_user: $1"
35
+ if [ $ME == $USERNAME ] ; then
36
+ bash -c "$1"
37
+ else
38
+ su - $USERNAME -s /bin/bash -c "$1"
39
+ fi
40
+ }
41
+
42
+ mc_start() {
43
+ if pgrep -u $USERNAME -f $SERVICE > /dev/null
44
+ then
45
+ echo "$SERVICE is already running!"
46
+ else
47
+ echo "Starting $SERVICE..."
48
+ cd $MCPATH
49
+ as_user "cd $MCPATH && screen -h $HISTORY -dmS minecraft $INVOCATION"
50
+ sleep 7
51
+ if pgrep -u $USERNAME -f $SERVICE > /dev/null
52
+ then
53
+ echo "$SERVICE is now running."
54
+ else
55
+ echo "Error! Could not start $SERVICE!"
56
+ fi
57
+ fi
58
+ }
59
+
60
+ mc_saveoff() {
61
+ if pgrep -u $USERNAME -f $SERVICE > /dev/null
62
+ then
63
+ echo "$SERVICE is running... suspending saves"
64
+ as_user "screen -p 0 -S minecraft -X eval 'stuff \"say SERVER BACKUP STARTING. Server going readonly...\"\015'"
65
+ as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-off\"\015'"
66
+ as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-all\"\015'"
67
+ sync
68
+ sleep 10
69
+ else
70
+ echo "$SERVICE is not running. Not suspending saves."
71
+ fi
72
+ }
73
+
74
+ mc_saveon() {
75
+ if pgrep -u $USERNAME -f $SERVICE > /dev/null
76
+ then
77
+ echo "$SERVICE is running... re-enabling saves"
78
+ as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-on\"\015'"
79
+ as_user "screen -p 0 -S minecraft -X eval 'stuff \"say SERVER BACKUP ENDED. Server going read-write...\"\015'"
80
+ else
81
+ echo "$SERVICE is not running. Not resuming saves."
82
+ fi
83
+ }
84
+
85
+ mc_stop() {
86
+ if pgrep -u $USERNAME -f $SERVICE > /dev/null
87
+ then
88
+ echo "Stopping $SERVICE"
89
+ as_user "screen -p 0 -S minecraft -X eval 'stuff \"say SERVER SHUTTING DOWN IN 10 SECONDS. Saving map...\"\015'"
90
+ as_user "screen -p 0 -S minecraft -X eval 'stuff \"save-all\"\015'"
91
+ sleep 10
92
+ as_user "screen -p 0 -S minecraft -X eval 'stuff \"stop\"\015'"
93
+ sleep 7
94
+ else
95
+ echo "$SERVICE was not running."
96
+ fi
97
+ if pgrep -u $USERNAME -f $SERVICE > /dev/null
98
+ then
99
+ echo "Error! $SERVICE could not be stopped."
100
+ else
101
+ echo "$SERVICE is stopped."
102
+ fi
103
+ }
104
+
105
+ mc_backup() {
106
+ mc_saveoff
107
+
108
+ NOW=`date "+%Y-%m-%d_%Hh%M"`
109
+ BACKUP_FILE="$BACKUPPATH/${WORLD}_${NOW}.tar"
110
+ echo "Backing up minecraft world..."
111
+ #as_user "cd $MCPATH && cp -r $WORLD $BACKUPPATH/${WORLD}_`date "+%Y.%m.%d_%H.%M"`"
112
+ as_user "tar -C \"$MCPATH\" -cf \"$BACKUP_FILE\" $WORLD"
113
+
114
+ echo "Backing up $SERVICE"
115
+ as_user "tar -C \"$MCPATH\" -rf \"$BACKUP_FILE\" $SERVICE"
116
+ #as_user "cp \"$MCPATH/$SERVICE\" \"$BACKUPPATH/minecraft_server_${NOW}.jar\""
117
+
118
+ mc_saveon
119
+
120
+ echo "Compressing backup..."
121
+ as_user "gzip -f \"$BACKUP_FILE\""
122
+ echo "Done."
123
+ }
124
+
125
+ mc_command() {
126
+ command="$1";
127
+ if pgrep -u $USERNAME -f $SERVICE > /dev/null
128
+ then
129
+ pre_log_len=`wc -l "$MCPATH/logs/latest.log" | awk '{print $1}'`
130
+ echo "$SERVICE is running... executing command"
131
+ as_user "screen -p 0 -S minecraft -X eval 'stuff \"$command\"\015'"
132
+ sleep .1 # assumes that the command will run and print to the log file in less than .1 seconds
133
+ # print output
134
+ tail -n $[`wc -l "$MCPATH/logs/latest.log" | awk '{print $1}'`-$pre_log_len] "$MCPATH/logs/latest.log"
135
+ fi
136
+ }
137
+
138
+ #Start-Stop here
139
+ case "$1" in
140
+ start)
141
+ mc_start
142
+ ;;
143
+ stop)
144
+ mc_stop
145
+ ;;
146
+ restart)
147
+ mc_stop
148
+ mc_start
149
+ ;;
150
+ update)
151
+ mc_stop
152
+ mc_backup
153
+ mc_start
154
+ ;;
155
+ backup)
156
+ mc_backup
157
+ ;;
158
+ status)
159
+ if pgrep -u $USERNAME -f $SERVICE > /dev/null
160
+ then
161
+ echo "$SERVICE is running."
162
+ else
163
+ echo "$SERVICE is not running."
164
+ fi
165
+ ;;
166
+ command)
167
+ if [ $# -gt 1 ]; then
168
+ shift
169
+ mc_command "$*"
170
+ else
171
+ echo "Must specify server command (try 'help'?)"
172
+ fi
173
+ ;;
174
+
175
+ *)
176
+ echo "Usage: $0 {start|stop|update|backup|status|restart|command \"server command\"}"
177
+ exit 1
178
+ ;;
179
+ esac
180
+
181
+ exit 0
@@ -0,0 +1,76 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ minecraft_versions_url = 'http://s3.amazonaws.com/Minecraft.Download/versions/versions.json'
5
+ minecraft_version = node[:minecraft][:version] || JSON.parse(open(minecraft_versions_url).read)['latest']['release']
6
+
7
+ minecraft_dir = '/opt/minecraft'
8
+ minecraft_server_url = "https://s3.amazonaws.com/Minecraft.Download/versions/#{minecraft_version}/minecraft_server.#{minecraft_version}.jar"
9
+ filename = File.basename(minecraft_server_url)
10
+ minecraft_path = "#{minecraft_dir}/#{filename}"
11
+
12
+ minecraft_user = node[:minecraft][:user] || 'minecraft'
13
+
14
+ directory minecraft_dir do
15
+ action :create
16
+ mode '775'
17
+ group minecraft_user
18
+ end
19
+
20
+ directory "#{minecraft_dir}/backups" do
21
+ action :create
22
+ mode '775'
23
+ group minecraft_user
24
+ end
25
+
26
+ user 'create minecraft user' do
27
+ username 'minecraft'
28
+ home minecraft_dir
29
+ system_user true
30
+ end
31
+
32
+ execute "minecraft user can't login" do
33
+ command 'chsh -s /usr/sbin/nologin minecraft'
34
+ end
35
+
36
+ execute 'download minecraft server' do
37
+ command "wget #{minecraft_server_url} -O #{minecraft_path}"
38
+ not_if "test -f #{minecraft_path}"
39
+ end
40
+
41
+ execute 'make executable' do
42
+ command "chmod 0754 #{minecraft_path}"
43
+ end
44
+
45
+ execute 'change minecraft server owner' do
46
+ command "chown root:#{minecraft_user} #{minecraft_path}"
47
+ end
48
+
49
+ execute 'create symlink to minecraft jar' do
50
+ command "ln -sf #{filename} minecraft_server.jar"
51
+ cwd minecraft_dir
52
+ end
53
+
54
+ file "#{minecraft_dir}/eula.txt" do
55
+ content 'eula=true'
56
+ owner minecraft_user
57
+ group minecraft_user
58
+ end
59
+
60
+ package 'screen'
61
+
62
+ template '/etc/init.d/minecraft' do
63
+ mode '755'
64
+ owner 'root'
65
+ group 'root'
66
+ source 'minecraft.erb'
67
+ variables({
68
+ user: minecraft_user,
69
+ max_heap: node[:minecraft][:max_heap],
70
+ min_heap: node[:minecraft][:min_heap]
71
+ })
72
+ end
73
+
74
+ execute 'create minecraft service' do
75
+ command 'insserv minecraft'
76
+ end
@@ -0,0 +1,9 @@
1
+ module Itamae
2
+ module Plugin
3
+ module Recipe
4
+ module Minecraft
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itamae-plugin-recipe-minecraft
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Seiei Higa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - hanachin@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - itamae-plugin-recipe-minecraft.gemspec
53
+ - lib/itamae/plugin/recipe/minecraft.erb
54
+ - lib/itamae/plugin/recipe/minecraft.rb
55
+ - lib/itamae/plugin/recipe/minecraft/version.rb
56
+ homepage: https://github.com/hanachin/itamae-plugin-recipe-minecraft
57
+ licenses:
58
+ - CC BY-NC-SA 3.0
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.5
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: itamae recipe for minecraft.
80
+ test_files: []