a12df583e7f9db599ac403a2f6b8b006806e5ee0
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <libtest/common.h>
25 #include <libtest/blobslap_worker.h>
26 #include <libtest/killpid.h>
28 using namespace libtest
;
37 #include <sys/types.h>
41 #include <libgearman/gearman.h>
43 #ifndef __INTEL_COMPILER
44 #pragma GCC diagnostic ignored "-Wold-style-cast"
47 using namespace libtest
;
49 class BlobslapWorker
: public Server
53 BlobslapWorker(in_port_t port_arg
) :
54 Server("localhost", port_arg
)
57 pid_t
get_pid(bool error_is_ok
)
59 if (not pid_file().empty())
61 Wait
wait(pid_file(), 0);
63 if (error_is_ok
and not wait
.successful())
65 Error
<< "Pidfile was not found:" << pid_file();
68 return get_pid_from_file(pid_file());
77 if (pid_file().empty())
79 Error
<< "No pid file available";
83 Wait
wait(pid_file(), 0);
84 if (not wait
.successful())
86 Error
<< "Pidfile was not found:" << pid_file();
90 pid_t local_pid
= get_pid_from_file(pid_file());
96 if (::kill(local_pid
, 0) == 0)
106 return "blobslap_worker";
109 const char *executable()
111 return GEARMAND_BLOBSLAP_WORKER
;
114 const char *pid_file_option()
116 return "--pid-file=";
119 const char *daemon_file_option()
124 const char *log_file_option()
129 const char *port_option()
139 bool build(int argc
, const char *argv
[]);
145 bool BlobslapWorker::build(int argc
, const char *argv
[])
147 std::stringstream arg_buffer
;
149 for (int x
= 1 ; x
< argc
; x
++)
151 arg_buffer
<< " " << argv
[x
] << " ";
154 set_extra_args(arg_buffer
.str());
161 Server
*build_blobslap_worker(in_port_t try_port
)
163 return new BlobslapWorker(try_port
);