Permalink
Browse files

better zram

  • Loading branch information...
Raekye committed Oct 27, 2015
1 parent c65a192 commit f95837e9d2ba2119486a40be341cb77401991acd
Showing with 59 additions and 30 deletions.
  1. +16 −0 README.md
  2. +5 −15 app/workers/setup_server_worker.rb
  3. +29 −0 server_setup/zram-helper.sh
  4. +8 −0 server_setup/zram.service
  5. +0 −14 sysadmin/update.pl
  6. +1 −1 test-docker/systemctl.sh
@@ -37,6 +37,21 @@ The following instructions were made for Fedora 20, but the steps should be simi
1. Start the server: `./run.sh rails s`
1. Start the Sidekiq worker: `./run.sh sidekiq`

### Directory hierarchy
- app: main source code
- bin: rails stuff, don't touch
- config: rails app configuration
- db: rails app database stuff (schema, migrations, seeds)
- lib: rails stuff, don't touch
- log: 'nuff said
- public: static files
- server\_setup: stuff for the servers Gamocosm creates (e.g. zram scripts), used by `app/workers/setup_server_worker.rb`
- see [Additional Info for Server Admins][15] on the wiki for more information
- sysadmin: stuff for the Gamocosm server (you can run your own server! this is an open source project)
- test-docker: use docker container to test most of `app/workers/setup_server_worker.rb` (more below)
- test: pooteeweet
- vendor: rails stuff, don't touch

### run.sh and env.sh options
`run.sh` and `tests.sh` both source `env.sh` for environment variables/configuration.
`run.sh` also does `bundle exec` for you, so you just do `./run.sh GEM ARGS ...`.
@@ -194,3 +209,4 @@ Example: `TEST_DOCKER=true ./tests.sh`
[12]: https://github.com/KayoticSully
[13]: https://rvm.io
[14]: https://www.reddit.com/user/Jadorel
[15]: https://github.com/Gamocosm/Gamocosm/wiki/Additional-Info-for-Server-Admins
@@ -23,20 +23,8 @@ class SetupServerWorker
'wget'
]

ZRAM_SYSTEMD_SERVICE_ESCAPED = [
'[Unit]',
'Description=Zram',
'',
'[Service]',
'Type=oneshot',
'ExecStart=/usr/sbin/modprobe zram',
'ExecStart=/usr/bin/env bash -c \'echo 128M > /sys/block/zram0/disksize\'',
'ExecStart=/usr/sbin/mkswap /dev/zram0',
'ExecStart=/usr/sbin/swapon --priority 100 /dev/zram0',
'',
'[Install]',
'WantedBy=multi-user.target',
].join('\n').shell_escape
ZRAM_SYSTEMD_SERVICE_FILE_URL = 'https://raw.githubusercontent.com/Gamocosm/Gamocosm/release/server_setup/zram.service'
ZRAM_HELPER_SCRIPT_URL = 'https://raw.githubusercontent.com/Gamocosm/Gamocosm/release/server_setup/zram-helper.sh'

def perform(server_id, times = 0)
server = Server.find(server_id)
@@ -134,7 +122,9 @@ def base_install(user, server, host)
execute :usermod, '-aG', 'wheel', 'mcuser'

# setup zram
execute :echo, '-e', ZRAM_SYSTEMD_SERVICE_ESCAPED, '>', '/etc/systemd/system/zram.service'
execute :curl, '-o', '/etc/systemd/system/zram.service', "'#{ZRAM_SYSTEMD_SERVICE_FILE_URL}'"
execute :curl, '-o', '/usr/bin/zram-helper', "'#{ZRAM_HELPER_SCRIPT_URL}'"
execute :chmod, '+x', '/usr/bin/zram-helper'
execute :systemctl, 'enable', 'zram'
execute :systemctl, 'start', 'zram'

@@ -0,0 +1,29 @@
#!/usr/bin/env bash

# Source: Gamocosm

NUM_CPUS=$(grep --count '^processor' /proc/cpuinfo)
TOTAL_RAM=$(awk '/MemTotal/ { print $2; }' /proc/meminfo)

# convert to bytes, half or ram, split between cpus
DEVICE_SIZE=$((TOTAL_RAM * 1024 / 2 / NUM_CPUS));

case "$1" in
"start")
modprobe zram "num_devices=$NUM_CPUS"
for ((i = 0; i < $NUM_CPUS; i++)); do
echo $DEVICE_SIZE > "/sys/block/zram${i}/disksize"
mkswap "/dev/zram${i}"
swapon --priority 100 "/dev/zram${i}"
done
;;
"stop")
for device in $(awk '/zram/ { print $1; }' /proc/swaps); do
swapoff "$device"
done
rmmod zram
;;
*)
echo "Usage: zram [start|stop]"
;;
esac
@@ -0,0 +1,8 @@
[Unit]
Description=Zram (source: Gamocosm)

[Service]
ExecStart=/usr/bin/zram-helper start

[Install]
WantedBy=multi-user.target

This file was deleted.

Oops, something went wrong.
@@ -1,6 +1,6 @@
#!/bin/bash
echo 'In Docker container; patching systemctl.'
if [[ "$1" == "start" ]]; then
if [[ "$1" == "start" ]] && [[ "$2" == "mcsw" ]]; then
cd /home/mcuser/minecraft
echo | python3 /opt/gamocosm/minecraft-server_wrapper.py daemonize mcsw.pid --auth=/opt/gamocosm/mcsw-auth.txt > /dev/null 2>&1
sleep 2

0 comments on commit f95837e

Please sign in to comment.