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>
24 #include <libtest/blobslap_worker.h>
25 #include <libtest/killpid.h>
27 using namespace libtest
;
36 #include <sys/types.h>
40 #include <libgearman/gearman.h>
42 #ifndef __INTEL_COMPILER
43 #pragma GCC diagnostic ignored "-Wold-style-cast"
46 using namespace libtest
;
48 class BlobslapWorker
: public Server
52 BlobslapWorker(in_port_t port_arg
) :
53 Server("localhost", port_arg
)
56 pid_t
get_pid(bool error_is_ok
)
58 if (not pid_file().empty())
60 Wait
wait(pid_file(), 0);
62 if (error_is_ok
and not wait
.successful())
64 Error
<< "Pidfile was not found:" << pid_file();
67 return get_pid_from_file(pid_file());
76 if (pid_file().empty())
78 Error
<< "No pid file available";
82 Wait
wait(pid_file(), 0);
83 if (not wait
.successful())
85 Error
<< "Pidfile was not found:" << pid_file();
89 pid_t local_pid
= get_pid_from_file(pid_file());
95 if (::kill(local_pid
, 0) == 0)
105 return "blobslap_worker";
108 const char *executable()
110 return GEARMAND_BLOBSLAP_WORKER
;
113 const char *pid_file_option()
115 return "--pid-file=";
118 const char *daemon_file_option()
123 const char *log_file_option()
128 const char *port_option()
138 bool build(int argc
, const char *argv
[]);
144 bool BlobslapWorker::build(int argc
, const char *argv
[])
146 std::stringstream arg_buffer
;
148 for (int x
= 1 ; x
< argc
; x
++)
150 arg_buffer
<< " " << argv
[x
] << " ";
153 set_extra_args(arg_buffer
.str());
160 Server
*build_blobslap_worker(in_port_t try_port
)
162 return new BlobslapWorker(try_port
);