forked from davewinwood/octolux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.rb
executable file
·36 lines (30 loc) · 986 Bytes
/
server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env ruby
# frozen_string_literal: true
require_relative 'boot'
# change directory to where octolux.rb lives; this lets us run from anywhere.
Dir.chdir(__dir__)
require 'rack'
# connect to MQTT if configured
Thread.new { MQ.run } if CONFIG['mqtt']['uri']
# start a background thread which will listen for inverter packets
# in itself, this is wrapped in another thread to try and address
# reports of MQ stopping being updated. Unable to reproduce atm so
# this is a bodge.
Thread.new do
loop do
t = Thread.new do
begin
LuxListener.run
rescue StandardError => e
LOGGER.error "LuxListener Thread: #{e}"
LOGGER.debug e.backtrace.join("\n")
end
end
t.join
LOGGER.info 'Restarting LuxListener Thread in 5 seconds'
sleep 5
end
end
Rack::Server.start(Host: CONFIG['server']['listen_host'] || CONFIG['server']['host'],
Port: CONFIG['server']['port'],
app: App.freeze.app)