diff --git a/contrib/etc/default/tiny-web-example-webapp b/contrib/etc/default/tiny-web-example-webapp new file mode 100644 index 0000000..9b8d90e --- /dev/null +++ b/contrib/etc/default/tiny-web-example-webapp @@ -0,0 +1,11 @@ +# tiny-web-example +EXAMPLE_ROOT=/opt/axsh/tiny-web-example + +# Commnet out to run the vdc init script. +#RUN=yes + +## rack params +RACK_ENV=development +#BIND_ADDR=0.0.0.0 +#PORT=80 +#UNICORN_CONF=/etc/tiny-web-example/unicorn-common.conf \ No newline at end of file diff --git a/contrib/etc/init/tiny-web-example-webapp.conf b/contrib/etc/init/tiny-web-example-webapp.conf new file mode 100644 index 0000000..074ced7 --- /dev/null +++ b/contrib/etc/init/tiny-web-example-webapp.conf @@ -0,0 +1,33 @@ +description "tiny web example: web application" +author "axsh Co." + +start on started tiny-web-example-webapp +stop on stopped tiny-web-example-webapp + +respawn +respawn limit 5 60 + +env NAME=webapp + +script + [ -f /etc/default/tiny-web-example-${NAME} ] && . /etc/default/tiny-web-example-${NAME} + # Make RUN=yes effective only at auto start. + [ -n "$UPSTART_EVENTS" -a "x${RUN}" != "xyes" ] && { + logger "[${NAME}] Skip auto start for ${NAME}. Edit /etc/default/tiny-web-example-${NAME} to set RUN=yes." + exit 0 + } + + ulimit -c ${DAEMON_COREFILE_LIMIT:-0} + + [ -d "${EXAMPLE_ROOT}" ] || { + logger "no such directory: ${EXAMPLE_ROOT}" + exit 1 + } + cd ${EXAMPLE_ROOT}/frontend/ + + exec bundle exec unicorn \ + -o ${BIND_ADDR:-0.0.0.0} \ + -p ${PORT:-80} \ + -c ${UNICORN_CONF:-/etc/tiny-web-example/unicorn-common.conf} ./config-${NAME}.ru \ + >> /var/log/tiny-web-example/${NAME}.log 2>&1 +end script \ No newline at end of file diff --git a/webapi/config/webapi.conf b/contrib/etc/tiny-web-example/webapi.conf similarity index 100% rename from webapi/config/webapi.conf rename to contrib/etc/tiny-web-example/webapi.conf diff --git a/contrib/etc/tiny-web-example/webapp.yml b/contrib/etc/tiny-web-example/webapp.yml new file mode 100644 index 0000000..73f783f --- /dev/null +++ b/contrib/etc/tiny-web-example/webapp.yml @@ -0,0 +1 @@ +database_uri: 'mysql2://localhost/tiny_web_example?user=root' \ No newline at end of file diff --git a/frontend/config-webapp.ru b/frontend/config-webapp.ru index 2869e22..74d39c1 100644 --- a/frontend/config-webapp.ru +++ b/frontend/config-webapp.ru @@ -2,6 +2,9 @@ require 'rubygems' require 'sinatra' +require 'sinatra/config_file' + +config_file 'config/webapp.yml', '/etc/tiny-web-example/webapp.yml' $LOAD_PATH.unshift File.expand_path('..', __FILE__) diff --git a/frontend/config/webapp.yml.example b/frontend/config/webapp.yml.example new file mode 100644 index 0000000..73f783f --- /dev/null +++ b/frontend/config/webapp.yml.example @@ -0,0 +1 @@ +database_uri: 'mysql2://localhost/tiny_web_example?user=root' \ No newline at end of file diff --git a/frontend/models/comment.rb b/frontend/models/comment.rb index b6b5fb3..ff73c21 100644 --- a/frontend/models/comment.rb +++ b/frontend/models/comment.rb @@ -2,7 +2,7 @@ require 'sequel' -Sequel.connect("mysql2://localhost/tiny_web_example?user=root") +Sequel.connect(settings.database_uri) class Comment < Sequel::Model plugin :validation_helpers diff --git a/frontend/views/index.erb b/frontend/views/index.erb index 085e107..02565c8 100644 --- a/frontend/views/index.erb +++ b/frontend/views/index.erb @@ -7,6 +7,11 @@
<%= @errors %>
+ +