#!/usr/bin/env bash

# Run a Job on a Job Server.

JOB_ID=$1
JOB_SERVER=$2

if [[ -z "$JOB_ID" ]]; then
    echo "error: missing JOB_ID"
    exit 1
fi

if [[ -z "$JOB_SERVER" ]]; then
    echo "error: missing JOB_SERVER"
    exit 1
fi

k5start -Uf /etc/www-scheduler/keytab -- sh -c "remctl $JOB_SERVER cron runjob $JOB_ID"

exit 0

# Documentation.  Use a hack to hide this from the shell.  Because of the
# above exit line, this should never be executed.
DOCS=<<__END_OF_DOCS__

=head1 NAME

run-job - Run a scheduler job on a job server

=head1 SYNOPSIS

run-job I<job-id> I<job-server>

=head1 DESCRIPTION

Run the job with id I<job-id> on the job server I<job-server>.

=head1 OPTIONS

None.

=head1 EXIT STATUS

Returns C<0> on success, non-zero on any failure.

=head1 LICENSE AND COPYRIGHT

Copyright 2021,2022 The Board of Trustees of the Leland Stanford Junior
University.  All rights reserved.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of Stanford University not be used in
advertising or publicity pertaining to distribution of the software
without specific, written prior permission.  Stanford University makes no
representations about the suitability of this software for any purpose.
It is provided "as is" without express or implied warranty.

THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

=cut

__END_OF_DOCS__
