is_master 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/LICENSE +1 -1
- data/README.md +6 -2
- data/VERSION +1 -1
- data/bin/is_master +23 -5
- data/test/test_cli.rb +20 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95addbb0d7882dea2b0c89407e2eafcaac273db9
|
4
|
+
data.tar.gz: 29930f30a84441d6dd17b07c535c1c3e3fd69b8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 613d77a498bbaaec34a570cdce9e1c0a7c1962599cf8d13d78c50d7088e09f5fc991d53f9227f5860120b0f90075ffd590519cd962742c758b9238300ba3f468
|
7
|
+
data.tar.gz: 7ceb81a73cd6aca6df41351f0fc5be554d24b33d04b5cd2f44c9c22c845e60fcf9a43d9df06f60e5b17c3fd3a85de6dfb7f153364370ade53eb55f9e4401c60c
|
data/CHANGELOG.md
ADDED
data/LICENSE
CHANGED
@@ -186,7 +186,7 @@
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
187
187
|
identification within third-party archives.
|
188
188
|
|
189
|
-
Copyright
|
189
|
+
Copyright 2017 Adrien Waksberg
|
190
190
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
192
192
|
you may not use this file except in compliance with the License.
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# is_master
|
2
|
-
[](https://github.com/nishiki/is_master/releases)
|
3
3
|
[](https://travis-ci.org/nishiki/is_master)
|
4
4
|
[](https://github.com/nishiki/is_master/blob/master/LICENSE)
|
5
5
|
|
6
|
-
is_master execute a command when
|
6
|
+
is_master execute a command when on the machine there is the expected vip or file.
|
7
7
|
|
8
8
|
## Install
|
9
9
|
|
@@ -19,6 +19,10 @@ It's simple:
|
|
19
19
|
```
|
20
20
|
is_master 10.0.254.2 ls -l
|
21
21
|
```
|
22
|
+
or
|
23
|
+
```
|
24
|
+
is_master /path/to/file ls -l
|
25
|
+
```
|
22
26
|
|
23
27
|
## Development
|
24
28
|
### Test on local machine with docker
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/bin/is_master
CHANGED
@@ -1,18 +1,36 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
4
|
+
# distributed with this work for additional information
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
7
|
+
# "License"); you may not use this file except in compliance
|
8
|
+
# with the License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
13
|
+
# software distributed under the License is distributed on an
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
# KIND, either express or implied. See the License for the
|
16
|
+
# specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
|
2
19
|
require 'socket'
|
3
20
|
|
4
21
|
if ARGV.length < 2
|
5
22
|
puts 'is_master execute a command when it determine that server is master'
|
6
|
-
puts "Usage: #{$PROGRAM_NAME} VIP COMMAND"
|
7
|
-
puts ' VIP
|
23
|
+
puts "Usage: #{$PROGRAM_NAME} [VIP|FILE] COMMAND"
|
24
|
+
puts ' VIP - IP address expected to be master'
|
25
|
+
puts ' FILE - File expected to be master'
|
8
26
|
puts ' COMMAND - Command to execute if host is master'
|
9
27
|
exit 2
|
10
28
|
end
|
11
29
|
|
12
|
-
|
13
|
-
command
|
30
|
+
expected = ARGV[0]
|
31
|
+
command = ARGV[1..-1].join(' ')
|
14
32
|
|
15
|
-
if Socket.ip_address_list.map(&:ip_address).include?(
|
33
|
+
if Socket.ip_address_list.map(&:ip_address).include?(expected) || File.exist?(expected)
|
16
34
|
Kernel.exec(command)
|
17
35
|
else
|
18
36
|
puts 'OK - I am slave, i going to sleep'
|
data/test/test_cli.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
|
3
3
|
class TestCli < Test::Unit::TestCase
|
4
|
+
def test_missing_arg
|
5
|
+
output = %x(is_master 127.0.0.1)
|
6
|
+
assert_match('Usage: ', output)
|
7
|
+
|
8
|
+
output = %x(is_master)
|
9
|
+
assert_match('Usage: ', output)
|
10
|
+
end
|
11
|
+
|
4
12
|
def test_slave_mode
|
5
13
|
output = %x(is_master 10.255.255.0 echo 'GOOD!')
|
6
14
|
assert_match('I am slave', output)
|
@@ -10,4 +18,16 @@ class TestCli < Test::Unit::TestCase
|
|
10
18
|
output = %x(is_master 127.0.0.1 echo 'GOOD!')
|
11
19
|
assert_match('GOOD!', output)
|
12
20
|
end
|
21
|
+
|
22
|
+
def test_file_slave_mode
|
23
|
+
output = %x(is_master /tmp/test.txt echo 'GOOD!')
|
24
|
+
assert_match('I am slave', output)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_file_master_mode
|
28
|
+
File.write('/tmp/test.txt', '')
|
29
|
+
output = %x(is_master /tmp/test.txt echo 'GOOD!')
|
30
|
+
assert_match('GOOD!', output)
|
31
|
+
File.unlink('/tmp/test.txt')
|
32
|
+
end
|
13
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: is_master
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrien Waksberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -22,6 +22,7 @@ files:
|
|
22
22
|
- ".gitignore"
|
23
23
|
- ".rubocop.yml"
|
24
24
|
- ".travis.yml"
|
25
|
+
- CHANGELOG.md
|
25
26
|
- Dockerfile
|
26
27
|
- Gemfile
|
27
28
|
- LICENSE
|