#! /usr/bin/perl -w
#
# Start/stop a BOINC project
#
# Author: Gabor Gombas <gombasg@sztaki.hu>
#
# This is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.

=head1 NAME

boinc_ctl - Perform administrative tasks for BOINC projects

=head1 SYNOPSIS

boinc_ctl [B<--help>] [B<--quiet>] B<--name>=I<NAME> I<COMMAND>

=head1 DESCRIPTION

This script performs some administrative commands for BOINC projects. It
ensures that the commands run under the correct user ID and with the
correct configuration.

=head1 OPTIONS

=over

=item B<--help>

Display a short help text and exit.

=item B<--quiet>

Do not display status messages.

=item B<--name>=I<NAME>

The name of the project.

=item I<COMMAND>

The command to perform. Valid commands:

=over

=item B<start>

Enables the project by starting the configured daemons and allowing the
CGI scripts to run

=item B<stop>

Disables the project by halting the configured daemons and disabling the CGI
scripts

=item B<status>

Queries the project's status

=back

=back

=head1 SEE ALSO

B<boinc_create_project(8)>

=head1 AUTHOR

Written by Gabor Gombas <gombasg@sztaki.hu>

=head1 COPYRIGHT

LGPL-2.1 or later

=cut

use Boinc::Common;
use Boinc::Admin;

use Getopt::Long;
use IO::File;
use Pod::Usage;

use strict;
use vars qw($project_name $help $quiet);

my $logfile = '/var/log/boinc.log';

#######################################################################
# Main program

GetOptions("name=s" => \$project_name,
		"quiet" => \$quiet,
		"help" => \$help)
	or die("Failed to parse options\n");

pod2usage(1) if ($help);

die("You must specify the project name\n")
	unless $project_name;

die("No command specified\n")
	unless $ARGV[0];

set_logfile($logfile);
set_quiet($quiet);

my $cmd = $ARGV[0];

if ($cmd =~ m/^(start|stop|status)$/) {
	ctl_project($project_name, $cmd);
}
else {
	die("Unknown command $cmd\n");
}
