53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
#! /usr/bin/env python3
|
|
|
|
import os, sys, subprocess
|
|
|
|
class nfs_server_conf:
|
|
def __init__(self, nfs_srv_folders = ["/nfsroot/publicnfs","/nfsroot/datennfs"]) -> None:
|
|
if not os.geteuid()==0:
|
|
raise PermissionError("Sie sind kein Root")
|
|
self.nfs_srv_folders = nfs_srv_folders
|
|
|
|
def create_serverfolder(self):
|
|
for srv_folder in self.nfs_srv_folders:
|
|
if os.path.exists(srv_folder):
|
|
print(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:
|
|
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:
|
|
raise "Service " + unit_file + " konnte nicht gestart werden"
|
|
|
|
|
|
def nfs_server_conf(self):
|
|
pass
|
|
|
|
def nfs_con_user(self):
|
|
pass
|
|
|
|
def start_nfs_server(self):
|
|
pass
|
|
|
|
def main(self):
|
|
print("Erstelle Server Verzeichnise : ")
|
|
nfs_server_conf.create_serverfolder(self)
|
|
nfs_server_conf.mount_serverfolder(self)
|
|
|
|
def __str__(self) -> str:
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
my_nfs_server = nfs_server_conf()
|
|
my_nfs_server.main() |