Class: Nutella::Tmux
- Inherits:
-
Object
- Object
- Nutella::Tmux
- Defined in:
- lib/tmux/tmux.rb
Class Method Summary collapse
-
.app_bot_session_name(app_id) ⇒ Object
Builds a session name for an app-level session.
-
.kill_app_session(app_id) ⇒ Object
Removes the app-level session associated to a particular application.
-
.kill_run_session(app_id, run_id) ⇒ Object
Removes a run-level session associated to a particular run.
-
.session_exist?(session_id) ⇒ Boolean
Returns true if a tmux session with a certain id exists.
-
.session_name(app_id, run_id) ⇒ Object
Builds a session name for run-level session.
Instance Method Summary collapse
-
#initialize(app_id, run_id) ⇒ Tmux
constructor
A new instance of Tmux.
-
#new_app_bot_window(bot) ⇒ Object
Creates a new window (and session if necessary) to start an app-level bot.
-
#new_bot_window(bot) ⇒ Object
Creates a new window (and session if necessary) to start a run-level bot.
Constructor Details
#initialize(app_id, run_id) ⇒ Tmux
Returns a new instance of Tmux.
5 6 7 8 |
# File 'lib/tmux/tmux.rb', line 5 def initialize( app_id, run_id ) @app_id = app_id @run_id = run_id end |
Class Method Details
.app_bot_session_name(app_id) ⇒ Object
Builds a session name for an app-level session
51 52 53 |
# File 'lib/tmux/tmux.rb', line 51 def self.app_bot_session_name( app_id ) "#{app_id}-app-bots" end |
.kill_app_session(app_id) ⇒ Object
Removes the app-level session associated to a particular application
36 37 38 |
# File 'lib/tmux/tmux.rb', line 36 def self.kill_app_session( app_id ) `tmux kill-session -t #{app_bot_session_name( app_id )} > /dev/null 2>&1` end |
.kill_run_session(app_id, run_id) ⇒ Object
Removes a run-level session associated to a particular run
31 32 33 |
# File 'lib/tmux/tmux.rb', line 31 def self.kill_run_session( app_id, run_id ) `tmux kill-session -t #{session_name(app_id, run_id)} > /dev/null 2>&1` end |
.session_exist?(session_id) ⇒ Boolean
Returns true if a tmux session with a certain id exists
41 42 43 |
# File 'lib/tmux/tmux.rb', line 41 def self.session_exist?( session_id ) system( "tmux has-session -t #{session_id} > /dev/null 2>&1" ) end |
.session_name(app_id, run_id) ⇒ Object
Builds a session name for run-level session
46 47 48 |
# File 'lib/tmux/tmux.rb', line 46 def self.session_name( app_id, run_id ) "#{app_id}/#{run_id}" end |
Instance Method Details
#new_app_bot_window(bot) ⇒ Object
Creates a new window (and session if necessary) to start an app-level bot
21 22 23 24 25 26 27 28 |
# File 'lib/tmux/tmux.rb', line 21 def new_app_bot_window( bot ) # Create session name sn = Tmux.app_bot_session_name(@app_id) # Create session create_tmux_window(sn, bot) # Start bot `tmux send-keys "cd bots/#{bot};./startup #{Nutella.config['broker']} #{@app_id}" C-m` end |
#new_bot_window(bot) ⇒ Object
Creates a new window (and session if necessary) to start a run-level bot
11 12 13 14 15 16 17 18 |
# File 'lib/tmux/tmux.rb', line 11 def new_bot_window( bot ) # Create session name sn = Tmux.session_name(@app_id, @run_id) # Create session create_tmux_window(sn, bot) # Start bot `tmux send-keys "cd bots/#{bot};./startup #{Nutella.config['broker']} #{@app_id} #{@run_id}" C-m` end |