def debug_generate(): from freenasUI.common.locks import mntlock from freenasUI.middleware.notifier import notifier from freenasUI.network.models import GlobalConfiguration _n = notifier() gc = GlobalConfiguration.objects.all().order_by('-id')[0] mntpt, direc, dump = debug_get_settings() standby_debug = None if not _n.is_freenas() and _n.failover_licensed(): try: with client as c: job = c.call('failover.call_remote', 'system.debug', [], {'job': True}) standby_debug = job['result'] except: log.error('Failed to get debug from standby node', exc_info=True) with mntlock(mntpt=mntpt): debug_run(direc) if standby_debug: debug_file = '%s/debug.tar' % direc with client as c: _n.sync_file_recv(c, standby_debug, '%s/standby.txz' % direc) # provide correct hostnames if _n.failover_node() == 'A': my_hostname = gc.gc_hostname remote_hostname = gc.gc_hostname_b else: my_hostname = gc.gc_hostname_b remote_hostname = gc.gc_hostname with tarfile.open(debug_file, 'w') as tar: tar.add('%s/standby.txz' % direc, '%s.txz' % remote_hostname) tar.add(dump, '%s.txz' % my_hostname)
def debug_generate(): from freenasUI.common.locks import mntlock from freenasUI.middleware.notifier import notifier from freenasUI.network.models import GlobalConfiguration _n = notifier() gc = GlobalConfiguration.objects.all().order_by('-id')[0] mntpt, direc, dump = debug_get_settings() standby_debug = None if not _n.is_freenas() and _n.failover_licensed(): s = _n.failover_rpc() standby_debug = s.debug() with mntlock(mntpt=mntpt): debug_run(direc) if standby_debug: debug_file = '%s/debug.tar' % direc _n.sync_file_recv(s, standby_debug, '%s/standby.txz' % direc) if _n.failover_node() == 'B': hostname_a = gc.gc_hostname hostname_b = gc.gc_hostname_b else: hostname_a = gc.gc_hostname_b hostname_b = gc.gc_hostname with tarfile.open(debug_file, 'w') as tar: tar.add('%s/standby.txz' % direc, '%s.txz' % hostname_b) tar.add(dump, '%s.txz' % hostname_a)
def debug_generate(): from freenasUI.common.locks import mntlock from freenasUI.middleware.notifier import notifier from freenasUI.network.models import GlobalConfiguration _n = notifier() gc = GlobalConfiguration.objects.all().order_by('-id')[0] mntpt, direc, dump = debug_get_settings() standby_debug = None if not _n.is_freenas() and _n.failover_licensed(): try: with client as c: standby_debug = c.call('failover.call_remote', 'system.debug', [], {'job': True}, timeout=300) except: log.error('Failed to get debug from standby node', exc_info=True) with mntlock(mntpt=mntpt): debug_run(direc) if standby_debug: debug_file = '%s/debug.tar' % direc with client as c: _n.sync_file_recv(c, standby_debug, '%s/standby.txz' % direc) # provide correct hostnames if _n.failover_node() == 'A': my_hostname = gc.gc_hostname remote_hostname = gc.gc_hostname_b else: my_hostname = gc.gc_hostname_b remote_hostname = gc.gc_hostname with tarfile.open(debug_file, 'w') as tar: tar.add('%s/standby.txz' % direc, '%s.txz' % remote_hostname) tar.add(dump, '%s.txz' % my_hostname)
def debug(request): hostname = GlobalConfiguration.objects.all().order_by('-id')[0].gc_hostname p1 = pipeopen("zfs list -H -o name") zfs = p1.communicate()[0] zfs = zfs.split() direc = "/var/tmp/ixdiagnose" mntpt = '/var/tmp' systemdataset, volume, basename = notifier().system_dataset_settings() if basename: mntpoint = '/mnt/%s' % basename if os.path.exists(mntpoint): direc = '%s/ixdiagnose' % mntpoint mntpt = mntpoint dump = "%s/ixdiagnose.tgz" % direc with mntlock(mntpt=mntpt): # Be extra safe in case we have left over from previous run if os.path.exists(direc): opts = ["/bin/rm", "-r", "-f", direc] p1 = pipeopen(' '.join(opts), allowfork=True) p1.wait() opts = ["/usr/local/bin/ixdiagnose", "-d", direc, "-s", "-F"] p1 = pipeopen(' '.join(opts), allowfork=True) p1.communicate() wrapper = FileWrapper(file(dump)) response = StreamingHttpResponse( wrapper, content_type='application/octet-stream', ) response['Content-Length'] = os.path.getsize(dump) response['Content-Disposition'] = \ 'attachment; filename=debug-%s-%s.tgz' % ( hostname.encode('utf-8'), time.strftime('%Y%m%d%H%M%S')) opts = ["/bin/rm", "-r", "-f", direc] p1 = pipeopen(' '.join(opts), allowfork=True) p1.wait() return response
debug = False # Detect if another instance is running def exit_if_running(pid): log.debug("Checking if process %d is still alive" % (pid, )) try: os.kill(pid, 0) # If we reached here, there is another process in progress log.debug("Process %d still working, quitting" % (pid, )) sys.exit(0) except OSError: log.debug("Process %d gone" % (pid, )) appPool.hook_tool_run('autorepl') MNTLOCK = mntlock() mypid = os.getpid() templog = '/tmp/repl-%d' % (mypid) now = datetime.datetime.now().replace(microsecond=0) if now.second < 30 or now.minute == 59: now = now.replace(second=0) else: now = now.replace(minute=now.minute + 1, second=0) now = datetime.time(now.hour, now.minute) # (mis)use MNTLOCK as PIDFILE lock. locked = True try: MNTLOCK.lock_try()
if 'AUTOREPL_SKIP_RUNNING' in os.environ: log.debug('Skipping check if autorepl is running.') return log.debug("Checking if process %d is still alive" % (pid, )) try: os.kill(pid, 0) # If we reached here, there is another process in progress log.debug("Process %d still working, quitting" % (pid, )) sys.exit(0) except OSError: log.debug("Process %d gone" % (pid, )) appPool.hook_tool_run('autorepl') MNTLOCK = mntlock() mypid = os.getpid() templog = '/tmp/repl-%d' % (mypid) start = datetime.datetime.now().replace(microsecond=0) if start.second < 30 or start.minute == 59: now = start.replace(second=0) else: now = start.replace(minute=start.minute + 1, second=0) now = datetime.time(now.hour, now.minute) # (mis)use MNTLOCK as PIDFILE lock. locked = True try: MNTLOCK.lock_try()
def perftest(request): systemdataset, volume, basename = notifier().system_dataset_settings() if request.method == 'GET': p1 = subprocess.Popen([ '/usr/local/bin/perftests-nas', '-t', ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) tests = p1.communicate()[0].strip('\n').split('\n') return render(request, 'system/perftest.html', { 'tests': tests, }) if not basename: raise MiddlewareError( _('System dataset is required to perform this action.') ) dump = os.path.join(notifier().system_dataset_path(), 'perftest.txz') perftestdataset = '%s/perftest' % basename perftestdir = os.path.join(notifier().system_dataset_path(), 'perftest') with mntlock(mntpt=notifier().system_dataset_path()): _n = notifier() rv, errmsg = _n.create_zfs_dataset( path=perftestdataset, props={ 'primarycache': 'metadata', 'secondarycache': 'metadata', 'mountpoint': 'legacy', 'compression': 'off', }, _restart_collectd=False, ) currdir = os.getcwd() if not os.path.isdir(perftestdir): os.mkdir(perftestdir) os.chdir(perftestdir) os.system('/sbin/mount -t zfs %s %s' % (perftestdataset, perftestdir)) p1 = subprocess.Popen([ '/usr/local/bin/perftests-nas', '-o', perftestdataset.encode('utf8'), '-s', str(PERFTEST_SIZE), ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) p1.communicate() os.chdir('..') p1 = pipeopen('tar -cJf %s perftest' % dump) p1.communicate() os.chdir(currdir) os.system('/sbin/umount -f %s' % perftestdataset) os.rmdir(perftestdir) _n.destroy_zfs_dataset(perftestdataset) return JsonResp( request, message='Performance test has completed.', events=[ 'window.location=\'%s\'' % reverse('system_perftest_download'), ], )
def perftest(request): systemdataset, volume, basename = notifier().system_dataset_settings() if request.method == 'GET': p1 = subprocess.Popen([ '/usr/local/bin/perftests-nas', '-t', ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) tests = p1.communicate()[0].strip('\n').split('\n') return render(request, 'system/perftest.html', { 'tests': tests, }) if not basename: raise MiddlewareError( _('System dataset is required to perform this action.')) dump = os.path.join(notifier().system_dataset_path(), 'perftest.txz') perftestdataset = '%s/perftest' % basename perftestdir = os.path.join(notifier().system_dataset_path(), 'perftest') with mntlock(mntpt=notifier().system_dataset_path()): _n = notifier() rv, errmsg = _n.create_zfs_dataset( path=perftestdataset, props={ 'primarycache': 'metadata', 'secondarycache': 'metadata', 'mountpoint': 'legacy', 'compression': 'off', }, _restart_collectd=False, ) currdir = os.getcwd() if not os.path.isdir(perftestdir): os.mkdir(perftestdir) os.chdir(perftestdir) os.system('/sbin/mount -t zfs %s %s' % (perftestdataset, perftestdir)) p1 = subprocess.Popen([ '/usr/local/bin/perftests-nas', '-o', perftestdataset.encode('utf8'), '-s', str(PERFTEST_SIZE), ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) p1.communicate() os.chdir('..') p1 = pipeopen('tar -cJf %s perftest' % dump) p1.communicate() os.chdir(currdir) os.system('/sbin/umount -f %s' % perftestdataset) os.rmdir(perftestdir) _n.destroy_zfs_dataset(perftestdataset) return JsonResp( request, message='Performance test has completed.', events=[ 'window.location=\'%s\'' % reverse('system_perftest_download'), ], )