[omd-commits] OMD Git: omd: Added --tmpfs-size/-t option to omd create/mv/cp

git version control git at mathias-kettner.de
Tue Jul 29 13:46:03 CEST 2014


Module:   omd
Branch:   master
Commit:   0f07ef8b2c73fae1e24f0f54e9261511eded5a8c
URL:      http://omdistro.org/projects/omd/repository/revisions/0f07ef8b2c73fae1e24f0f54e9261511eded5a8c

Author:   Lars Michelsen <lm at mathias-kettner.de>
Date:     Tue Jul 29 13:45:56 2014 +0200
Commiter: Lars Michelsen <lm at mathias-kettner.de>
Date:     Tue Jul 29 13:45:56 2014 +0200

Added --tmpfs-size/-t option to omd create/mv/cp

---

 Changelog          |    2 ++
 packages/omd/omd   |   22 ++++++++++++++++------
 packages/omd/omd.8 |   15 +++++++++++++++
 3 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/Changelog b/Changelog
index d388fb3..522f643 100644
--- a/Changelog
+++ b/Changelog
@@ -14,6 +14,8 @@ This file documents the revision history for the Open Monitoring Distribution
             - Added --apache-reload flag to omd create/rm for executing a
               reload of the system apache instead of a restart
             - Added nagios/icinga reload init hooks
+            - Added --tmpfs-size/-t option to omd create/mv/cp for specifying
+              an explicit maximum size for the sites tmpfs
             - FIX: Providing correct exit codes when running "omd status"
             - FIX: exit with 2 (partially running) when only some of the
               sites are running or partially running using "omd status"
diff --git a/packages/omd/omd b/packages/omd/omd
index d580879..8018ef1 100644
--- a/packages/omd/omd
+++ b/packages/omd/omd
@@ -794,12 +794,18 @@ def unmount_tmpfs(sitename, output = True, kill = False):
 
     return True
 
-def add_to_fstab(sitename):
+def add_to_fstab(sitename, tmpfs_size = None):
     # tmpfs                   /opt/omd/sites/b01/tmp  tmpfs   user,uid=b01,gid=b01 0 0
     mountpoint = tmp_dir(sitename)
     sys.stdout.write("Adding %s to /etc/fstab.\n" % mountpoint)
-    file("/etc/fstab", "a+").write("tmpfs  %s tmpfs noauto,user,mode=755,uid=%s,gid=%s 0 0\n" % \
-        (mountpoint, sitename, sitename))
+
+    # No size option: using up to 50% of the RAM
+    sizespec = ''
+    if tmpfs_size != None and re.match('^[0-9]+(G|M|%)$', tmpfs_size):
+        sizespec = ',size=%s' % tmpfs_size
+
+    file("/etc/fstab", "a+").write("tmpfs  %s tmpfs noauto,user,mode=755,uid=%s,gid=%s%s 0 0\n" % \
+        (mountpoint, sitename, sitename, sizespec))
 
 def remove_from_fstab(sitename):
     mountpoint = tmp_dir(sitename)
@@ -2259,7 +2265,7 @@ def main_create(args, options={}):
         fstab_verify(g_sitename)
     else:
         create_site_dir(g_sitename)
-        add_to_fstab(g_sitename)
+        add_to_fstab(g_sitename, tmpfs_size = options.get('tmpfs-size'))
 
     config_settings = {}
     if "no-autostart" in options:
@@ -2373,7 +2379,8 @@ def main_rm(args, options={}):
 
     if not kill and user_logged_in(g_sitename):
         bail_out("User '%s' still logged in or running processes." % g_sitename)
-    unmount_tmpfs(g_sitename, kill=kill)
+    if tmpfs_mounted(g_sitename):
+        unmount_tmpfs(g_sitename, kill=kill)
 
     if not reuse:
         remove_from_fstab(g_sitename)
@@ -2534,7 +2541,7 @@ def main_mv_or_cp(what, args, options={}):
 
     # Entry for tmps in /etc/fstab
     if not reuse:
-        add_to_fstab(new)
+        add_to_fstab(new, tmpfs_size = options.get('tmpfs-size'))
 
     # Make apache aware of new site
     create_apache_hook(new)
@@ -2971,6 +2978,7 @@ commands = [
       ( "no-init",  "n",  False, "leave new site directory empty (a later omd init does this"),
       ( "no-autostart", "A", False, "set AUTOSTART to off (useful for test sites)"), 
       ( "apache-reload",  False,  False, "Issue a reload of the system apache instead of a restart"),
+      ( "tmpfs-size",  "t",  True, "specify the maximum size of the tmpfs (defaults to 50% of RAM)"),
     ],
     "Create a new site (-u UID, -g GID)",
 
@@ -3022,6 +3030,7 @@ commands = [
       ( "gid", "g", True, "create site group with GID ARG" ),
       ( "reuse", None, False, "do not create a site user, reuse existing one" ),
       ( "conflict", None, True, "non-interactive conflict resolution. ARG is install, keepold, abort or ask"),
+      ( "tmpfs-size",  "t",  True, "specify the maximum size of the tmpfs (defaults to 50% of RAM)"),
     ],
     "Rename a site",
     ""),
@@ -3034,6 +3043,7 @@ commands = [
       ( "no-logs", None, False, "do not copy log files"),
       ( "no-past", "N", False,  "do not copy RRD file and log files"),
       ( "conflict", None, True, "non-interactive conflict resolution. ARG is install, keepold, abort or ask"),
+      ( "tmpfs-size",  "t",  True, "specify the maximum size of the tmpfs (defaults to 50% of RAM)"),
     ],
     "Make a copy of a site",
     ""),
diff --git a/packages/omd/omd.8 b/packages/omd/omd.8
index d426434..52d5a33 100644
--- a/packages/omd/omd.8
+++ b/packages/omd/omd.8
@@ -122,6 +122,11 @@ the system Apache (/omd/apache/SITE.conf will be empty).
 
 \fB--apache-reload\fP Issue a reaload of the apache process instead of the default restart
 
+\fB-t SIZE\fP By default the tmpfs of the site is created to allocate 50% of
+the available RAM at max. When providing the \fB-t\fP option together with the SIZE
+given as absolute value of e.g. \fB500M\fP or percentage value like \fB10%\fP the
+maximum size of the tmpfs can be changed.
+
 .TP
 .B omd init [OPTIONS] SITE
 Initializes a site that has been created with \fBomd create --no-init\fP.
@@ -188,6 +193,11 @@ The following options can be used:
 \fB--conflict=HOW\fP non-interactively resolve merge conflicts. See
 section about \fBomd update\fP for details.
 
+\fB-t SIZE\fP By default the tmpfs of the site is created to allocate 50% of
+the available RAM at max. When providing the \fB-t\fP option together with the SIZE
+given as absolute value of e.g. \fB500M\fP or percentage value like \fB10%\fP the
+maximum size of the tmpfs can be changed.
+
 .TP
 .B omd cp [OPTIONS] SITE NEWNAME     
 Make a copy of a site. A new site with the name NEWSITE will be created
@@ -217,6 +227,11 @@ purposes.
 \fB--conflict=HOW\fP non-interactively resolve merge conflicts. See
 section about \fBomd update\fP for details.
 
+\fB-t SIZE\fP By default the tmpfs of the site is created to allocate 50% of
+the available RAM at max. When providing the \fB-t\fP option together with the SIZE
+given as absolute value of e.g. \fB500M\fP or percentage value like \fB10%\fP the
+maximum size of the tmpfs can be changed.
+
 .TP
 .B omd [-f, --force] [ -V VERSION ] update [ --conflict=HOW ] SITE             
 Update SITE to the current default version of OMD or to the version



More information about the omd-commits mailing list