first commit

This commit is contained in:
cclecle
2022-12-12 16:19:51 +00:00
commit 87933ef766
4 changed files with 87 additions and 0 deletions

1
Readme.md Normal file
View File

@@ -0,0 +1 @@
A simple Systemd Daemon writen in python that automatically (force) start your glusterfs volume when all bricks become online again.

View 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")

View 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

View 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