mirror of
https://github.com/nishiki/is_master.git
synced 2025-02-21 13:50:05 +00:00
feat: add exepected file option
This commit is contained in:
parent
fb275120e4
commit
ef526273a4
5 changed files with 40 additions and 13 deletions
10
CHANGELOG.md
Normal file
10
CHANGELOG.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# CHANGELOG
|
||||
## 1.1.0 (2017-12-15)
|
||||
|
||||
* add expected file option
|
||||
* add changelog
|
||||
* fix copyright in LICENSE file
|
||||
|
||||
## 1.0.0 (2017-11-09)
|
||||
|
||||
* first version
|
|
@ -1,9 +1,9 @@
|
|||
# is_master
|
||||
[](https://github.com/nishiki/is_master/releases)
|
||||
[](https://github.com/nishiki/is_master/releases)
|
||||
[](https://travis-ci.org/nishiki/is_master)
|
||||
[](https://github.com/nishiki/is_master/blob/master/LICENSE)
|
||||
|
||||
is_master execute a command when it determine that server is master
|
||||
is_master execute a command when on the machine there is the expected vip or file.
|
||||
|
||||
## Install
|
||||
|
||||
|
@ -19,6 +19,10 @@ It's simple:
|
|||
```
|
||||
is_master 10.0.254.2 ls -l
|
||||
```
|
||||
or
|
||||
```
|
||||
is_master /path/to/file ls -l
|
||||
```
|
||||
|
||||
## Development
|
||||
### Test on local machine with docker
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
1.0.0
|
||||
1.1.0
|
||||
|
|
|
@ -20,16 +20,17 @@ require 'socket'
|
|||
|
||||
if ARGV.length < 2
|
||||
puts 'is_master execute a command when it determine that server is master'
|
||||
puts "Usage: #{$PROGRAM_NAME} VIP COMMAND"
|
||||
puts ' VIP - IP address expected to be master'
|
||||
puts "Usage: #{$PROGRAM_NAME} [VIP|FILE] COMMAND"
|
||||
puts ' VIP - IP address expected to be master'
|
||||
puts ' FILE - File expected to be master'
|
||||
puts ' COMMAND - Command to execute if host is master'
|
||||
exit 2
|
||||
end
|
||||
|
||||
vip = ARGV[0]
|
||||
command = ARGV[1..-1].join(' ')
|
||||
expected = ARGV[0]
|
||||
command = ARGV[1..-1].join(' ')
|
||||
|
||||
if Socket.ip_address_list.map(&:ip_address).include?(vip)
|
||||
if Socket.ip_address_list.map(&:ip_address).include?(expected) || File.exist?(expected)
|
||||
Kernel.exec(command)
|
||||
else
|
||||
puts 'OK - I am slave, i going to sleep'
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
require 'test/unit'
|
||||
|
||||
class TestCli < Test::Unit::TestCase
|
||||
def test_missing_arg
|
||||
output = %x(is_master 127.0.0.1)
|
||||
assert_match('Usage: ', output)
|
||||
|
||||
output = %x(is_master)
|
||||
assert_match('Usage: ', output)
|
||||
end
|
||||
|
||||
def test_slave_mode
|
||||
output = %x(is_master 10.255.255.0 echo 'GOOD!')
|
||||
assert_match('I am slave', output)
|
||||
|
@ -11,11 +19,15 @@ class TestCli < Test::Unit::TestCase
|
|||
assert_match('GOOD!', output)
|
||||
end
|
||||
|
||||
def test_missing_arg
|
||||
output = %x(is_master 127.0.0.1)
|
||||
assert_match('Usage: ', output)
|
||||
def test_file_slave_mode
|
||||
output = %x(is_master /tmp/test.txt echo 'GOOD!')
|
||||
assert_match('I am slave', output)
|
||||
end
|
||||
|
||||
output = %x(is_master)
|
||||
assert_match('Usage: ', output)
|
||||
def test_file_master_mode
|
||||
File.write('/tmp/test.txt', '')
|
||||
output = %x(is_master /tmp/test.txt echo 'GOOD!')
|
||||
assert_match('GOOD!', output)
|
||||
File.unlink('/tmp/test.txt')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue