first commit
This commit is contained in:
1
Readme.md
Normal file
1
Readme.md
Normal file
@@ -0,0 +1 @@
|
||||
A simple Systemd Daemon writen in python that automatically (force) start your glusterfs volume when all bricks become online again.
|
||||
64
pyAutoReupGlusterVolume.py
Normal file
64
pyAutoReupGlusterVolume.py
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
if __name__=="__main__":
|
||||
AllVolumes = dict()
|
||||
failedVolume = dict()
|
||||
my_env = os.environ.copy()
|
||||
res=subprocess.run("gluster volume status --xml",shell=True,capture_output=True,universal_newlines=True,env=my_env)
|
||||
root = ET.fromstring(res.stdout)
|
||||
for volume in root.iter('volume'):
|
||||
VolumeName = volume.find('volName').text
|
||||
AllVolumes[VolumeName]=dict()
|
||||
AllVolumes[VolumeName]["nodes"] = dict()
|
||||
for node in volume.findall('node'):
|
||||
NodeName = node.find('hostname').text
|
||||
Path = node.find('path').text
|
||||
Port = node.find('port').text
|
||||
Status = node.find('status').text
|
||||
pid = node.find('pid').text
|
||||
AllVolumes[VolumeName]["nodes"][NodeName] = dict()
|
||||
AllVolumes[VolumeName]["nodes"][NodeName]['Path'] = Path
|
||||
AllVolumes[VolumeName]["nodes"][NodeName]['Port'] = Port
|
||||
AllVolumes[VolumeName]["nodes"][NodeName]['Status'] = Status
|
||||
AllVolumes[VolumeName]["nodes"][NodeName]['pid'] = pid
|
||||
if NodeName == "Self-heal Daemon":
|
||||
continue
|
||||
elif NodeName == "Quota Daemon":
|
||||
continue
|
||||
else:
|
||||
if int(Status)==0 or Port=="N/A":
|
||||
if not VolumeName in failedVolume:
|
||||
failedVolume[VolumeName]=[]
|
||||
failedVolume[VolumeName].append(NodeName)
|
||||
AllVolumes[VolumeName]["tasks"] = dict()
|
||||
for task in volume.findall('task'):
|
||||
type = task.find('type').text
|
||||
id = task.find('id').text
|
||||
status = task.find('status').text
|
||||
statusStr = task.find('statusStr').text
|
||||
AllVolumes[VolumeName]["tasks"]["type"] = type
|
||||
AllVolumes[VolumeName]["tasks"]["id"] = id
|
||||
AllVolumes[VolumeName]["tasks"]["status"] = status
|
||||
AllVolumes[VolumeName]["tasks"]["statusStr"] = statusStr
|
||||
|
||||
print("All Volumes:")
|
||||
print(AllVolumes)
|
||||
|
||||
print("Failed Nodes:")
|
||||
print(failedVolume)
|
||||
|
||||
for _Volume,_Nodes in failedVolume.items():
|
||||
Pass=True
|
||||
for Node in _Nodes:
|
||||
if subprocess.call(["ping","-q","-c","2",Node]) != 0:
|
||||
Pass=False
|
||||
if Pass==True:
|
||||
print(f" Volume {_Volume} seems online again, force restart")
|
||||
subprocess.call(["gluster","volume","start",_Volume,"force"])
|
||||
|
||||
print("Finished")
|
||||
10
pyAutoReupGlusterVolume.service
Normal file
10
pyAutoReupGlusterVolume.service
Normal file
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Automatic GlusterFs Volume restart
|
||||
Wants=pyAutoReupGlusterVolume.timer
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/opt/chacha/pyAutoReupGlusterVolume.py
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
12
pyAutoReupGlusterVolume.timer
Normal file
12
pyAutoReupGlusterVolume.timer
Normal file
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Automatic GlusterFs Volume restart
|
||||
Requires=pyAutoReupGlusterVolume.service
|
||||
|
||||
[Timer]
|
||||
Unit=pyAutoReupGlusterVolume.service
|
||||
OnBootSec=1min
|
||||
OnUnitActiveSec=30s
|
||||
AccuracySec=1s
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Reference in New Issue
Block a user