From e3a31d722b8764047e472b658271e6788c13aa85 Mon Sep 17 00:00:00 2001 From: Rhett Lee Date: Mon, 1 Feb 2016 16:43:07 +0800 Subject: [PATCH] fix 'rails s' not work --- server/.gitignore | 2 ++ server/bin/bundle | 3 +++ server/bin/rails | 9 +++++++++ server/bin/rake | 9 +++++++++ server/bin/setup | 34 ++++++++++++++++++++++++++++++++++ server/bin/spring | 15 +++++++++++++++ server/bin/update | 29 +++++++++++++++++++++++++++++ 7 files changed, 101 insertions(+) create mode 100755 server/bin/bundle create mode 100755 server/bin/rails create mode 100755 server/bin/rake create mode 100755 server/bin/setup create mode 100755 server/bin/spring create mode 100755 server/bin/update diff --git a/server/.gitignore b/server/.gitignore index 050c9d9..c0ed308 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -15,3 +15,5 @@ /log/* !/log/.keep /tmp + +!/bin diff --git a/server/bin/bundle b/server/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/server/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/server/bin/rails b/server/bin/rails new file mode 100755 index 0000000..0138d79 --- /dev/null +++ b/server/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/server/bin/rake b/server/bin/rake new file mode 100755 index 0000000..d87d5f5 --- /dev/null +++ b/server/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/server/bin/setup b/server/bin/setup new file mode 100755 index 0000000..589bee8 --- /dev/null +++ b/server/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') or system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/server/bin/spring b/server/bin/spring new file mode 100755 index 0000000..62ec28f --- /dev/null +++ b/server/bin/spring @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)) + Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq } + gem 'spring', match[1] + require 'spring/binstub' + end +end diff --git a/server/bin/update b/server/bin/update new file mode 100755 index 0000000..9851923 --- /dev/null +++ b/server/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system 'bundle check' or system! 'bundle install' + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end