mmode 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,23 +6,13 @@ module Mmode
6
6
  desc 'enable [USER]', 'Enable maintenance mode for given user'
7
7
 
8
8
  def enable(name)
9
- user = User.new(name)
10
- if user.exists?
11
- user.enable
12
- else
13
- puts 'User does not exist!'
14
- end
9
+ User.new(name).enable
15
10
  end
16
11
 
17
12
  desc 'disable [USER]', 'Disable maintenance mode for given user'
18
13
 
19
14
  def disable(name)
20
- user = User.new(name)
21
- if user.exists?
22
- user.disable
23
- else
24
- puts 'User does not exist!'
25
- end
15
+ User.new(name).disable
26
16
  end
27
17
  end
28
18
  end
@@ -9,16 +9,26 @@ module Mmode
9
9
  @name = name
10
10
  end
11
11
 
12
- def exists?
13
- File.exists? "/home/usr/#{@name}"
14
- end
15
-
16
12
  def enable
17
- `ssh scrcpt2.nine.ch 'touch /home/usr/screenconcept/maintenance.txt; sudo monit unmonitor -g thin_#{@name}'`
13
+ run_if_user_exists "touch /home/usr/screenconcept/maintenance.txt; sudo monit unmonitor -g thin_#{@name}"
18
14
  end
19
15
 
20
16
  def disable
21
- `ssh scrcpt2.nine.ch 'rm /home/usr/screenconcept/maintenance.txt; sudo monit monitor -g thin_#{@name}'`
17
+ run_if_user_exists "rm /home/usr/screenconcept/maintenance.txt; sudo monit monitor -g thin_#{@name}"
18
+ end
19
+
20
+ private
21
+
22
+ def homedir
23
+ "/home/usr/#{name}"
24
+ end
25
+
26
+ def run_if_user_exists(command)
27
+ `ssh scrcpt2.nine.ch "if [ -d '#{homedir}' ]; then #{command}; else echo #{error}; fi"`
28
+ end
29
+
30
+ def error
31
+ "User does not exist!"
22
32
  end
23
33
  end
24
34
  end
@@ -1,3 +1,3 @@
1
1
  module Mmode
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmode
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Felipe Kaufmann