commit message from python script

This commit is contained in:
2023-09-15 10:21:13 +02:00
parent bbf01b7123
commit 04999bb97b

View File

@@ -8,26 +8,31 @@ class nfs_server_conf:
raise PermissionError("Sie sind kein Root")
self.nfs_srv_folders = nfs_srv_folders
def create_serverfolder(self):
def mount_serverfolder(self):
for srv_folder in self.nfs_srv_folders:
unit_mount_file = "/etc/systemd/system/" + os.path.basename(srv_folder) + ".mount"
mountfile = os.path.basename(unit_mount_file)
if os.path.exists(srv_folder):
print(srv_folder,"ist bereits vorhanden !")
print("Das Verzeichnis", srv_folder,"ist bereits vorhanden !")
else:
os.makedirs(srv_folder, mode=1777)
def mount_serverfolder(self):
for srv_folder in self.nfs_srv_folders:
with open("/etc/systemd/system/" + os.path.basename(srv_folder) + ".mount", "w") as unit_file:
if os.path.exists(unit_mount_file) is True:
print("Die Unit", unit_mount_file, "existiert bereits !", sep=" ")
else:
with open(unit_mount_file, "w") as unit_file:
print("""[Unit]\nDescription=Mount nfs Server Share\n[Mount]\nWhat={srv_folder}\nWhere={srv_point}\nType=None\nOptions=bind\n[Install]\nWantedBy=multi-user.target""".format(
srv_folder=srv_folder,
srv_point="/" + os.path.basename(srv_folder)), file=unit_file)
try:
mountfile = os.path.basename(srv_folder) + ".mount"
subprocess.run(['systemctl', 'daemon-reload'])
print(mountfile)
#subprocess.run('systemctl start ')
subprocess.Popen('systemctl start ' + mountfile, shell=True)
except SystemError:
if subprocess.run(['systemctl', 'daemon-reload']) .returncode == 0:
print("Systemed daemon-reload wurde ausgeführt")
else:
raise "Reloade konnte nicht ausgeführt werden."
#Starte UnitFile
if subprocess.run(['systemctl', 'start', mountfile]).returncode == 0:
print(mountfile, "wurde gestartet !", sep=" ")
else:
raise "Service " + unit_file + " konnte nicht gestart werden"
@@ -41,8 +46,6 @@ class nfs_server_conf:
pass
def main(self):
print("Erstelle Server Verzeichnise : ")
nfs_server_conf.create_serverfolder(self)
nfs_server_conf.mount_serverfolder(self)
def __str__(self) -> str: