nfs-server.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # -*- coding: utf-8 -*-
  2. from comar.service import *
  3. from pardus import fstabutils
  4. import signal
  5. import os
  6. serviceType = "server"
  7. serviceDesc = _({"en": "NFS Server",
  8. "tr": "NFS Sunucusu"})
  9. serviceConf = "nfs"
  10. ERR_INSMOD = _({"en": "Failed probing module %s",
  11. "tr": "%s modülü yüklenemedi",
  12. })
  13. PROCNFSD_MOUNTPOINT = "/proc/fs/nfsd"
  14. RQUOTAD_PATH = "/usr/sbin/rpc.rquotad"
  15. IDMAPD_PIDFILE = "/run/rpc.idmapd.pid"
  16. SVCGSSD_PIDFILE = "/run/rpc.svcgssd.pid"
  17. RQUOTAD_PIDFILE = "/run/rpc.rquotad.pid"
  18. MOUNTD_PIDFILE = "/run/rpc.mountd.pid"
  19. # Parse the fstab file and determine whether we need quotad or not by searching
  20. # mount option quota in any mount entry.
  21. # If none, nfs conf.d file decides if it's needed.
  22. def need_quotad():
  23. fstab = fstabutils.Fstab()
  24. for entry in fstab.get_entries():
  25. if "quota" in entry.get_fs_mntopts():
  26. return True
  27. @synchronized
  28. def start():
  29. startDependencies("nfs_common")
  30. if run("/sbin/modprobe -q nfsd"):
  31. fail(ERR_INSMOD % "nfsd")
  32. # Check if PROCNFSD_MOUNTPOINT is mounted
  33. if run("/bin/mountpoint -q %s" % PROCNFSD_MOUNTPOINT):
  34. run("/bin/mount -t nfsd nfsd %s" % PROCNFSD_MOUNTPOINT)
  35. run("/usr/sbin/exportfs -r")
  36. # If RPCNFSDCOUNT is not explicitly defined in confd, use default one, 8 threads.
  37. startService(command="/usr/sbin/rpc.nfsd",
  38. args="%s %s" % (config.get("RPCNFSD_OPTIONS", ""), config.get("RPCNFSDCOUNT", "8")),
  39. donotify=True)
  40. if config.get("NEED_SVCGSSD", "no") == "yes":
  41. startService(command="/usr/sbin/rpc.svcgssd",
  42. args="-f %s" % config.get("RPCSVCGSSD_OPTIONS", ""),
  43. donotify=True,
  44. detach=True,
  45. makepid=True,
  46. pidfile=SVCGSSD_PIDFILE)
  47. # Start rpc.rquotad daemon here if its available
  48. if (config.get("NEED_QUOTAD", "no") == "yes" or need_quotad()) and os.path.exists(RQUOTAD_PATH):
  49. RPCRQUOTAD_OPTIONS = config.get("RPCRQUOTAD_OPTIONS", "")
  50. RQUOTAD_PORT = config.get("RQUOTAD_PORT")
  51. if RQUOTAD_PORT:
  52. RPCRQUOTAD_OPTIONS += " -p %s" % RQUOTAD_PORT
  53. startService(command=RQUOTAD_PATH,
  54. args="-F %s" % RPCRQUOTAD_OPTIONS,
  55. donotify=True,
  56. detach=True,
  57. makepid=True,
  58. pidfile=RQUOTAD_PIDFILE)
  59. # Reload rpc.idmapd
  60. if os.path.exists(IDMAPD_PIDFILE):
  61. os.kill(int(file(IDMAPD_PIDFILE).read().strip()), signal.SIGHUP)
  62. RPCMOUNTD_OPTIONS = config.get("RPCMOUNTD_OPTIONS", "")
  63. MOUNTD_PORT = config.get("MOUNTD_PORT")
  64. if MOUNTD_PORT:
  65. RPCMOUNTD_OPTIONS += " -p %s" % MOUNTD_PORT
  66. startService(command="/usr/sbin/rpc.mountd",
  67. args="-F %s" % RPCMOUNTD_OPTIONS,
  68. donotify=True,
  69. detach=True,
  70. makepid=True,
  71. pidfile=MOUNTD_PIDFILE)
  72. @synchronized
  73. def stop():
  74. stopService(pidfile=MOUNTD_PIDFILE,
  75. donotify=True)
  76. if os.path.exists(MOUNTD_PIDFILE):
  77. os.unlink(MOUNTD_PIDFILE)
  78. stopService(pidfile=SVCGSSD_PIDFILE,
  79. donotify=True)
  80. if os.path.exists(SVCGSSD_PIDFILE):
  81. os.unlink(SVCGSSD_PIDFILE)
  82. stopService(pidfile=RQUOTAD_PIDFILE,
  83. donotify=True)
  84. if os.path.exists(RQUOTAD_PIDFILE):
  85. os.unlink(RQUOTAD_PIDFILE)
  86. stopService(command="/usr/sbin/rpc.nfsd",
  87. args="0",
  88. donotify=True)
  89. # Unexport all exported directories
  90. run("/usr/sbin/exportfs -au")
  91. if not run("/bin/mountpoint -q %s" % PROCNFSD_MOUNTPOINT):
  92. run("/usr/sbin/exportfs -f %s" % PROCNFSD_MOUNTPOINT)
  93. def reload():
  94. # Re-export all exported directories
  95. run("/usr/sbin/exportfs -r")
  96. def status():
  97. # ugly way of learning if the daemon is up and running.
  98. result = not run("/sbin/pidof nfsd") and isServiceRunning(MOUNTD_PIDFILE)
  99. if config.get("NEED_SVCGSSD", "no") == "yes":
  100. result = result and isServiceRunning(SVCGSSD_PIDFILE)
  101. if (config.get("NEED_QUOTAD", "no") == "yes" or need_quotad()) and os.path.exists(RQUOTAD_PATH):
  102. result = result and isServiceRunning(RQUOTAD_PIDFILE)
  103. return result