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
)
59 pid_t
get_pid(bool error_is_ok
)
61 if (pid_file().empty())
63 Error
<< "pid_file was empty";
67 Wait
wait(pid_file(), 0);
69 if (error_is_ok
and not wait
.successful())
71 Error
<< "Pidfile was not found:" << pid_file();
75 std::stringstream error_message
;
76 pid_t ret
= get_pid_from_file(pid_file(), error_message
);
78 if (error_is_ok
and is_pid_valid(ret
) == false)
80 Error
<< error_message
.str();
88 if (pid_file().empty())
90 Error
<< "No pid file available";
94 Wait
wait(pid_file(), 0);
95 if (not wait
.successful())
97 Error
<< "Pidfile was not found:" << pid_file();
101 std::stringstream error_message
;
102 pid_t local_pid
= get_pid_from_file(pid_file(), error_message
);
103 if (is_pid_valid(local_pid
) == false)
105 Error
<< error_message
.str();
109 // Use kill to determine is the process exist
110 if (::kill(local_pid
, 0) == 0)
120 return "blobslap_worker";
123 const char *executable()
125 return GEARMAND_BLOBSLAP_WORKER
;
128 const char *pid_file_option()
130 return "--pid-file=";
133 const char *daemon_file_option()
138 const char *log_file_option()
140 return "--log-file=";
143 const char *port_option()
153 bool build(int argc
, const char *argv
[]);
159 bool BlobslapWorker::build(int argc
, const char *argv
[])
161 std::stringstream arg_buffer
;
163 for (int x
= 1 ; x
< argc
; x
++)
165 arg_buffer
<< " " << argv
[x
] << " ";
168 set_extra_args(arg_buffer
.str());
175 Server
*build_blobslap_worker(in_port_t try_port
)
177 return new BlobslapWorker(try_port
);