Class: FluentdServer::CLI
- Inherits:
-
Thor
- Object
- Thor
- FluentdServer::CLI
- Defined in:
- lib/fluentd_server/cli.rb
Constant Summary collapse
- BASE_DIR =
File.join(Dir.pwd, "fluentd-server")
- DATA_DIR =
File.join(BASE_DIR, "data")
- LOG_DIR =
File.join(BASE_DIR, "log")
- JOB_DIR =
File.join(BASE_DIR, "jobs")
- LOG_FILE =
File.join(LOG_DIR, "application.log")
- ENV_FILE =
File.join(BASE_DIR, ".env")
- PROCFILE =
File.join(BASE_DIR, "Procfile")
- CONFIGRU_FILE =
File.join(BASE_DIR, "config.ru")
- CONFIG_DIR =
File.join(BASE_DIR, "config")
- DEFAULT_DOTENV =
<<-EOS PORT=5126 HOST=0.0.0.0 DATABASE_URL=sqlite3:#{DATA_DIR}/fluentd_server.db JOB_DIR=#{JOB_DIR} LOG_PATH=#{LOG_FILE} LOG_LEVEL=warn LOG_SHIFT_AGE=0 LOG_SHIFT_SIZE=1048576 EOS
- DEFAULT_PROCFILE =
<<-EOS web: unicorn -E production -p $PORT -o $HOST -c config/unicorn.conf job: fluentd-server job serf: $(gem path serf-td-agent)/bin/serf agent EOS
Instance Method Summary collapse
- #init ⇒ Object
-
#initialize(args = [], opts = [], config = {}) ⇒ CLI
constructor
A new instance of CLI.
- #job ⇒ Object
- #job_clear ⇒ Object
- #migrate ⇒ Object
- #new ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(args = [], opts = [], config = {}) ⇒ CLI
Returns a new instance of CLI.
36 37 38 |
# File 'lib/fluentd_server/cli.rb', line 36 def initialize(args = [], opts = [], config = {}) super(args, opts, config) end |
Instance Method Details
#init ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fluentd_server/cli.rb', line 52 def init Dotenv.load require 'fluentd_server/environment' require 'rake' require 'sinatra/activerecord/rake' ActiveRecord::Tasks::DatabaseTasks.db_dir = File.("../../../db", __FILE__) ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [File.("../../../db/migrate", __FILE__)] # ToDo: Fix that db:migrate raises an error in the case of sqlite3 like # SQLite3::SQLException: database schema has changed: INSERT INTO "schema_migrations" ("version") VALUES (?) # Rake::Task['db:migrate'].invoke # Use db:schema:load after generating db/schema.rb by executing db:migrate several times for now Rake::Task['db:schema:load'].invoke puts 'fluentd-server init finished.' end |
#job ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/fluentd_server/cli.rb', line 87 def job Dotenv.load require 'delayed_job' require 'fluentd_server/model' = { :min_priority => ENV['MIN_PRIORITY'], :max_priority => ENV['MAX_PRIORITY'], :queues => (ENV['QUEUES'] || ENV['QUEUE'] || '').split(','), :quiet => false } Delayed::Worker.new().start end |
#job_clear ⇒ Object
101 102 103 104 105 106 |
# File 'lib/fluentd_server/cli.rb', line 101 def job_clear Dotenv.load require 'delayed_job' require 'fluentd_server/model' Delayed::Job.delete_all end |
#migrate ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/fluentd_server/cli.rb', line 68 def migrate Dotenv.load require 'fluentd_server/environment' require 'rake' require 'sinatra/activerecord/rake' ActiveRecord::Tasks::DatabaseTasks.db_dir = File.("../../../db", __FILE__) ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [File.("../../../db/migrate", __FILE__)] Rake::Task['db:migrate'].invoke end |
#new ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/fluentd_server/cli.rb', line 41 def new FileUtils.mkdir_p(LOG_DIR) FileUtils.mkdir_p(JOB_DIR) File.write ENV_FILE, DEFAULT_DOTENV File.write PROCFILE, DEFAULT_PROCFILE FileUtils.cp(File.("../../../config.ru", __FILE__), CONFIGRU_FILE) FileUtils.cp_r(File.("../../../config", __FILE__), CONFIG_DIR) puts 'fluentd-server new finished.' end |
#start ⇒ Object
79 80 81 82 83 |
# File 'lib/fluentd_server/cli.rb', line 79 def start self.migrate # do migration before start not to forget on updation require "foreman/cli" Foreman::CLI.new.invoke(:start, [], {}) end |