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") raise PermissionError("Sie sind kein Root")
self.nfs_srv_folders = nfs_srv_folders self.nfs_srv_folders = nfs_srv_folders
def create_serverfolder(self): def mount_serverfolder(self):
for srv_folder in self.nfs_srv_folders: 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): if os.path.exists(srv_folder):
print(srv_folder,"ist bereits vorhanden !") print("Das Verzeichnis", srv_folder,"ist bereits vorhanden !")
else: else:
os.makedirs(srv_folder, mode=1777) os.makedirs(srv_folder, mode=1777)
def mount_serverfolder(self): if os.path.exists(unit_mount_file) is True:
for srv_folder in self.nfs_srv_folders: print("Die Unit", unit_mount_file, "existiert bereits !", sep=" ")
with open("/etc/systemd/system/" + os.path.basename(srv_folder) + ".mount", "w") as unit_file: 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( 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_folder=srv_folder,
srv_point="/" + os.path.basename(srv_folder)), file=unit_file) srv_point="/" + os.path.basename(srv_folder)), file=unit_file)
try: if subprocess.run(['systemctl', 'daemon-reload']) .returncode == 0:
mountfile = os.path.basename(srv_folder) + ".mount" print("Systemed daemon-reload wurde ausgeführt")
subprocess.run(['systemctl', 'daemon-reload']) else:
print(mountfile) raise "Reloade konnte nicht ausgeführt werden."
#subprocess.run('systemctl start ') #Starte UnitFile
subprocess.Popen('systemctl start ' + mountfile, shell=True) if subprocess.run(['systemctl', 'start', mountfile]).returncode == 0:
except SystemError: print(mountfile, "wurde gestartet !", sep=" ")
else:
raise "Service " + unit_file + " konnte nicht gestart werden" raise "Service " + unit_file + " konnte nicht gestart werden"
@@ -41,8 +46,6 @@ class nfs_server_conf:
pass pass
def main(self): def main(self):
print("Erstelle Server Verzeichnise : ")
nfs_server_conf.create_serverfolder(self)
nfs_server_conf.mount_serverfolder(self) nfs_server_conf.mount_serverfolder(self)
def __str__(self) -> str: def __str__(self) -> str: