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
24 #include <libtest/common.h>
26 #include <libtest/blobslap_worker.h>
35 #include <sys/types.h>
39 #include <libgearman/gearman.h>
41 #ifndef __INTEL_COMPILER
42 #pragma GCC diagnostic ignored "-Wold-style-cast"
47 class BlobslapWorker
: public Server
51 BlobslapWorker(in_port_t port_arg
) :
52 Server("localhost", port_arg
, "benchmark/blobslap_worker", true)
57 pid_t
get_pid(bool error_is_ok
)
59 if (pid_file().empty())
61 Error
<< "pid_file was empty";
65 Wait
wait(pid_file(), 0);
67 if (error_is_ok
and not wait
.successful())
69 Error
<< "Pidfile was not found:" << pid_file();
73 std::stringstream error_message
;
74 pid_t ret
= get_pid_from_file(pid_file(), error_message
);
76 if (error_is_ok
and is_pid_valid(ret
) == false)
78 Error
<< error_message
.str();
86 if (pid_file().empty())
88 Error
<< "No pid file available";
92 Wait
wait(pid_file(), 0);
93 if (not wait
.successful())
95 Error
<< "Pidfile was not found:" << pid_file();
99 std::stringstream error_message
;
100 pid_t local_pid
= get_pid_from_file(pid_file(), error_message
);
101 if (is_pid_valid(local_pid
) == false)
103 Error
<< error_message
.str();
107 // Use kill to determine is the process exist
108 if (::kill(local_pid
, 0) == 0)
118 return "blobslap_worker";
121 bool has_port_option() const
126 bool has_log_file_option() const
136 bool build(size_t argc
, const char *argv
[]);
142 bool BlobslapWorker::build(size_t argc
, const char *argv
[])
144 std::stringstream arg_buffer
;
146 for (size_t x
= 0 ; x
< argc
; x
++)
154 Server
*build_blobslap_worker(in_port_t try_port
)
156 return new BlobslapWorker(try_port
);
159 } // namespace libtest