View | Details | Raw Unified | Return to ticket 2134 | Differences between
and this patch

Collapse All | Expand All

(-)a/contribs/torque/qrerun.pl (-134 / +134 lines)
Lines 1-134 Link Here
1
#! /usr/bin/perl -w
1
#! /usr/bin/perl -w
2
###############################################################################
2
###############################################################################
3
#
3
#
4
#  qrerun - PBS wrapper to cancel and resubmit a job
4
#  qrerun - PBS wrapper to cancel and resubmit a job
5
#
5
#
6
###############################################################################
6
###############################################################################
7
#  This file is part of SLURM, a resource management program.
7
#  This file is part of SLURM, a resource management program.
8
#  For details, see <http://slurm.schedmd.com/>.
8
#  For details, see <http://slurm.schedmd.com/>.
9
#  Please also read the included file: DISCLAIMER.
9
#  Please also read the included file: DISCLAIMER.
10
#
10
#
11
#  SLURM is free software; you can redistribute it and/or modify it under
11
#  SLURM is free software; you can redistribute it and/or modify it under
12
#  the terms of the GNU General Public License as published by the Free
12
#  the terms of the GNU General Public License as published by the Free
13
#  Software Foundation; either version 2 of the License, or (at your option)
13
#  Software Foundation; either version 2 of the License, or (at your option)
14
#  any later version.
14
#  any later version.
15
#
15
#
16
#  In addition, as a special exception, the copyright holders give permission
16
#  In addition, as a special exception, the copyright holders give permission
17
#  to link the code of portions of this program with the OpenSSL library under
17
#  to link the code of portions of this program with the OpenSSL library under
18
#  certain conditions as described in each individual source file, and
18
#  certain conditions as described in each individual source file, and
19
#  distribute linked combinations including the two. You must obey the GNU
19
#  distribute linked combinations including the two. You must obey the GNU
20
#  General Public License in all respects for all of the code used other than
20
#  General Public License in all respects for all of the code used other than
21
#  OpenSSL. If you modify file(s) with this exception, you may extend this
21
#  OpenSSL. If you modify file(s) with this exception, you may extend this
22
#  exception to your version of the file(s), but you are not obligated to do
22
#  exception to your version of the file(s), but you are not obligated to do
23
#  so. If you do not wish to do so, delete this exception statement from your
23
#  so. If you do not wish to do so, delete this exception statement from your
24
#  version.  If you delete this exception statement from all source files in
24
#  version.  If you delete this exception statement from all source files in
25
#  the program, then also delete it here.
25
#  the program, then also delete it here.
26
#
26
#
27
#  SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
27
#  SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
28
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
28
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
29
#  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
29
#  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
30
#  details.
30
#  details.
31
#
31
#
32
#  You should have received a copy of the GNU General Public License along
32
#  You should have received a copy of the GNU General Public License along
33
#  with SLURM; if not, write to the Free Software Foundation, Inc.,
33
#  with SLURM; if not, write to the Free Software Foundation, Inc.,
34
#  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
34
#  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
35
#
35
#
36
#  Based off code with permission copyright 2006, 2007 Cluster Resources, Inc.
36
#  Based off code with permission copyright 2006, 2007 Cluster Resources, Inc.
37
###############################################################################
37
###############################################################################
38
use strict;
38
use strict;
39
use FindBin;
39
use FindBin;
40
use Getopt::Long 2.24 qw(:config no_ignore_case);
40
use Getopt::Long 2.24 qw(:config no_ignore_case);
41
use lib "${FindBin::Bin}/../lib/perl";
41
use lib "${FindBin::Bin}/../lib/perl";
42
use autouse 'Pod::Usage' => qw(pod2usage);
42
use autouse 'Pod::Usage' => qw(pod2usage);
43
use Slurm ':all';
43
use Slurm ':all';
44
use Slurmdb ':all'; # needed for getting the correct cluster dims
44
use Slurmdb ':all'; # needed for getting the correct cluster dims
45
use Switch;
45
use Switch;
46
46
47
# Parse Command Line Arguments
47
# Parse Command Line Arguments
48
my (
48
my (
49
	$help, $man,
49
	$help, $man,
50
	$err, $pid, $resp
50
	$err, $pid, $resp
51
);
51
);
52
52
53
GetOptions(
53
GetOptions(
54
        'help|?'    => \$help,
54
        'help|?'    => \$help,
55
        '--man'     => \$man,
55
        '--man'     => \$man,
56
        ) or pod2usage(2);
56
        ) or pod2usage(2);
57
57
58
pod2usage(2) if $help;
58
pod2usage(2) if $help;
59
# Handle man page flag
59
# Handle man page flag
60
if ($man)
60
if ($man)
61
{
61
{
62
        if ($< == 0)    # Cannot invoke perldoc as root
62
        if ($< == 0)    # Cannot invoke perldoc as root
63
        {
63
        {
64
                my $id = eval { getpwnam("nobody") };
64
                my $id = eval { getpwnam("nobody") };
65
                $id = eval { getpwnam("nouser") } unless defined $id;
65
                $id = eval { getpwnam("nouser") } unless defined $id;
66
                $id = -2                          unless defined $id;
66
                $id = -2                          unless defined $id;
67
                $<  = $id;
67
                $<  = $id;
68
        }
68
        }
69
        $> = $<;                         # Disengage setuid
69
        $> = $<;                         # Disengage setuid
70
        $ENV{PATH} = "/bin:/usr/bin";    # Untaint PATH
70
        $ENV{PATH} = "/bin:/usr/bin";    # Untaint PATH
71
        delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
71
        delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
72
        if ($0 =~ /^([-\/\w\.]+)$/) { $0 = $1; }    # Untaint $0
72
        if ($0 =~ /^([-\/\w\.]+)$/) { $0 = $1; }    # Untaint $0
73
        else { die "Illegal characters were found in \$0 ($0)\n"; }
73
        else { die "Illegal characters were found in \$0 ($0)\n"; }
74
        pod2usage(-exitstatus => 0, -verbose => 2);
74
        pod2usage(-exitstatus => 0, -verbose => 2);
75
}
75
}
76
76
77
77
78
# This makes the assumption JOBID will always be the last argument
78
# This makes the assumption JOBID will always be the last argument
79
my $job_id = $ARGV[$#ARGV];
79
my $job_id = $ARGV[$#ARGV];
80
80
81
if (@ARGV < 1) {
81
if (@ARGV < 1) {
82
	pod2usage(-message=>"Invalid Argument", -verbose=>1); 
82
	pod2usage(-message=>"Invalid Argument", -verbose=>1); 
83
	exit(1);
83
	exit(1);
84
}
84
}
85
85
86
if (Slurm->requeue($job_id)) {
86
if (Slurm->requeue($job_id)) {
87
	$err = Slurm->get_errno();
87
	$err = Slurm->get_errno();
88
	$resp = Slurm->strerror($err);
88
	$resp = Slurm->strerror($err);
89
	pod2usage(-message=>"Job id $job_id rerun error: $resp", -verbose=>0);
89
	pod2usage(-message=>"Job id $job_id rerun error: $resp", -verbose=>0);
90
	exit(1);
90
	exit(1);
91
}
91
}
92
exit(0);
92
exit(0);
93
93
94
__END__
94
__END__
95
95
96
=head1 NAME
96
=head1 NAME
97
97
98
B<qrerun> -  To rerun a job is to terminate the job and return the job to the queued state in the execution queue in which the job currently resides.
98
B<qrerun> -  To rerun a job is to terminate the job and return the job to the queued state in the execution queue in which the job currently resides.
99
If a job is marked as not rerunable then the rerun request will fail for that job. 
99
If a job is marked as not rerunable then the rerun request will fail for that job. 
100
100
101
See the option on the qsub and qalter commands. 
101
See the option on the qsub and qalter commands. 
102
102
103
It is aimed to be feature-compatible with PBS' qsub.
103
It is aimed to be feature-compatible with PBS' qsub.
104
104
105
=head1 SYNOPSIS
105
=head1 SYNOPSIS
106
106
107
B<qrerun> [-? | --help] [--man] [--verbose] <job_id>
107
B<qrerun> [-? | --help] [--man] [--verbose] <job_id>
108
108
109
=head1 DESCRIPTION
109
=head1 DESCRIPTION
110
110
111
The B<qrerun> command directs that the specified job is to be rerun if possible. 
111
The B<qrerun> command directs that the specified job is to be rerun if possible. 
112
112
113
=head1 OPTIONS
113
=head1 OPTIONS
114
114
115
=over 4
115
=over 4
116
116
117
=item B<-? | --help>
117
=item B<-? | --help>
118
118
119
a brief help message
119
a brief help message
120
120
121
=item B<--man>
121
=item B<--man>
122
122
123
full documentation
123
full documentation
124
124
125
=back
125
=back
126
126
127
=head1 EXIT STATUS
127
=head1 EXIT STATUS
128
128
129
On success, B<qrerun> will exit with a value of zero. On failure, B<qrerun> will exit with a value greater than zero.
129
On success, B<qrerun> will exit with a value of zero. On failure, B<qrerun> will exit with a value greater than zero.
130
130
131
=head1 SEE ALSO
131
=head1 SEE ALSO
132
132
133
qalter(1) qsub(1)
133
qalter(1) qsub(1)
134
=cut
134
=cut

Return to ticket 2134