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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 "\n\
  72. Logger specification format 'LOGFILE[;FILT][;FMT]' with :\n\
  73. \t- LOGFILE the log file name\n\
  74. \t- FILT a number (in decimal or hexadicimal 0xXX) indicating wich\n\
  75. \t facility/level to log\n\
  76. \t- FMT the logline format in a special markup format using fields between { }\n\
  77. \t supported fields are :\n\
  78. \t\t- {datetime} {datetime:SIZE} {datetime:SIZE:FMT} defines a format and a \n\
  79. \t\t constant length for a datetime field. Default : {datetime:25:%F %T%z}\n\
  80. \t\t- {level} the loglevel \n\
  81. \t\t- {facility} the log facility\n\
  82. \t\t- {pid} the process PID\n\
  83. \t\t- {ident} the defined ident (set by process)\n\
  84. \t\t- {msg} the log message (can only appear once)\n\
  85. You can escape { and } by using {{ and }} and all field names can by\n\
  86. abbreviated to one character.\n"
  87. #define PYENTRY_DEFAULT_FUN "application"
  88. /**@brief Friendly name for @ref struct pyfcgi_conf_s
  89. * @see struct pyfcgi_conf_s */
  90. typedef struct pyfcgi_conf_s pyfcgi_conf_t;
  91. typedef struct pyfcgi_conf_logger_s pyfcgi_conf_logger_t;
  92. typedef struct pyfcgi_context_s pyfcgi_context_t;
  93. struct pyfcgi_context_s {
  94. pid_t pid;
  95. pid_t ppid;
  96. char *pidfile;
  97. };
  98. /**@brief Structure containing configuration
  99. * @ingroup conf_internal
  100. * The structure is used for the global @ref pyfcgi_conf variable.
  101. * @see pyfcgi_conf_t
  102. */
  103. struct pyfcgi_conf_s
  104. {
  105. /**@brief Entrypoint module name
  106. * @ingroup conf_glob */
  107. char *py_entrymod;
  108. /**@brief Entrypoint function name
  109. * @ingroup conf_glob */
  110. char *py_entryfun;
  111. /**@brief Minimum count worker in pool
  112. * @ingroup conf_glob */
  113. int min_wrk;
  114. /**@brief Maximum count workers in pool
  115. * @ingroup conf_glob */
  116. int max_wrk;
  117. /**@brief Maximum request before a worker restarts (0 for no restart)
  118. * @ingroup conf_glob */
  119. int max_reqs;
  120. /**@brief Logger configuration
  121. * @ingroupe conf_glob */
  122. pyfcgi_conf_logger_t logs;
  123. /**@brief Context informations */
  124. pyfcgi_context_t context;
  125. };
  126. /**@brief Configuration globals, inherited from parent to childs */
  127. pyfcgi_conf_t PyFCGI_conf;
  128. /**@brief Print usage on FD 2 (stdout) */
  129. void usage();
  130. /**@brief Print pyfcgi & python version on given fd */
  131. void print_version(int);
  132. /**@brief Init conf with default values */
  133. void default_conf();
  134. /**@brief Parse arguments and store them in conf
  135. * @return 0 if no error */
  136. int parse_args(int argc, char *argv[]);
  137. int check_entrypoint_import();
  138. int parse_optlog(const char*);
  139. #endif