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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 monitoring Monitoring a running PyFCGI
  20. *
  21. * PyFCGI have the ability to listen on a UDP socket, replying to simple
  22. * queries (or simple stats).
  23. */
  24. #ifndef _MONITOR__H___
  25. #define _MONITOR__H___
  26. #include "config.h"
  27. #include <fcgiapp.h> /* fcgi library; put it first*/
  28. #include <netdb.h>
  29. #include <strings.h>
  30. #include <sys/socket.h>
  31. #include <sys/un.h>
  32. #include <netinet/in.h>
  33. #include <arpa/inet.h>
  34. #define UNIX_SOCKPATH_MAX 108
  35. #define PYFCGI_MONITOR_STREAM_BACKLOG 5
  36. typedef struct pyfcgi_monitor_s pyfcgi_monitor_t;
  37. typedef union pyfcgi_monitor_addr_u pyfcgi_monitor_addr_t;
  38. #include "conf.h"
  39. #include "logger.h"
  40. union pyfcgi_monitor_addr_u
  41. {
  42. struct sockaddr_in in;
  43. struct sockaddr_in6 in6;
  44. struct sockaddr_un un;
  45. };
  46. struct pyfcgi_monitor_s
  47. {
  48. int sockserv;
  49. int sockargs[3];
  50. pyfcgi_monitor_addr_t addr;
  51. };
  52. /**@brief Start the stats server monitoring server
  53. * @return PID of the child process and -1 on error
  54. * @note When called the configuration has to be parsed */
  55. pid_t pyfcgi_spawn_monitor();
  56. /**@brief Main function for socket stats server
  57. *
  58. * Create the socket & bind to indicated address. If bind fails, sleep 30s, then
  59. * exit, in order to retry the whole process
  60. */
  61. void pyfcgi_monitor_loop();
  62. void pyfcgi_monitor_stream_loop();
  63. void pyfcgi_monitor_dgram_loop();
  64. /**@brief Check socket URL validity
  65. * @param const char* the URL to check
  66. * @return -1 if error else 0
  67. * @note Logs error using dprintf(2, ...) because this function will
  68. * be called when checking configuration
  69. */
  70. int pyfcgi_monitor_check_sock(const char*);
  71. /**@brief Parse stored socket URL
  72. * @param const char* the URL to parse
  73. * @param int[3] socket creation arguments
  74. * @param pyfcgi_monitor_addr_t the addr to bind to
  75. * @return 0 if no error else -1
  76. * @todo add support for xxx://[IPV6]:port
  77. */
  78. int pyfcgi_monitor_parse_sock(const char*, int[3], pyfcgi_monitor_addr_t*);
  79. /**@brief Parse an addres:port string in a sockaddr_in
  80. * @param const char* the hostname:port string
  81. * @param int socket family
  82. * @param pyfcgi_monitor_addr_t* the addr pointer
  83. * @param int* if not NULL will be set to choosen domain
  84. * @return 0 if no erro else -1
  85. * @todo add support for xxx://[IPV6]:port
  86. */
  87. int pyfcgi_monitor_parse_inet_addr(const char*, int, pyfcgi_monitor_addr_t*,
  88. int*);
  89. #endif