domain.pp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. define limits::domain (
  2. $as = undef,
  3. $core = undef,
  4. $cpu = undef,
  5. $data = undef,
  6. $fsize = undef,
  7. $locks = undef,
  8. $maxlogins = undef,
  9. $maxsyslogins = undef,
  10. $memlock = undef,
  11. $msgqueue = undef,
  12. $nice = undef,
  13. $nofile = undef,
  14. $nproc = undef,
  15. $priority = undef,
  16. $rss = undef,
  17. $rtprio = undef,
  18. $sigpending = undef,
  19. $stack = undef,
  20. ) {
  21. $domain = $title
  22. # core: limits the core file size (KB)
  23. if $core {
  24. limits::set{ "${domain}-core":
  25. domain => $domain,
  26. item => 'core',
  27. soft => $core[soft],
  28. hard => $core[hard],
  29. }
  30. }
  31. # data: maximum data size (KB)
  32. if $data {
  33. limits::set{ "${domain}-data":
  34. domain => $domain,
  35. item => 'data',
  36. soft => $data[soft],
  37. hard => $data[hard],
  38. }
  39. }
  40. # fsize: maximum filesize (KB)
  41. if $fsize {
  42. limits::set{ "${domain}-fsize":
  43. domain => $domain,
  44. item => 'fsize',
  45. soft => $fsize[soft],
  46. hard => $fsize[hard],
  47. }
  48. }
  49. # memlock: maximum locked-in-memory address space (KB)
  50. if $memlock {
  51. limits::set{ "${domain}-memlock":
  52. domain => $domain,
  53. item => 'memlock',
  54. soft => $memlock[soft],
  55. hard => $memlock[hard],
  56. }
  57. }
  58. # nofile: maximum number of open files
  59. if $nofile {
  60. limits::set{ "${domain}-nofile":
  61. domain => $domain,
  62. item => 'nofile',
  63. soft => $nofile[soft],
  64. hard => $nofile[hard],
  65. }
  66. }
  67. # rss: maximum resident set size (KB) (Ignored in Linux 2.4.30 and higher)
  68. if $rss {
  69. limits::set{ "${domain}-rss":
  70. domain => $domain,
  71. item => 'rss',
  72. soft => $rss[soft],
  73. hard => $rss[hard],
  74. }
  75. }
  76. # stack: maximum stack size (KB)
  77. if $stack {
  78. limits::set{ "${domain}-stack":
  79. domain => $domain,
  80. item => 'stack',
  81. soft => $stack[soft],
  82. hard => $stack[hard],
  83. }
  84. }
  85. # cpu: maximum CPU time (minutes)
  86. if $cpu {
  87. limits::set{ "${domain}-cpu":
  88. domain => $domain,
  89. item => 'cpu',
  90. soft => $cpu[soft],
  91. hard => $cpu[hard],
  92. }
  93. }
  94. # nproc: maximum number of processes
  95. if $nproc {
  96. limits::set{ "${domain}-nproc":
  97. domain => $domain,
  98. item => 'nproc',
  99. soft => $nproc[soft],
  100. hard => $nproc[hard],
  101. }
  102. }
  103. # as: address space limit (KB)
  104. if $as {
  105. limits::set{ "${domain}-as":
  106. domain => $domain,
  107. item => 'as',
  108. soft => $as[soft],
  109. hard => $as[hard],
  110. }
  111. }
  112. # maxlogins: maximum number of logins for this user except for this with uid=0
  113. if $maxlogins {
  114. limits::set{ "${domain}-maxlogins":
  115. domain => $domain,
  116. item => 'maxlogins',
  117. soft => $maxlogins[soft],
  118. hard => $maxlogins[hard],
  119. }
  120. }
  121. # maxsyslogins: maximum number of all logins on system
  122. if $maxsyslogins {
  123. limits::set{ "${domain}-maxsyslogins":
  124. domain => $domain,
  125. item => 'maxsyslogins',
  126. soft => $maxsyslogins[soft],
  127. hard => $maxsyslogins[hard],
  128. }
  129. }
  130. # priority: the priority to run user process with (negative values boost process priority)
  131. if $priority {
  132. limits::set{ "${domain}-priority":
  133. domain => $domain,
  134. item => 'priority',
  135. soft => $priority[soft],
  136. hard => $priority[hard],
  137. }
  138. }
  139. # locks: maximum locked files (Linux 2.4 and higher)
  140. if $locks {
  141. limits::set{ "${domain}-locks":
  142. domain => $domain,
  143. item => 'locks',
  144. soft => $locks[soft],
  145. hard => $locks[hard],
  146. }
  147. }
  148. # sigpending: maximum number of pending signals (Linux 2.6 and higher)
  149. if $sigpending {
  150. limits::set{ "${domain}-sigpending":
  151. domain => $domain,
  152. item => 'sigpending',
  153. soft => $sigpending[soft],
  154. hard => $sigpending[hard],
  155. }
  156. }
  157. # msgqueue: maximum memory used by POSIX message queues (bytes) (Linux 2.6 and higher)
  158. if $msgqueue {
  159. limits::set{ "${domain}-msgqueue":
  160. domain => $domain,
  161. item => 'msgqueue',
  162. soft => $msgqueue[soft],
  163. hard => $msgqueue[hard],
  164. }
  165. }
  166. # nice: maximum nice priority allowed to raise to (Linux 2.6.12 and higher) values: [-20,19]
  167. if $nice {
  168. limits::set{ "${domain}-nice":
  169. domain => $domain,
  170. item => 'nice',
  171. soft => $nice[soft],
  172. hard => $nice[hard],
  173. }
  174. }
  175. # rtprio: maximum realtime priority allowed for non-privileged processes (Linux 2.6.12 and higher)
  176. if $rtprio {
  177. limits::set{ "${domain}-rtprio":
  178. domain => $domain,
  179. item => 'rtprio',
  180. soft => $rtprio[soft],
  181. hard => $rtprio[hard],
  182. }
  183. }
  184. }