Skip to content

Commit 1e920c9

Browse files
committed
Started implementing new server command
1 parent bfca4d7 commit 1e920c9

27 files changed

+333
-301
lines changed

lib/cli/cli.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative 'cli_utils'
2+
# Require all the commands
23
Dir["#{File.dirname(__FILE__)}/commands/*.rb"].each do |file|
34
require_relative "commands/#{File.basename(file, File.extname(file))}"
45
end

lib/cli/commands/checkup.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative 'meta/command'
2+
require 'config/config'
23
require 'semantic'
34

45
module Nutella
@@ -23,7 +24,7 @@ def run( args=nil )
2324
end
2425

2526
# Set ready flag in config.json
26-
Nutella.config['ready'] = true
27+
Config.file['ready'] = true
2728

2829
# Output success message
2930
console.success 'All systems go! You are ready to use nutella!'
@@ -37,7 +38,7 @@ def broker_exists
3738
# Check if Docker image for the broker was already pulled
3839
if `docker images matteocollina/mosca:v2.3.0 --format "{{.ID}}"` != ""
3940
# If so, check that a broker configuration exists and create one if it doesn't
40-
Nutella.config['broker'] = '127.0.0.1' if Nutella.config['broker'].nil?
41+
Config.file['broker'] = '127.0.0.1' if Config.file['broker'].nil?
4142
true
4243
else
4344
false
@@ -49,7 +50,7 @@ def install_local_broker
4950
# Docker pull to install
5051
system "docker pull matteocollina/mosca:v2.3.0 > /dev/null 2>&1"
5152
# Write broker setting inside config.json
52-
Nutella.config['broker'] = '127.0.0.1'
53+
Config.file['broker'] = '127.0.0.1'
5354
end
5455

5556

@@ -72,11 +73,11 @@ def all_dependencies_installed?
7273
end
7374
semver
7475
end
75-
# Tmux version lambda
76-
tmux_semver = lambda do
77-
out = `tmux -V`
78-
out.slice!(0,5)
79-
Semantic::Version.new "#{out[0..2]}.0"
76+
# Immortal version lambda
77+
immortal_semver = lambda do
78+
out = `immortal -v`
79+
out.gsub("\n",'')
80+
Semantic::Version.new out
8081
end
8182
# Mongo version lambda
8283
mongo_semver = lambda do
@@ -85,7 +86,7 @@ def all_dependencies_installed?
8586
Semantic::Version.new out[0..4]
8687
end
8788
# Check versions
88-
return true if check_version?('docker', '17.0.0', docker_semver) && check_version?('git', '1.8.0', git_semver) && check_version?('tmux', '1.8.0', tmux_semver) && check_version?('mongodb', '2.6.9', mongo_semver)
89+
return true if check_version?('docker', '17.0.0', docker_semver) && check_version?('git', '1.8.0', git_semver) && check_version?('immortal', '0.23.0', immortal_semver) && check_version?('mongodb', '2.6.9', mongo_semver)
8990
# If even one of the checks fails, return false
9091
false
9192
end

lib/cli/commands/compile.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require_relative 'meta/run_command'
2-
require 'tmux/tmux'
32

43
module Nutella
54
class Compile < RunCommand

lib/cli/commands/dependencies.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require_relative 'meta/run_command'
2-
require 'tmux/tmux'
32

43
module Nutella
54
class Dependencies < RunCommand

lib/cli/commands/meta/command.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
module Nutella
42

53
# Nutella command

lib/cli/commands/meta/run_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require_relative 'command'
2-
require_relative '../util/components_list'
2+
require 'util/components_list'
33
require 'slop'
44

55
module Nutella

lib/cli/commands/server.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require_relative 'meta/command'
2+
require 'util/mqtt_broker'
3+
require 'util/mongo'
4+
require 'util/framework_components_starter'
5+
6+
module Nutella
7+
class Server < RunCommand
8+
@description = 'Starts the MQTT broker and the framework level bots'
9+
10+
def run(args=nil)
11+
if MQTTBroker.start
12+
console.success('MQTT broker started')
13+
else
14+
console.error('Failed to start MQTT broker')
15+
end
16+
if Mongo.start
17+
console.success('Mongo started')
18+
else
19+
console.error('Failed to start Mongo')
20+
end
21+
if FrameworkComponentsStarter.start
22+
console.success('Framework level components started')
23+
else
24+
console.error('Failed to start Framework level components')
25+
end
26+
end
27+
end
28+
29+
end

lib/cli/commands/start.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require_relative 'meta/run_command'
2-
require_relative 'util/components_starter'
2+
# require 'util/components_starter'
33

44
module Nutella
55
class Start < RunCommand

lib/cli/commands/stop.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require_relative 'meta/run_command'
2-
require 'tmux/tmux'
32

43
module Nutella
54
class Stop < RunCommand

lib/cli/commands/util/components_starter.rb

Lines changed: 0 additions & 204 deletions
This file was deleted.

lib/config_files_management/config.rb renamed to lib/config/config.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
require 'config_files_management/persisted_hash'
1+
require_relative 'persisted_hash'
22

33
module Nutella
44
class Config
55
# This method initializes the nutella configuration file (config.json) with:
66
# - config_dir: directory where the configuration files are stored in
77
# - broker_dir: directory where the local broker is installed in
8+
# - immortal_dir: directory used to store immortal yaml files
89
# - main_interface_port: the port used to serve interfaces
910
def self.init
1011
file['config_dir'] = "#{ENV['HOME']}/.nutella/"
@@ -18,4 +19,4 @@ def self.file
1819
PersistedHash.new( "#{ENV['HOME']}/.nutella/config.json" )
1920
end
2021
end
21-
end
22+
end
File renamed without changes.

0 commit comments

Comments
 (0)