Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

conf.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright (C) 2019 Weber Yann
  3. *
  4. * This file is part of PyFCGI.
  5. *
  6. * PyFCGI is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * PyFCGI is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PyFCGI. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __CONF_H___
  20. #define __CONF_H___
  21. #include <unistd.h>
  22. #include <getopt.h>
  23. #include <sys/types.h>
  24. #include <sys/wait.h>
  25. #include "config.h"
  26. /**@defgroup conf_internal PYFCGI configuration handling
  27. */
  28. /**@defgroup conf_glob PYFCGI global (for all process) configurations
  29. * @see struct_pyfcgi_conf_s
  30. * @ingroup conf_internal */
  31. #include "logger.h"
  32. #include "pyutils.h"
  33. /**@defgroup ret_status Function & process return status
  34. */
  35. #define PYFCGI_ERR 16
  36. /**@ingroup ret_status */
  37. #define PYFCGI_WORKER_FAIL 32
  38. /**@ingroup ret_status */
  39. #define PYFCGI_MASTER_FAIL 64
  40. /**@ingroup ret_status */
  41. #define PYFCGI_FATAL 128
  42. #define PYFCGI_NAME "spawn-fcgi [OPTIONS] -- pyfcgi"
  43. #define PYFCGI_SHORT_OPT "Ce:E:w:W:m:l:Svh"
  44. #define PYFCGI_LONG_OPT { \
  45. {"config", required_argument, 0, 'C'},\
  46. {"pymodule", required_argument, 0, 'e'},\
  47. {"pyapp", required_argument, 0, 'E'},\
  48. {"min-worker", required_argument, 0, 'w'},\
  49. {"max-worker", required_argument, 0, 'W'},\
  50. {"max-request", required_argument, 0, 'm'},\
  51. {"log", required_argument, 0, 'L'},\
  52. {"syslog", no_argument, 0, 'S'},\
  53. {"pid-file", required_argument, 0, 'P'},\
  54. {"version", no_argument, 0, 'v'},\
  55. {"help", no_argument, 0, 'h' },\
  56. {0, 0, 0, 0}\
  57. }
  58. #define PYFCGI_OPT_HELP {\
  59. {"Load options from configuration file", "CONFIG"},\
  60. {"Search application function in given python module", "MODULE_NAME"},\
  61. {"Python application entrypoint function name", "FUNC_NAME"},\
  62. {"Minimum worker in the pool", "INT"},\
  63. {"Maximum worker in the pool", "INT"},\
  64. {"Request count after wich the worker is restarted (if 0 never restart)", "INT"},\
  65. {"Add a logfile using syntax : 'LOGFILE[;FILT][;FMT]'", "LOGGER_SPEC"},\
  66. {"Use syslog for logging", NULL},\
  67. {"Create a PID file", "FILENAME"},\
  68. {"Print PyFCGI and Python version and exit", NULL},\
  69. {"Display this help and exit", NULL},\
  70. }
  71. #define PYFCGI_HELP_TEXT "Logger specification format 'LOGFILE[;FILT][;FMT]' with :\n\
  72. \t- LOGFILE the log file name\n\
  73. \t- FILT a number (in decimal or hexadicimal 0xXX) indicating wich\n\
  74. \t facility/level to log\n\
  75. \t- FMT the logline format in a special markup format using fields between { }\n\
  76. \t supported fields are :\n\
  77. \t\t- {datetime} {datetime:SIZE} {datetime:SIZE:FMT} defines a format and a \n\
  78. \t\t constant length for a datetime field. Default : {datetime:25:%F %T%z}\n\
  79. \t\t- {level} the loglevel \n\
  80. \t\t- {facility} the log facility\n\
  81. \t\t- {pid} the process PID\n\
  82. \t\t- {ident} the defined ident (set by process)\n\
  83. \t\t- {msg} the log message (can only appear once)\n\
  84. You can escape { and } by using {{ and }} and all field names can by\n\
  85. abbreviated to one character.\n"
  86. #define PYENTRY_DEFAULT_FUN "application"
  87. /**@brief Friendly name for @ref struct pyfcgi_conf_s
  88. * @see struct pyfcgi_conf_s */
  89. typedef struct pyfcgi_conf_s pyfcgi_conf_t;
  90. typedef struct pyfcgi_conf_logger_s pyfcgi_conf_logger_t;
  91. typedef struct pyfcgi_context_s pyfcgi_context_t;
  92. struct pyfcgi_context_s {
  93. pid_t pid;
  94. pid_t ppid;
  95. char *pidfile;
  96. };
  97. /**@brief Structure containing configuration
  98. * @ingroup conf_internal
  99. * The structure is used for the global @ref pyfcgi_conf variable.
  100. * @see pyfcgi_conf_t
  101. */
  102. struct pyfcgi_conf_s
  103. {
  104. /**@brief Entrypoint module name
  105. * @ingroup conf_glob */
  106. char *py_entrymod;
  107. /**@brief Entrypoint function name
  108. * @ingroup conf_glob */
  109. char *py_entryfun;
  110. /**@brief Minimum count worker in pool
  111. * @ingroup conf_glob */
  112. int min_wrk;
  113. /**@brief Maximum count workers in pool
  114. * @ingroup conf_glob */
  115. int max_wrk;
  116. /**@brief Maximum request before a worker restarts (0 for no restart)
  117. * @ingroup conf_glob */
  118. int max_reqs;
  119. /**@brief Logger configuration
  120. * @ingroupe conf_glob */
  121. pyfcgi_conf_logger_t logs;
  122. /**@brief Context informations */
  123. pyfcgi_context_t context;
  124. };
  125. /**@brief Configuration globals, inherited from parent to childs */
  126. pyfcgi_conf_t PyFCGI_conf;
  127. /**@brief Print usage on FD 2 (stdout) */
  128. void usage();
  129. /**@brief Print pyfcgi & python version on given fd */
  130. void print_version(int);
  131. /**@brief Init conf with default values */
  132. void default_conf();
  133. /**@brief Parse arguments and store them in conf
  134. * @return 0 if no error */
  135. int parse_args(int argc, char *argv[]);
  136. int check_entrypoint_import();
  137. int parse_optlog(const char*);
  138. #endif