-
Notifications
You must be signed in to change notification settings - Fork 0
/
thingspeak.def
122 lines (110 loc) · 4.13 KB
/
thingspeak.def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Bootstrap: docker
From: mchawre/ubuntu-12.04
%labels
Author Ivan Mičetić
Version 0.1.1
%post
# Update system
export LC_ALL=C
export DEBIAN_FRONTEND=noninteractive
export TZ=UTC
rm -fv /etc/apt/sources.list.d/proposed.list
sed -i 's/archive\.ubuntu/old-releases\.ubuntu/' /etc/apt/sources.list
apt-get update
apt-get -y --no-install-recommends install \
dialog \
apt-utils
apt-get -y purge apache2
apt-get -y --no-install-recommends install \
build-essential \
mysql-client \
libssl1.0.0 \
libmysqlclient-dev \
libxml2-dev \
libxslt-dev \
git-core \
curl
# Install Ruby 2.1.0 via rvm
cd /opt
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -
export rvm_path=/opt/rvm
# Use insecure connection for rvm download
# \curl -sSL https://get.rvm.io | bash -s stable
\curl -Lk https://get.rvm.io | bash -s stable
export rvm_bin_prvmath=/opt/rvm/bin
export GEM_HOME=/opt/rvm/gems/ruby-2.1.0
export IRBRC=/opt/rvm/rubies/ruby-2.1.0/.irbrc
export MY_RUBY_HOME=/opt/rvm/rubies/ruby-2.1.0
export rvm_prefix=/opt
export PATH=/opt/rvm/gems/ruby-2.1.0/bin:/opt/rvm/gems/ruby-2.1.0@global/bin:/opt/rvm/rubies/ruby-2.1.0/bin:/opt/rvm/bin:${PATH}
export rvm_version="1.29.12 (latest)"
export GEM_PATH=/opt/rvm/gems/ruby-2.1.0:/opt/rvm/gems/ruby-2.1.0@global
rvm install ruby-2.1.0
# Install ThingSpeak server from official repository
git clone https://github.com/iobridge/thingspeak.git
cd /opt/thingspeak
rm -fv tmp log
ln -s /tmp tmp
ln -s /tmp log
chmod 777 tmp log
gem install minitest -v '4.7.5'
gem install json -v '1.8.1'
bundle install
cp config/database.yml.example config/database.yml
# Use database at host
sed -i -r -e 's/^([^#].*socket:.*)/#\1\n host: 127.0.0.1/' config/database.yml
# Fix for newer versions of MySQL
sed -ri "s/^(require File.*)/\1\nrequire File\.expand_path\('\.\.\/initializers\/mysql2_adapter', __FILE__\)\n/" \
/opt/thingspeak/config/environment.rb
echo "require 'active_record/connection_adapters/mysql2_adapter'" \
>/opt/thingspeak/config/initializers/mysql2_adapter.rb
echo "class ActiveRecord::ConnectionAdapters::Mysql2Adapter" \
>>/opt/thingspeak/config/initializers/mysql2_adapter.rb
echo ' NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"' \
>>/opt/thingspeak/config/initializers/mysql2_adapter.rb
echo "end" >>/opt/thingspeak/config/initializers/mysql2_adapter.rb
# Setup database
if [ -z ${SKIP_DB_SETUP+x} ]; then
rake db:create
rake db:schema:load
fi
# Clean up
apt-get -y purge build-essential \
git-core \
curl
apt-get -y autoremove
apt-get clean
rm -rf /var/lib/apt/lists/*
rm -f /tmp/development.log
%test
if [ -z ${SKIP_DB_SETUP+x} ]; then
# This will pass if ThingSpeak server was installed successfully
# and database on host was initialized properly
mysql -u thing -pspeak -h 127.0.0.1 -e \
"SHOW COLUMNS FROM thingspeak_development.users" >/dev/null
if [ $? -ne 0 ]; then
echo "Error connecting or reading database on host, aborting!"
exit 1
fi
else
echo "Skipping test (SKIP_DB_SETUP is set)..."
fi
%environment
export LC_ALL=C
export rvm_bin_prvmath=/opt/rvm/bin
export GEM_HOME=/opt/rvm/gems/ruby-2.1.0
export IRBRC=/opt/rvm/rubies/ruby-2.1.0/.irbrc
export MY_RUBY_HOME=/opt/rvm/rubies/ruby-2.1.0
export rvm_prefix=/opt
export PATH=/opt/rvm/gems/ruby-2.1.0/bin:/opt/rvm/gems/ruby-2.1.0@global/bin:/opt/rvm/rubies/ruby-2.1.0/bin:/opt/rvm/bin:${PATH}
export rvm_version="1.29.12 (latest)"
export GEM_PATH=/opt/rvm/gems/ruby-2.1.0:/opt/rvm/gems/ruby-2.1.0@global
export LISTEN_PORT=3000
%runscript
echo "Starting rails server ..."
cd /opt/thingspeak
exec rails server -p $LISTEN_PORT
%startscript
cd /opt/thingspeak
nohup rails server -p $LISTEN_PORT >/dev/null 2>&1 </dev/null &