nfs-common.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # -*- coding: utf-8 -*-
  2. from comar.service import *
  3. from pardus import fstabutils
  4. import os
  5. serviceType = "server"
  6. serviceDesc = _({"en": "NFS Common Services",
  7. "tr": "NFS Ortak Servisleri"})
  8. serviceConf = "nfs"
  9. ERR_INSMOD = _({"en": "Failed probing module %s",
  10. "tr": "%s modülü yüklenemedi",
  11. })
  12. ERR_RMMOD = _({"en": "Failed removing module %s",
  13. "tr": "%s modülü çıkarılamadı",
  14. })
  15. PIPEFS_MOUNTPOINT = "/var/lib/nfs/rpc_pipefs"
  16. STATD_PIDFILE = "/run/rpc.statd.pid"
  17. IDMAPD_PIDFILE = "/run/rpc.idmapd.pid"
  18. GSSD_PIDFILE = "/run/rpc.gssd.pid"
  19. # Parse the fstab file and determine whether we need gssd or not, by searching
  20. # mount option sec=krb* in nfs mount entries.
  21. # If none, nfs conf.d file decides if it's needed.
  22. def need_gssd():
  23. fstab = fstabutils.Fstab()
  24. for entry in fstab.get_entries():
  25. if entry.is_nfs():
  26. if "sec=krb" in entry.get_fs_mntopts():
  27. return True
  28. @synchronized
  29. def start():
  30. startDependencies("rpcbind")
  31. # Set the ports lockd should listen on
  32. LOCKD_TCPPORT = config.get("LOCKD_TCPPORT")
  33. if LOCKD_TCPPORT:
  34. run("/sbin/sysctl -w fs.nfs.nlm_tcpport=%s" % LOCKD_TCPPORT)
  35. LOCKD_UDPPORT = config.get("LOCKD_UDPPORT")
  36. if LOCKD_UDPPORT:
  37. run("/sbin/sysctl -w fs.nfs.nlm_udpport=%s" % LOCKD_UDPPORT)
  38. # rpc.statd is first
  39. RPCSTATD_OPTIONS = config.get("RPCSTATD_OPTIONS", "")
  40. STATD_PORT = config.get("STATD_PORT")
  41. if STATD_PORT:
  42. RPCSTATD_OPTIONS += " -p %s" % STATD_PORT
  43. startService(command="/sbin/rpc.statd",
  44. args="%s" % RPCSTATD_OPTIONS,
  45. donotify=True,
  46. pidfile=STATD_PIDFILE)
  47. if config.get("NEED_IDMAPD", "yes") == "yes" or (config.get("NEED_GSSD", "no") == "yes" or need_gssd()):
  48. if run("/sbin/modprobe -q nfs"):
  49. fail(ERR_INSMOD % "nfs")
  50. # Make sure the mointpoint exists
  51. if not os.path.exists(PIPEFS_MOUNTPOINT):
  52. os.makedirs(PIPEFS_MOUNTPOINT)
  53. # Check if PIPEFS_MOUNTPOINT is a real mounted fs
  54. if run("/bin/mountpoint -q %s" % PIPEFS_MOUNTPOINT):
  55. run("/bin/mount -t rpc_pipefs rpc_pipefs %s" % PIPEFS_MOUNTPOINT)
  56. startService(command="/usr/sbin/rpc.idmapd",
  57. args="-f %s" % config.get("RPCIDMAPD_OPTIONS", ""),
  58. donotify=True,
  59. detach=True,
  60. makepid=True,
  61. pidfile=IDMAPD_PIDFILE)
  62. if config.get("NEED_GSSD", "no") == "yes" or need_gssd():
  63. if run("/sbin/modprobe -q rpcsec_gss_krb5"):
  64. fail(ERR_INSMOD % "rpcsec_gss_krb5")
  65. startService(command="/usr/sbin/rpc.gssd",
  66. args="-f %s" % config.get("RPCGSSD_OPTIONS", ""),
  67. donotify=True,
  68. detach=True,
  69. makepid=True,
  70. pidfile=GSSD_PIDFILE)
  71. @synchronized
  72. def stop():
  73. LOCKD_TCPPORT = config.get("LOCKD_TCPPORT")
  74. if LOCKD_TCPPORT:
  75. run("/sbin/sysctl -w fs.nfs.nlm_tcpport=0")
  76. LOCKD_UDPPORT = config.get("LOCKD_UDPPORT")
  77. if LOCKD_UDPPORT:
  78. run("/sbin/sysctl -w fs.nfs.nlm_udpport=0")
  79. stopService(pidfile=GSSD_PIDFILE,
  80. donotify=True)
  81. stopService(pidfile=IDMAPD_PIDFILE,
  82. donotify=True)
  83. stopService(pidfile=STATD_PIDFILE,
  84. donotify=True)
  85. if not run("/bin/mountpoint -q %s" % PIPEFS_MOUNTPOINT):
  86. run("/bin/umount %s" % PIPEFS_MOUNTPOINT)
  87. def status():
  88. result = isServiceRunning(STATD_PIDFILE)
  89. if config.get("NEED_IDMAPD", "yes") == "yes":
  90. result = result and isServiceRunning(IDMAPD_PIDFILE)
  91. if config.get("NEED_GSSD", "no") == "yes" or need_gssd():
  92. result = result and isServiceRunning(GSSD_PIDFILE)
  93. return result