Commit c9ce1955 authored by Shawn Routhier's avatar Shawn Routhier

[trac3664] Add the command line processing

Continue adding the boiler plate files and
add the function to parse the command line arguments.
parent 6b345dcb
......@@ -48,8 +48,8 @@ BUILT_SOURCES = lfc_messages.h lfc_messages.cc
noinst_LTLIBRARIES = liblfc.la
liblfc_la_SOURCES =
liblfc_la_SOURCES += lfc_lfc.h
liblfc_la_SOURCES += lfc_lfc.cc
liblfc_la_SOURCES += lfc.h
liblfc_la_SOURCES += lfc.cc
nodist_liblfc_la_SOURCES = lfc_messages.h lfc_messages.cc
EXTRA_DIST += lfc_messages.mes
......
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
[<!ENTITY mdash "&#8212;">]>
<!--
- Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
-
- Permission to use, copy, modify, and/or distribute this software for any
- purpose with or without fee is hereby granted, provided that the above
- copyright notice and this permission notice appear in all copies.
-
- THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- PERFORMANCE OF THIS SOFTWARE.
-->
<refentry>
<refentryinfo>
<date>Feb 1, 2015</date>
</refentryinfo>
<refmeta>
<refentrytitle>kea-lfc</refentrytitle>
<manvolnum>8</manvolnum>
<refmiscinfo>Kea</refmiscinfo>
</refmeta>
<refnamediv>
<refname>kea-lfc</refname>
<refpurpose>Lease File Cleanup process in Kea</refpurpose>
</refnamediv>
<docinfo>
<copyright>
<year>2015</year>
<holder>Internet Systems Consortium, Inc. ("ISC")</holder>
</copyright>
</docinfo>
<refsynopsisdiv>
<cmdsynopsis>
<command>kea-lfc</command>
<arg><option>-v</option></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsynopsisdiv>
<cmdsynopsis>
<command>kea-lfc</command>
<arg><option>-s</option></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>DESCRIPTION</title>
<para>
The <command>kea-lfc</command> service process removes redundant
information for the files used to provide persistent storage for
the memfile data base back end. The service is written to run as
a stand alone process. While it can be started externally it
should be started by the Kea DHCP servers as desired and required.
</para>
</refsect1>
<refsect1>
<title>ARGUMENTS</title>
<para>The arguments are as follows:</para>
<variablelist>
<varlistentry>
<term><option>-v</option></term>
<listitem><para>
Verbose mode sets the logging level to debug. This is primarily
for development purposes in stand-alone mode.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-c</option></term>
<listitem><para>
Configuration file including the configuration for LFC process.
It may also contain configuration entries for other Kea services.
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>HISTORY</title>
<para>
The <command>kea-lfc</command> process was first coded in January
2015 by the ISC Kea/DHCP team.
</para>
</refsect1>
</refentry><!--
- Local variables:
- mode: sgml
- End:
-->
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <config.h>
#include <lfc/lfc.h>
#include <exceptions/exceptions.h>
#include <log/logger_support.h>
#include <log/logger_manager.h>
//#include <dhcpsrv/cfgmgr.h>
#include <iostream>
using namespace std;
namespace isc {
namespace lfc {
/// @brief Defines the application name, it may be used to locate
/// configuration data and appears in log statements.
const char* lfc::lfc_app_name_ = "DhcpLFC";
/// @brief Defines the executable name.
const char*lfc::lfc_bin_name_ = "kea-lfc";
lfc::lfc()
: dhcp_version_(0), verbose_(false), config_file_(""),
previous_file_(""), copy_file_(""), output_file_("") {
std::cerr << "created lfc" << std::endl;
}
lfc::~lfc() {
std::cerr << "destroyed lfc" << std::endl;
}
void
lfc::launch(int argc, char* argv[], const bool test_mode) {
try {
parseArgs(argc, argv);
} catch (const InvalidUsage& ex) {
usage(ex.what());
throw; // rethrow it
}
std::cerr << "launched lfc" << std::endl;
}
void
lfc::parseArgs(int argc, char* argv[])
{
int ch;
while ((ch = getopt(argc, argv, "46dvVp:i:o:c:")) != -1) {
switch (ch) {
case '4':
// Process DHCPv4 lease files.
dhcp_version_ = 4;
break;
case '6':
// Process DHCPv6 lease files.
dhcp_version_ = 6;
break;
case 'v':
// Print just Kea vesion and exit.
// std::cout << getVersion(false) << std::endl;
exit(EXIT_SUCCESS);
case 'V':
// Print extended Kea vesion and exit.
//std::cout << getVersion(true) << std::endl;
exit(EXIT_SUCCESS);
case 'd':
// Verbose output.
verbose_ = true;
break;
case 'p':
// Previous file name.
if (optarg == NULL) {
isc_throw(InvalidUsage, "Previous file name missing");
}
previous_file_ = optarg;
break;
case 'i':
// Copy file name.
if (optarg == NULL) {
isc_throw(InvalidUsage, "Copy file name missing");
}
copy_file_ = optarg;
break;
case 'o':
// Output file name.
if (optarg == NULL) {
isc_throw(InvalidUsage, "Output file name missing");
}
output_file_ = optarg;
break;
case 'c':
// Previous file name.
if (optarg == NULL) {
isc_throw(InvalidUsage, "Configuration file name missing");
}
config_file_ = optarg;
break;
default:
usage("");
}
}
// Check for extraneous parameters.
if (argc > optind) {
isc_throw(InvalidUsage, "Extraneous parameters.");
}
if (dhcp_version_ == 0) {
isc_throw(InvalidUsage, "DHCP version required");
}
if (previous_file_.empty()) {
isc_throw(InvalidUsage, "Previous file not specified");
}
if (copy_file_.empty()) {
isc_throw(InvalidUsage, "Copy file not specified");
}
if (output_file_.empty()) {
isc_throw(InvalidUsage, "Output file not specified");
}
if (config_file_.empty()) {
isc_throw(InvalidUsage, "Config file not specified");
}
// If verbose is set echo the input information
if (verbose_ == true) {
std::cerr << "Protocol version: " << dhcp_version_ << std::endl
<< "Previous lease file: " << previous_file_ << std::endl
<< "Copy lease file: " << copy_file_ << std::endl
<< "Output lease file: " << output_file_ << std::endl
<< "Config file: " << config_file_ << std::endl;
}
}
void
lfc::pidCheck()
{
}
void
lfc::pidDelete()
{
}
void
lfc::usage(const std::string & text)
{
if (text != "") {
std::cerr << "Usage error: " << text << std::endl;
}
std::cerr << "Usage: " << lfc_bin_name_ << std::endl
<< " [-4|-6] -p file -i file -o file -c file" << std::endl
<< " -4 or -6 clean a set of v4 or v6 lease files" << std::endl
<< " -p <file>: previous lease file" << std::endl
<< " -i <file>: copy of lease file" << std::endl
<< " -o <file>: output lease file" << std::endl
<< " -c <file>: configuration file" << std::endl
<< " -v: print version number and exit" << std::endl
<< " -V: print extended version inforamtion and exit" << std::endl
<< " -d: optional, verbose output " << std::endl
<< std::endl;
}
}; // namespace isc::lfc
}; // namespace isc
//std::string
//isc::dhcp::Daemon::getVersion(bool extended) {
// std::stringstream tmp;
//
// tmp << VERSION;
// if (extended) {
// tmp << std::endl << EXTENDED_VERSION;
//
// @todo print more details (is it Botan or OpenSSL build,
// with or without MySQL/Postgres? What compilation options were
// used? etc)
// }
//
// return (tmp.str());
//}
......@@ -12,8 +12,8 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef LFC_LFC_H
#define LFC_LFC_H
#ifndef LFC_H
#define LFC_H
#include <boost/shared_ptr.hpp>
......@@ -22,6 +22,69 @@
namespace isc {
namespace lfc {
/// @brief Exception thrown when the command line is invalid.
class InvalidUsage : public isc::Exception {
public:
InvalidUsage(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) { };
};
//class lfcBase;
//typedef boost::shared_ptr<lfcBase> lfcBasePtr;
class lfc {
public:
/// @brief Defines the application name, it may be used to locate
/// configuration data and appears in log statements.
static const char* lfc_app_name_;
/// @brief Defines the executable name, by convention this should match
/// the executable name.
static const char* lfc_bin_name_;
/// @brief Constructor
lfc();
/// @brief Destructor
~lfc();
/// @brief Acts as the primary entry point to start execution
/// of the process. Provides the control logic:
///
/// 1. parse command line arguments
/// 2. verifies that it is the only instance
/// 3. creates pid file
/// .... TBD
/// 4. remove pid file
/// 5. exit to the caller
void launch(int argc, char* argv[], const bool test_mode);
/// @brief Process the command line arguments. It is the first
/// step taken after the process has been launched.
void parseArgs(int argc, char* argv[]);
/// @brief Use the pid to determine if there is another instance
/// and create a pid file if we are alone.
void pidCheck();
/// @brief Get rid of the pid file we created earlier
void pidDelete();
/// #brief prints the program usage text to std error.
///
/// @param text is a string message which will preceded the usage text.
/// This is intended to be used for specific usage violation messages.
void usage(const std::string& text);
private:
int dhcp_version_;
bool verbose_;
std::string config_file_;
std::string previous_file_;
std::string copy_file_;
std::string output_file_;
};
}; // namespace isc:lfc
}; // namespace isc
......
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include <lfc/lfc_lfc.h>
namespace isc {
namespace lfc {
}; // namespace isc::lfc
}; // namespace isc
......@@ -13,7 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <config.h>
#include <lfc/lfc_lfc.h>
#include <lfc/lfc.h>
#include <exceptions/exceptions.h>
#include <log/logger_support.h>
#include <log/logger_manager.h>
......@@ -31,16 +31,16 @@ using namespace std;
/// errors, EXIT_FAILURE otherwise.
int main(int argc, char* argv[]) {
int ret = EXIT_SUCCESS;
lfc lfc;
// Instantiate/fetch the lfc application controller singleton.
// DControllerBasePtr& controller = D2Controller::instance();
// Instantiate/fetch the lfc application controller.
// lfc& lfc = lfc::lfc();
// Launch the controller passing in command line arguments.
// Exit program with the controller's return code.
try {
// 'false' value disables test mode.
//controller->launch(argc, argv, false);
std::cerr << "Service started:" << std::endl;
lfc.launch(argc, argv, false);
} catch (const isc::Exception& ex) {
std::cerr << "Service failed:" << ex.what() << std::endl;
ret = EXIT_FAILURE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment