Class: Cinchize::Cinchize

Inherits:
Object
  • Object
show all
Defined in:
lib/cinchize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, network, plugins, plugin_options) ⇒ Cinchize

Returns a new instance of Cinchize.



129
130
131
132
133
134
# File 'lib/cinchize.rb', line 129

def initialize options, network, plugins, plugin_options
  @network = network
  @plugins = plugins      
  @plugin_options = plugin_options
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



127
128
129
# File 'lib/cinchize.rb', line 127

def options
  @options
end

Instance Method Details

#app_nameObject



136
137
138
# File 'lib/cinchize.rb', line 136

def app_name
  options[:app_name]
end

#clean_app_nameObject



144
145
146
# File 'lib/cinchize.rb', line 144

def clean_app_name
  app_name.split('_', 2).last
end

#dirObject



140
141
142
# File 'lib/cinchize.rb', line 140

def dir
  options[:dir]
end

#restartObject



148
149
150
151
# File 'lib/cinchize.rb', line 148

def restart
  stop
  start
end

#running?Boolean

Returns:

  • (Boolean)


207
208
209
210
211
212
213
# File 'lib/cinchize.rb', line 207

def running? 
  pidfile = Daemons::PidFile.new dir, app_name
  return false if pidfile.pid.nil?
  return Process.kill(0, pidfile.pid) != 0
rescue Errno::ESRCH => e
  return false
end

#startObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/cinchize.rb', line 153

def start 
  if running?
    raise ArgumentError.new "#{clean_app_name} is already running"      
  end

  puts "* starting #{clean_app_name}"

  daemon = Daemons::ApplicationGroup.new(app_name, {
    :ontop => options[:ontop],
    :dir => dir,
    :dir_mode => options[:dir_mode]
  })
  app = daemon.new_application :mode => :none, :log_output => options[:log_output]
  app.start

  network = @network
  plugins = @plugins
  plugin_options = @plugin_options

  loop do
    bot = Cinch::Bot.new do  
      configure do |c|
        network.each_pair { |key, value| c.send("#{key}=".to_sym, value) }

        c.plugins.plugins = plugins
        c.plugins.options = plugin_options
      end
    end

    bot.start
  end
end

#statusObject



199
200
201
202
203
204
205
# File 'lib/cinchize.rb', line 199

def status 
  if running?
    puts "* #{clean_app_name} is running"
  else
    puts "* #{clean_app_name} is not running"
  end
end

#stopObject



186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/cinchize.rb', line 186

def stop 
  unless running?
    puts "* #{clean_app_name} is not running"
    return
  end

  pidfile = Daemons::PidFile.new dir, app_name
  puts "* stopping #{clean_app_name}"

  Process.kill(9, pidfile.pid)
  File.delete(pidfile.filename)
end