mirror of
https://gitlab.crans.org/nounous/keepalived.git
synced 2024-12-22 02:00:09 +01:00
Scripts for keepalive to start and stop service
This commit is contained in:
commit
9c4ce6f114
2 changed files with 47 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
keepalived.json
|
46
keepalived.py
Executable file
46
keepalived.py
Executable file
|
@ -0,0 +1,46 @@
|
|||
#!/bin/env python3
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from enum import Enum
|
||||
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
class Type(Enum):
|
||||
GROUP = 'GROUP'
|
||||
INSTANCE = 'INSTANCE'
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
||||
class State(Enum):
|
||||
MASTER = 'MASTER'
|
||||
BACKUP = 'BACKUP'
|
||||
FAULT = 'FAULT'
|
||||
STOP = 'STOP'
|
||||
DELETED = 'DELETED'
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
||||
def handling(state):
|
||||
if state == State.MASTER:
|
||||
return 'start'
|
||||
else:
|
||||
return 'stop'
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Start and stop service on keepalived switch')
|
||||
parser.add_argument('TYPE', type=Type, choices=list(Type))
|
||||
parser.add_argument('NAME', type=str)
|
||||
parser.add_argument('STATE', type=State, choices=list(State))
|
||||
parser.add_argument('PRIORITY', type=int)
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(os.path.join(path, "keepalived.json")) as config_file:
|
||||
config = json.load(config_file)
|
||||
|
||||
for service in config['services'][args.NAME]:
|
||||
subprocess.run(['systemctl', handling(args.STATE), service])
|
Loading…
Reference in a new issue