@@ -362,6 +362,50 @@ def _handle_freenx(passwd):
362
362
else :
363
363
log .info ("freenx-server is not installed; not configuring it" )
364
364
365
+
366
+ def _run (cmd ):
367
+ if not cmd :
368
+ log .error ("Trying to run an empty command? '{0}'" .format (cmd ))
369
+ return False
370
+ try :
371
+ process = subprocess .Popen (cmd , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
372
+ stdout , stderr = process .communicate ()
373
+ if process .returncode == 0 :
374
+ log .debug ("Successfully ran '%s'" % cmd )
375
+ if stdout :
376
+ return stdout
377
+ else :
378
+ return True
379
+ else :
380
+ log .error ("Error running '%s'. Process returned code '%s' and following stderr: '%s'"
381
+ % (cmd , process .returncode , stderr ))
382
+ return False
383
+ except Exception , e :
384
+ log .error ("Exception running '%s': '%s'" % (cmd , e ))
385
+ return False
386
+
387
+
388
+ def _ensure_ephemeral_disk_mounted ():
389
+ """
390
+ Make sure `/mnt` is a mounted device vs. just being part of `/`.
391
+
392
+ At least some AWS instance types (e.g., r3) do not auto-mount what's in
393
+ `/ets/fstab` so make sure the ephemeral disks are in fact mounted.
394
+ http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#InstanceStoreTrimSupport
395
+ """
396
+ if not _run ('mountpoint -q /mnt' ):
397
+ device = '/dev/xvdb' # Most of AWS instances have this device
398
+ if os .path .exists (device ):
399
+ log .debug ("/mnt is not a mountpoint; will try to mount it from {0}"
400
+ .format (device ))
401
+ _run ('mkfs.xfs {0}' .format (device ))
402
+ _run ('mount -o discard {0} /mnt' .format (device ))
403
+ else :
404
+ log .warning ("Mountpoint /mnt not available and no device {0}"
405
+ .format (device ))
406
+ else :
407
+ log .debug ("/mnt is already a mountpoint so not mounting it again." )
408
+
365
409
# ====================== Actions methods ======================
366
410
367
411
def _handle_empty ():
@@ -492,6 +536,8 @@ def _handle_yaml(user_data):
492
536
with open (USER_DATA_FILE , 'w' ) as ud_yaml :
493
537
yaml .dump (ud , ud_yaml , default_flow_style = False )
494
538
539
+ _ensure_ephemeral_disk_mounted ()
540
+
495
541
# Get & run boot script
496
542
if _get_boot_script (ud ):
497
543
_run_boot_script (DEFAULT_BOOT_SCRIPT_NAME )
0 commit comments