Skip to content

Commit e74d0f3

Browse files
committed
omd: add mount command to populate tmpfs
1 parent 95bbea6 commit e74d0f3

1 file changed

Lines changed: 65 additions & 4 deletions

File tree

  • packages/omd

packages/omd/omd

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,20 +1722,20 @@ def prepare_and_populate_tmpfs(sitename):
17221722
# to be populated like the tmpfs afterwards.
17231723
if g_site_conf["TMPFS"] == "on":
17241724
if tmpfs_mounted(sitename):
1725-
return
1725+
return False
17261726

17271727
sys.stdout.write("Creating temporary filesystem %s..." % tmp)
17281728
sys.stdout.flush()
17291729
if not os.path.exists(tmp):
17301730
os.mkdir(tmp)
17311731
if 0 != os.system("mount %s '%s'" % (g_info["MOUNT_OPTIONS"], tmp) ):
17321732
sys.stdout.write(tty_error + "\n")
1733-
return
1733+
return False
17341734
else:
17351735
# Skip initializing when either the tmp dir does not exist
17361736
# and the site is not totally stopped
17371737
if os.path.exists(tmp) and not site_is_stopped(sitename):
1738-
return
1738+
return False
17391739

17401740
sys.stdout.write("Preparing tmp directory %s..." % tmp)
17411741
sys.stdout.flush()
@@ -1745,6 +1745,7 @@ def prepare_and_populate_tmpfs(sitename):
17451745
create_skeleton_files(sitename, "tmp")
17461746
chown_tree(tmp, sitename)
17471747
ok()
1748+
return True
17481749

17491750
def unmount_tmpfs(sitename, output = True, kill = False):
17501751
# Clear directory hierarchy when not using a tmpfs
@@ -3876,6 +3877,56 @@ def prepare_dry_run_update_path(dry_run_path, from_version, to_version):
38763877

38773878
return
38783879

3880+
def main_mount(args, options = {}):
3881+
global g_sitename
3882+
global g_sitedir
3883+
3884+
# if no site is selected, all sites are affected
3885+
exit_status = 0
3886+
if not g_sitename:
3887+
for site in all_sites():
3888+
# Set global vars for the current site
3889+
g_sitename = site
3890+
g_sitedir = site_dir(g_sitename)
3891+
load_site_conf()
3892+
3893+
if opt_version and site_version(site) != opt_version:
3894+
continue
3895+
3896+
# already mounted
3897+
if tmpfs_mounted(g_sitename):
3898+
sys.stderr.write("Cannot mount tmpfs of site '%s': already mounted.\n" % site)
3899+
continue
3900+
3901+
# Skip the site even when it is partly running
3902+
if not site_is_stopped(site):
3903+
sys.stderr.write("Cannot mount tmpfs of site '%s' while it is running.\n" % site)
3904+
continue
3905+
3906+
sys.stdout.write("%sMounting tmpfs of site %s%s..." % (tty_bold, site, tty_normal))
3907+
sys.stdout.flush()
3908+
3909+
# We need to open a subprocess, because each site must be populated with the account of the
3910+
# site user. And after setuid() we cannot return.
3911+
stdout = sys.stdout
3912+
stderr = sys.stderr
3913+
p = subprocess.Popen(
3914+
[sys.argv[0], "mount" ] + [ site ] + args,
3915+
stdin=open(os.devnull, "r"),
3916+
stdout=stdout,
3917+
stderr=stderr
3918+
)
3919+
3920+
if not p.wait():
3921+
exit_status = 1
3922+
else:
3923+
# Skip the site even when it is partly running
3924+
if not site_is_stopped(g_sitename):
3925+
bail_out(tty_error + ": Cannot mount tmpfs of site '%s' while it is running." % g_sitename)
3926+
if not prepare_and_populate_tmpfs(g_sitename):
3927+
exit_status = 1
3928+
sys.exit(exit_status)
3929+
38793930
def main_umount(args, options = {}):
38803931
global g_sitename
38813932
global g_sitedir
@@ -3908,7 +3959,6 @@ def main_umount(args, options = {}):
39083959
unmount_tmpfs(g_sitename, kill=options.kill)
39093960
sys.exit(exit_status)
39103961

3911-
39123962
def main_init_action(command, args, options={}):
39133963
if g_sitename:
39143964
exit_status = init_action(command, args, options)
@@ -4888,6 +4938,17 @@ commands = [
48884938
must_exist = True,
48894939
),
48904940

4941+
Command(
4942+
command = "mount",
4943+
description = "Mount ramdisk volumes of site(s) and populate tmp/",
4944+
fn = main_mount,
4945+
needs_site = 2,
4946+
must_exist = True,
4947+
option_spec = [
4948+
( "--version", "-V", { "help":"nmount only sites with version ARG" }),
4949+
],
4950+
),
4951+
48914952
Command(
48924953
command = "umount",
48934954
description = "Umount ramdisk volumes of site(s)",

0 commit comments

Comments
 (0)