Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92997594
hpc_delaccounts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 25, 11:38
Size
1 KB
Mime Type
text/x-perl
Expires
Wed, Nov 27, 11:38 (2 d)
Engine
blob
Format
Raw Data
Handle
22553081
Attached To
rSLURMACCOUNTS slurm-accounts
hpc_delaccounts
View Options
#!/usr/bin/perl -w
# cleanup_accounts - delete empty slurm accounts
#
# Author : EPFL-SCITAS
# Date : March 2016
use strict;
use FindBin;
use lib "$FindBin::RealBin/../lib/blib";
use HPCUsers;
use Slurm;
use Log;
use Cmd;
use Cwd 'abs_path';
# -----------------------------------------------------------------------------
# Command line options
#
my %opt;
my $logfile = "hpcusers.log";
sub print_usage() {
print STDERR << "EOF";
Delete all empty slurm accounts.
By default, perform a dry run by only printing commands to be run.
usage: $0 [-g] [-h]
OPTIONS
-g : go for real by applying the required modifications, and log commands in $logfile.
-h : this (help) message
example: $0 -g
EOF
exit;
}
sub init()
{
use Getopt::Std;
my $opt_string = 'hg';
getopts("$opt_string", \%opt) or print_usage();
# pathname of logfile
my $cluster = Slurm::get_cluster_name();
my $logdir = "$FindBin::RealBin/../var/";
if ($cluster ne "" && -e "$logdir") {
$Log::logfile = abs_path($logdir . $cluster . "_" . $logfile);
} else {
$Log::logfile = "/var/log/" . $logfile;
}
print_usage() if $opt{h};
$Cmd::dry_run = 1;
$Cmd::dry_run = 0 if $opt{g};
print_usage() if (scalar @ARGV > 1);
}
# Remove empty slurm accounts
sub cleanup_slurm_accounts()
{
my $nb_iterations = 0;
rescan:
return if ++$nb_iterations > 25; # we never know, to avoid infinite loop
foreach my $accountname (Slurm::all_accounts()) {
if (Slurm::is_account_empty($accountname)) {
Log::output_last_cmd_result() if Slurm::delete_account($accountname);
# if slurm account tree is modified, we need to rescan accounts from scratch
goto rescan if ($Cmd::result{status} eq "reinitialized");
}
}
}
# -----------------------------------------------------------------------------
&init();
&HPCUsers::init();
&cleanup_slurm_accounts();
Event Timeline
Log In to Comment