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