Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

conf.h 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "config.h"
  24. /**@defgroup conf_internal PYFCGI configuration handling
  25. */
  26. /**@defgroup conf_glob PYFCGI global (for all process) configurations
  27. * @see struct_pyfcgi_conf_s
  28. * @ingroup conf_internal */
  29. #include "logger.h"
  30. /**@defgroup ret_status Function & process return status
  31. */
  32. #define PYFCGI_ERR 16
  33. /**@ingroup ret_status */
  34. #define PYFCGI_WORKER_FAIL 32
  35. /**@ingroup ret_status */
  36. #define PYFCGI_MASTER_FAIL 64
  37. /**@ingroup ret_status */
  38. #define PYFCGI_FATAL 128
  39. #define PYFCGI_NAME "spawn-fcgi [OPTIONS] -- pyfcgi"
  40. #define PYFCGI_SHORT_OPT "Ce:E:w:W:m:l:Svh"
  41. #define PYFCGI_LONG_OPT { \
  42. {"config", required_argument, 0, 'C'},\
  43. {"pymodule", required_argument, 0, 'e'},\
  44. {"pyapp", required_argument, 0, 'E'},\
  45. {"min-worker", required_argument, 0, 'w'},\
  46. {"max-worker", required_argument, 0, 'W'},\
  47. {"max-request", required_argument, 0, 'm'},\
  48. {"log", required_argument, 0, 'L'},\
  49. {"syslog", no_argument, 0, 'S'},\
  50. {"pid-file", required_argument, 0, 'P'},\
  51. {"version", no_argument, 0, 'v'},\
  52. {"help", no_argument, 0, 'h' },\
  53. {0, 0, 0, 0}\
  54. }
  55. #define PYFCGI_OPT_HELP {\
  56. {"Load options from configuration file", "CONFIG"},\
  57. {"Search application function in given python module", "MODULE_NAME"},\
  58. {"Python application entrypoint function name", "FUNC_NAME"},\
  59. {"Minimum worker in the pool", "INT"},\
  60. {"Maximum worker in the pool", "INT"},\
  61. {"Request count after wich the worker is restarted (if 0 never restart)", "INT"},\
  62. {"Add a logfile using syntax : 'LOGFILE[;FILT][;FMT]'", "LOGGER_SPEC"},\
  63. {"Use syslog for logging", NULL},\
  64. {"Create a PID file", "FILENAME"},\
  65. {"Print PyFCGI and Python version and exit", NULL},\
  66. {"Display this help and exit", NULL},\
  67. }
  68. #define PYFCGI_HELP_TEXT "Logger specification format 'LOGFILE[;FILT][;FMT]' with :\n\
  69. \t- LOGFILE the log file name\n\
  70. \t- FILT a number (in decimal or hexadicimal 0xXX) indicating wich\n\
  71. \t facility/level to log\n\
  72. \t- FMT the logline format in a special markup format using fields between { }\n\
  73. \t supported fields are :\n\
  74. \t\t- {datetime} {datetime:SIZE} {datetime:SIZE:FMT} defines a format and a \n\
  75. \t\t constant length for a datetime field. Default : {datetime:25:%F %T%z}\n\
  76. \t\t- {level} the loglevel \n\
  77. \t\t- {facility} the log facility\n\
  78. \t\t- {pid} the process PID\n\
  79. \t\t- {ident} the defined ident (set by process)\n\
  80. \t\t- {msg} the log message (can only appear once)\n\
  81. You can escape { and } by using {{ and }} and all field names can by\n\
  82. abbreviated to one character.\n"
  83. /**@brief Friendly name for @ref struct pyfcgi_conf_s
  84. * @see struct pyfcgi_conf_s */
  85. typedef struct pyfcgi_conf_s pyfcgi_conf_t;
  86. typedef struct pyfcgi_conf_logger_s pyfcgi_conf_logger_t;
  87. typedef struct pyfcgi_context_s pyfcgi_context_t;
  88. struct pyfcgi_context_s {
  89. pid_t pid;
  90. pid_t ppid;
  91. char *pidfile;
  92. };
  93. /**@brief Structure containing configuration
  94. * @ingroup conf_internal
  95. * The structure is used for the global @ref pyfcgi_conf variable.
  96. * @see pyfcgi_conf_t
  97. */
  98. struct pyfcgi_conf_s
  99. {
  100. /**@brief Entrypoint module name
  101. * @ingroup conf_glob */
  102. char *py_entrymod;
  103. /**@brief Entrypoint function name
  104. * @ingroup conf_glob */
  105. char *py_entryfun;
  106. /**@brief Minimum count worker in pool
  107. * @ingroup conf_glob */
  108. int min_wrk;
  109. /**@brief Maximum count workers in pool
  110. * @ingroup conf_glob */
  111. int max_wrk;
  112. /**@brief Maximum request before a worker restarts (0 for no restart)
  113. * @ingroup conf_glob */
  114. int max_reqs;
  115. /**@brief Logger configuration
  116. * @ingroupe conf_glob */
  117. pyfcgi_conf_logger_t logs;
  118. /**@brief Context informations */
  119. pyfcgi_context_t context;
  120. };
  121. /**@brief Configuration globals, inherited from parent to childs */
  122. pyfcgi_conf_t PyFCGI_conf;
  123. /**@brief Print usage on FD 2 (stdout) */
  124. void usage();
  125. /**@brief Print pyfcgi & python version on given fd */
  126. void print_version(int);
  127. /**@brief Parse arguments and store them in conf
  128. * @return 0 if no error */
  129. int parse_args(int argc, char *argv[]);
  130. int parse_optlog(const char*);
  131. #endif