Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add daemon_spawn #2

Merged
merged 1 commit into from

1 participant

Atsuo Fukaya
Atsuo Fukaya
Owner

No description provided.

Atsuo Fukaya fukayatsu merged commit 18b0237 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 22, 2014
  1. Add daemon_spawn

    authored
This page is out of date. Refresh to see the latest.
5 rpi/.gitignore
View
@@ -1,2 +1,5 @@
.bundle
-.env
+.env
+tmp/
+log/
+
2  rpi/Gemfile
View
@@ -8,3 +8,5 @@ gem 'aws-sdk'
gem 'whenever'
gem 'rake'
gem 'iremocon'
+gem 'daemon-spawn'
+
2  rpi/Gemfile.lock
View
@@ -19,6 +19,7 @@ GEM
uuidtools (~> 2.1)
chronic (0.10.2)
coderay (1.1.0)
+ daemon-spawn (0.4.2)
dotenv (0.9.0)
extlib (0.9.16)
faraday (0.9.0)
@@ -74,6 +75,7 @@ PLATFORMS
DEPENDENCIES
activesupport
aws-sdk
+ daemon-spawn
dotenv
google-api-client
iremocon
6 rpi/Rakefile
View
@@ -8,9 +8,3 @@ namespace :calendar do
end
end
-namespace :manager do
- desc 'start manager'
- task :start do
- ElectronicsManager.new.start
- end
-end
22 rpi/electronics_manager.rb
View
@@ -1,15 +1,16 @@
require 'yaml'
require 'iremocon'
+require 'daemon_spawn'
+require 'aws-sdk'
+require 'dotenv'; Dotenv.load!
+require 'active_support/all'
-class ElectronicsManager
- def initialize
+class ElectronicsManager < DaemonSpawn::Base
+ def start(args)
@settings = YAML.load_file('settings.yml')
@iremocon = Iremocon.new(@settings['iremocon']['address'])
- end
- def start
puts 'start manager'
- Process.daemon
loop do
queue.poll(idle_timeout: 60) do |message|
ray_number = commands[message.body]
@@ -24,6 +25,9 @@ def start
end
end
+ def stop
+ end
+
private
def commands
@@ -38,3 +42,11 @@ def queue
).queues[ENV['SQS_URL']]
end
end
+
+ElectronicsManager.spawn!({
+ working_dir: __dir__,
+ pid_file: File.expand_path(__dir__ + '/tmp/manager.pid'),
+ log_file: File.expand_path(__dir__ + '/log/manager.log'),
+ sync_log: true,
+ singleton: true
+})
0  rpi/log/.gitkeep
View
No changes.
0  rpi/tmp/.gitkeep
View
No changes.
Something went wrong with that request. Please try again.