1
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
* Gearmand client and server library.
5
* Copyright (C) 2011 Data Differential, http://datadifferential.com/
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions are
12
* * Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* * Redistributions in binary form must reproduce the above
16
* copyright notice, this list of conditions and the following disclaimer
17
* in the documentation and/or other materials provided with the
20
* * The names of its contributors may not be used to endorse or
21
* promote products derived from this software without specific prior
24
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47
#include <sys/socket.h>
70
#ifdef HAVE_SYS_RESOURCE_H
71
#include <sys/resource.h>
73
#ifdef HAVE_SYS_STAT_H
76
#ifdef HAVE_SYS_TYPES_H
77
#include <sys/types.h>
83
#include <libgearman-1.0/protocol.h>
84
#include <boost/program_options.hpp>
86
#include <util/instance.hpp>
87
#include <util/string.hpp>
89
using namespace datadifferential;
92
This is a very quickly build application, I am just tired of telneting to the port.
95
class Finish : public util::Instance::Finish
98
bool call(bool success, const std::string &response)
102
if (response.empty())
104
std::cout << "OK" << std::endl;
108
std::cout << response;
111
else if (not response.empty())
113
std::cerr << "Error: " << response;
118
std::cerr << "Error" << std::endl;
127
int main(int args, char *argv[])
129
boost::program_options::options_description desc("Options");
134
("help", "Options related to the program.")
135
("host,h", boost::program_options::value<std::string>(&host)->default_value("localhost"),"Connect to the host")
136
("port,p", boost::program_options::value<std::string>(&port)->default_value(GEARMAN_DEFAULT_TCP_PORT_STRING), "Port number or service to use for connection")
137
("server-version", "Fetch the version number for the server.")
138
("server-verbose", "Fetch the verbose setting for the server.")
139
("create-function", boost::program_options::value<std::string>(), "Create the function from the server.")
140
("drop-function", boost::program_options::value<std::string>(), "Drop the function from the server.")
141
("getpid", "Get Process ID for the server.")
142
("status", "Status for the server.")
143
("workers", "Workers for the server.")
144
("shutdown", "Shutdown server.")
147
boost::program_options::variables_map vm;
150
boost::program_options::store(boost::program_options::parse_command_line(args, argv, desc), vm);
151
boost::program_options::notify(vm);
153
catch(std::exception &e)
155
std::cout << argv[0] << " : " << e.what() << std::endl;
156
std::cout << std::endl << desc << std::endl;
160
util::Instance instance(host, port);
161
instance.set_finish(new Finish);
163
if (vm.count("help"))
165
std::cout << desc << std::endl;
169
if (vm.count("shutdown"))
171
instance.push(new util::Operation(util_literal_param("shutdown\r\n")));
174
if (vm.count("status"))
176
instance.push(new util::Operation(util_literal_param("status\r\n")));
179
if (vm.count("workers"))
181
instance.push(new util::Operation(util_literal_param("workers\r\n")));
184
if (vm.count("server-version"))
186
instance.push(new util::Operation(util_literal_param("version\r\n")));
189
if (vm.count("server-verbose"))
191
instance.push(new util::Operation(util_literal_param("verbose\r\n")));
194
if (vm.count("drop-function"))
196
std::string execute(util_literal_param("drop function "));
197
execute.append(vm["drop-function"].as<std::string>());
198
execute.append("\r\n");
199
instance.push(new util::Operation(execute.c_str(), execute.size()));
202
if (vm.count("create-function"))
204
std::string execute(util_literal_param("create function "));
205
execute.append(vm["create-function"].as<std::string>());
206
execute.append("\r\n");
207
instance.push(new util::Operation(execute.c_str(), execute.size()));
210
if (vm.count("getpid"))
212
instance.push(new util::Operation(util_literal_param("getpid\r\n")));