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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include "stats.h"
  41. union pyfcgi_monitor_addr_u
  42. {
  43. struct sockaddr_in in;
  44. struct sockaddr_in6 in6;
  45. struct sockaddr_un un;
  46. };
  47. struct pyfcgi_monitor_s
  48. {
  49. int sockserv;
  50. int sockcli;
  51. int sockargs[3];
  52. pyfcgi_monitor_addr_t addr;
  53. };
  54. /**@brief Attempt to init unitialized IPC component
  55. *
  56. * If an error occured it will be logged, and the init should be retry latter.
  57. *
  58. * @note the monitor process uses IPC_WREQS to count requests IPC_SEMST for
  59. * SHM syn and IPC_SHMST for SHM initalization
  60. */
  61. int pyfcgi_monitor_IPC_init();
  62. /**@brief Start the stats server monitoring server
  63. * @return PID of the child process and -1 on error
  64. * @note When called the configuration has to be parsed */
  65. pid_t pyfcgi_spawn_monitor();
  66. /**@brief Main function for socket stats server
  67. *
  68. * Create the socket & bind to indicated address. If bind fails, sleep 30s, then
  69. * exit, in order to retry the whole process
  70. */
  71. void pyfcgi_monitor_loop();
  72. void pyfcgi_monitor_stream_loop();
  73. void pyfcgi_monitor_dgram_loop();
  74. /**@brief Check socket URL validity
  75. * @param const char* the URL to check
  76. * @return -1 if error else 0
  77. * @note Logs error using dprintf(2, ...) because this function will
  78. * be called when checking configuration
  79. */
  80. int pyfcgi_monitor_check_sock(const char*);
  81. /**@brief Parse stored socket URL
  82. * @param const char* the URL to parse
  83. * @param int[3] socket creation arguments
  84. * @param pyfcgi_monitor_addr_t the addr to bind to
  85. * @return 0 if no error else -1
  86. * @todo add support for xxx://[IPV6]:port
  87. */
  88. int pyfcgi_monitor_parse_sock(const char*, int[3], pyfcgi_monitor_addr_t*);
  89. /**@brief Parse an addres:port string in a sockaddr_in
  90. * @param const char* the hostname:port string
  91. * @param int socket family
  92. * @param pyfcgi_monitor_addr_t* the addr pointer
  93. * @param int* if not NULL will be set to choosen domain
  94. * @return 0 if no erro else -1
  95. * @todo add support for xxx://[IPV6]:port
  96. */
  97. int pyfcgi_monitor_parse_inet_addr(const char*, int, pyfcgi_monitor_addr_t*,
  98. int*);
  99. void pyfcgi_monitor_sighandler(int signum);
  100. #endif