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.

monitor.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. /**@defgroup monitor_proc Monitoring process
  20. * @brief Collect informations and run a monitoring server providing statistics
  21. * @ingroup main_proc
  22. */
  23. /**@defgroup monitoring Monitoring server
  24. * @brief A small UDP server for monitoring
  25. *
  26. * PyFCGI have the ability to listen on a UDP socket, replying to simple
  27. * queries (or simple stats).
  28. * @ingroup monitor_proc
  29. */
  30. /**@file monitor.h
  31. * @brief Monitoring server headers
  32. * @ingroup monitoring
  33. */
  34. #ifndef _MONITOR__H___
  35. #define _MONITOR__H___
  36. #include "config.h"
  37. #include <fcgiapp.h> /* fcgi library; put it first*/
  38. #include <netdb.h>
  39. #include <strings.h>
  40. #include <sys/socket.h>
  41. #include <sys/un.h>
  42. #include <netinet/in.h>
  43. #include <arpa/inet.h>
  44. #define UNIX_SOCKPATH_MAX 108
  45. #define PYFCGI_MONITOR_STREAM_BACKLOG 5
  46. typedef struct pyfcgi_monitor_s pyfcgi_monitor_t;
  47. typedef union pyfcgi_monitor_addr_u pyfcgi_monitor_addr_t;
  48. #include "conf.h"
  49. #include "logger.h"
  50. #include "stats.h"
  51. union pyfcgi_monitor_addr_u
  52. {
  53. struct sockaddr_in in;
  54. struct sockaddr_in6 in6;
  55. struct sockaddr_un un;
  56. };
  57. struct pyfcgi_monitor_s
  58. {
  59. int sockserv;
  60. int sockcli;
  61. int sockargs[3];
  62. pyfcgi_monitor_addr_t addr;
  63. };
  64. /**@brief Attempt to init unitialized IPC component
  65. *
  66. * If an error occured it will be logged, and the init should be retry latter.
  67. *
  68. * @note the monitor process uses IPC_WREQS to count requests IPC_SEMST for
  69. * SHM syn and IPC_SHMST for SHM initalization
  70. */
  71. int pyfcgi_monitor_IPC_init();
  72. /**@brief Start the stats server monitoring server
  73. * @return PID of the child process and -1 on error
  74. * @note When called the configuration has to be parsed */
  75. pid_t pyfcgi_spawn_monitor();
  76. /**@brief Main function for socket stats server
  77. *
  78. * Create the socket & bind to indicated address. If bind fails, sleep 30s, then
  79. * exit, in order to retry the whole process
  80. */
  81. void pyfcgi_monitor_loop();
  82. void pyfcgi_monitor_stream_loop();
  83. void pyfcgi_monitor_dgram_loop();
  84. /**@brief Check socket URL validity
  85. * @param sockurl the URL to check
  86. * @return -1 if error else 0
  87. * @note Logs error using dprintf(2, ...) because this function will
  88. * be called when checking configuration
  89. */
  90. int pyfcgi_monitor_check_sock(const char* sockurl);
  91. /**@brief Parse stored socket URL
  92. * @param sockurl the URL to parse
  93. * @param sockargs socket creation arguments
  94. * @param listen_addr the addr to bind to
  95. * @return 0 if no error else -1
  96. * @todo add support for xxx://[IPV6]:port
  97. */
  98. int pyfcgi_monitor_parse_sock(const char* sockurl, int sockargs[3],
  99. pyfcgi_monitor_addr_t* listen_addr);
  100. /**@brief Parse an addres:port string in a sockaddr_in
  101. * @param addr_str the hostname:port string
  102. * @param socktype socket family
  103. * @param listen_addr the addr pointer
  104. * @param domain if not NULL will be set to choosen domain
  105. * @return 0 if no erro else -1
  106. * @todo add support for xxx://[IPV6]:port
  107. */
  108. int pyfcgi_monitor_parse_inet_addr(const char* addr_str, int socktype,
  109. pyfcgi_monitor_addr_t* listen_addr, int* domain);
  110. /**@brief Monitor process sighandler */
  111. void pyfcgi_monitor_sighandler(int signum);
  112. /**@brief Monitor timeout sighandler */
  113. void pyfcgi_monitor_timeout(int signum);
  114. #endif