2 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
3 * Copyright (C) 2006-2009 Brian Aker
6 * Use and distribution licensed under the BSD license. See
7 * the COPYING file in the parent directory for full text.
16 #include <netinet/in.h>
27 std::string _pid_file
;
28 std::string _log_file
;
29 std::string _base_command
; // executable command which include libtool, valgrind, gdb, etc
30 std::string _running
; // Current string being used for system()
35 std::string _hostname
;
36 std::string _extra_args
;
39 Server(const std::string
& hostname
, const in_port_t port_arg
, const bool is_socket_arg
= false);
43 virtual const char *name()= 0;
44 virtual const char *executable()= 0;
45 virtual const char *port_option()= 0;
46 virtual const char *pid_file_option()= 0;
47 virtual const char *daemon_file_option()= 0;
48 virtual const char *log_file_option()= 0;
49 virtual bool is_libtool()= 0;
51 virtual const char *socket_file_option() const
56 virtual bool broken_pid_file()
61 const std::string
& pid_file() const
66 const std::string
& base_command() const
71 const std::string
& log_file() const
76 const std::string
& hostname() const
81 const std::string
& socket() const
86 bool has_socket() const
93 virtual bool ping()= 0;
95 virtual pid_t
get_pid(bool error_is_ok
= false)= 0;
97 virtual bool build(int argc
, const char *argv
[])= 0;
99 in_port_t
port() const
104 bool has_port() const
109 // Reset a server if another process has killed the server
117 void set_extra_args(const std::string
&arg
);
119 bool args(std::string
& options
);
133 bool check_pid(pid_t pid_arg
) const
135 return (pid_arg
> 1);
138 bool is_socket() const
140 return _hostname
[0] == '/';
143 const std::string
running() const
148 std::string
log_and_pid();
150 bool kill(pid_t pid_arg
);
152 bool command(std::string
& command_arg
);
158 bool is_valgrind() const;
159 bool is_debug() const;
162 bool set_socket_file();
163 void rebuild_base_command();
167 std::ostream
& operator<<(std::ostream
& output
, const libtest::Server
&arg
);
169 class server_startup_st
172 std::string server_list
;
177 std::vector
<Server
*> servers
;
179 server_startup_st() :
183 bool start_socket_server(const std::string
& server_type
, const in_port_t try_port
, int argc
, const char *argv
[]);
185 std::string
option_string() const;
189 return servers
.size();
192 bool is_debug() const;
193 bool is_valgrind() const;
195 void shutdown(bool remove
= false);
196 void push_server(Server
*);
197 Server
*pop_server();
199 ~server_startup_st();
202 bool server_startup(server_startup_st
&, const std::string
&, in_port_t try_port
, int argc
, const char *argv
[]);
204 } // namespace libtest