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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #define PYENTRY_DEFAULT_FUN "application"
  84. /**@brief Friendly name for @ref struct pyfcgi_conf_s
  85. * @see struct pyfcgi_conf_s */
  86. typedef struct pyfcgi_conf_s pyfcgi_conf_t;
  87. typedef struct pyfcgi_conf_logger_s pyfcgi_conf_logger_t;
  88. typedef struct pyfcgi_context_s pyfcgi_context_t;
  89. struct pyfcgi_context_s {
  90. pid_t pid;
  91. pid_t ppid;
  92. char *pidfile;
  93. };
  94. /**@brief Structure containing configuration
  95. * @ingroup conf_internal
  96. * The structure is used for the global @ref pyfcgi_conf variable.
  97. * @see pyfcgi_conf_t
  98. */
  99. struct pyfcgi_conf_s
  100. {
  101. /**@brief Entrypoint module name
  102. * @ingroup conf_glob */
  103. char *py_entrymod;
  104. /**@brief Entrypoint function name
  105. * @ingroup conf_glob */
  106. char *py_entryfun;
  107. /**@brief Minimum count worker in pool
  108. * @ingroup conf_glob */
  109. int min_wrk;
  110. /**@brief Maximum count workers in pool
  111. * @ingroup conf_glob */
  112. int max_wrk;
  113. /**@brief Maximum request before a worker restarts (0 for no restart)
  114. * @ingroup conf_glob */
  115. int max_reqs;
  116. /**@brief Logger configuration
  117. * @ingroupe conf_glob */
  118. pyfcgi_conf_logger_t logs;
  119. /**@brief Context informations */
  120. pyfcgi_context_t context;
  121. };
  122. /**@brief Configuration globals, inherited from parent to childs */
  123. pyfcgi_conf_t PyFCGI_conf;
  124. /**@brief Print usage on FD 2 (stdout) */
  125. void usage();
  126. /**@brief Print pyfcgi & python version on given fd */
  127. void print_version(int);
  128. /**@brief Init conf with default values */
  129. void default_conf();
  130. /**@brief Parse arguments and store them in conf
  131. * @return 0 if no error */
  132. int parse_args(int argc, char *argv[]);
  133. int parse_optlog(const char*);
  134. #endif