MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndb_daemon.h
1 /* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 */
16 #ifndef NDB_DAEMON_H
17 #define NDB_DAEMON_H
18 
19 C_MODE_START
20 
21 
22 typedef int (*ndb_daemon_run_t)(int, char**);
23 typedef void (*ndb_daemon_stop_t)(void);
24 
25 /*
26  Used from "mini" main to run an application as a
27  service on windows, where the "run" function will be run
28  as a service if first arg is --service=<service_name>.
29 
30  Defaults to "normal" behaviour which is to call "run" directly
31  with argc/argv
32 
33 */
34 int ndb_daemon_init(int argc, char** argv,
35  ndb_daemon_run_t run, ndb_daemon_stop_t stop,
36  const char* name, const char* display_name);
37 
38 /*
39  To be called at the point where an application needs to daemonize
40  itself.
41 
42  The daemonizing will on most platforms do a fork itself as a daemon.
43  I.e fork, setsid, create pidfile, and redirect all output to logfile.
44 
45  On windows, only create pidfile and redirect.
46 */
47 int ndb_daemonize(const char* pidfile_name, const char *logfile_name);
48 
49 
50 /*
51  To be called when application should exit.
52 
53  Performs an ordered shutdown of service if running as a serevice.
54  */
55 void ndb_daemon_exit(int status);
56 
57 
58 /*
59  if any of the functions in ndb_daemon return non-zero (failure)
60  then ndb_daemon_error contains the error message
61 */
62 
63 extern char ndb_daemon_error[];
64 
65 /*
66  Print the additional arguments available for service
67 */
68 void ndb_service_print_options(const char* name);
69 
70 /*
71  Utility function to make the program wait for debugger at
72  a given location. Very useful for debugging a program
73  started as a service.
74 */
75 void ndb_service_wait_for_debugger(int timeout_sec);
76 
77 C_MODE_END
78 
79 #endif