Hi,
during warmup of a monitored process monit should ignore all connection checks. Tomcat, for example, depending on how many webapps are to be deployed, requires some time to bring up the listening port and to answer to monit's queries. Monit will restart tomcat over and over unless the timeout is set high enough. Though, in production use, we don't want to use large timeouts. When applying "monit-start_timeout.patch" check_process will return TRUE while the process uptime is still below the start timeout.
One of our requirements is to monitor sockets and to check their file permissions. So we need monit to handle sockets just as regular files. The file "monit-socket.patch" is for that purpose.
When trying to monitor mysql-proxy you'll probably encounter a "2007 protocol mismatch" error since mysql-proxy does not support the old mysql4.0 protocol monit uses. Also, a username is required upon connection. "monit-mysql41.patch" makes monit use the mysql4.1 protocol which is valid up to recent mysql releases. Monit connects as user "M" without password, but this mysql user doesn't need to exist.
Kind regards, Philippe
use mysql 4.1 protocol when authenticating. This is required for checking mysql-proxy. Philippe Kueck <projects at unixadm dot org> --- src/protocols/mysql.c.mysql41 +++ src/protocols/mysql.c @@ -51,56 +51,39 @@ */ int check_mysql(Socket_T socket) { - unsigned char buf[STRLEN]; - - unsigned char requestLogin[10] = { - 0x06, /** Packet Length */ - 0x00, - 0x00, - - 0x01, /** Packet Number */ - - 0x00, /** Flags */ - 0x00, /** Max Packet */ - 0x00, - 0x00, - - 0x00, /** Username*/ + unsigned char buf[STRLEN]; - 0x00 /** Password*/ + unsigned char requestLogin[39] = { + 0x23, 0x00, 0x00, // packet_length, 3 bytes + 0x01, // packet_number, 1 byte + 0x00, 0xa2, 0x00, 0x00, // client_flags, 4 bytes (do+auth 4.1, transact) + 0x00, 0x00, 0x00, 0x40, // max_packet_size, 4 bytes + 0x08, // charset_number (latin1), 1 byte + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // filler, 23 bytes + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4d, 0x00, // user "M" null terminated, 2 bytes + 0x00, // scramble, 1 byte }; unsigned char requestPing[5] = { - 0x01, /** Packet Length */ - 0x00, - 0x00, - - 0x00, /** Packet Number */ - - 0x0E /** Command Ping */ + 0x01, 0x00, 0x00, // packet_length, 3 bytes + 0x00, // packet_number, 1 byte + 0x0e // command ping (14), 1 byte }; unsigned char responsePing[5] = { - 0x03, /** Packet Length */ - 0x00, - 0x00, - - 0x01, /** Packet Number */ - - 0x00 /** Response Code OK */ - - /** Padding Ignored */ + 0x07, 0x00, 0x00, // packet_length, 3 bytes + 0x01, // packet_number, 1 byte + 0x00 // affected_rows, 1 byte + // remaining 4 bytes ignored }; unsigned char requestQuit[5] = { - 0x01, /** Packet Length */ - 0x00, - 0x00, - - 0x00, /** Packet Number */ - - 0x01 /** Command Quit */ + 0x01, 0x00, 0x00, // packet_length, 3 bytes + 0x00, // packet_number, 1 byte + 0x01 // command quit (1), 1 byte }; ASSERT(socket);
run file checks on socket files also, which is needed for monitoring socket file permissions and ownership. Philippe Kueck <projects at unixadm dot org> --- src/file.c.socket +++ src/file.c @@ -145,6 +145,7 @@ time_t file_getTimestamp(char *object, m if(! stat(object, &buf)) { if(((type == S_IFREG) && S_ISREG(buf.st_mode)) || ((type == S_IFDIR) && S_ISDIR(buf.st_mode)) || + ((type == S_IFSOCK) && S_ISSOCK(buf.st_mode)) || ((type == (S_IFREG|S_IFDIR)) && (S_ISREG(buf.st_mode) || S_ISDIR(buf.st_mode))) ) { @@ -273,6 +274,22 @@ int file_isFifo(char *fifo) { /** + * Check if this is a socket + * @param socket A path to the socket to check + * @return TRUE if socket exist, otherwise FALSE + */ +int file_isSocket(char *socket) { + + struct stat buf; + + ASSERT(socket); + + return (stat(socket, &buf) == 0 && S_ISSOCK(buf.st_mode)); + +} + + +/** * Check if the file exist on the system * @file A path to the file to check * @return TRUE if file exist otherwise FALSE @@ -308,8 +325,8 @@ int file_checkStat(char *filename, char LogError("%s: Cannot stat the %s '%s' -- %s\n", prog, description, filename, STRERROR); return FALSE; } - if(!S_ISREG(buf.st_mode)) { - LogError("%s: The %s '%s' is not a regular file.\n", prog, description, filename); + if(!S_ISREG(buf.st_mode) && !S_ISSOCK(buf.st_mode)) { + LogError("%s: The %s '%s' is not a regular file nor a socket.\n", prog, description, filename); return FALSE; } if(buf.st_uid != geteuid()) { --- src/file.h.socket +++ src/file.h @@ -101,6 +101,14 @@ int file_isFifo(char *fifo); /** + * Check if this is a socket + * @param socket A path to the socket to check + * @return TRUE if socket exist, otherwise FALSE + */ +int file_isSocket(char *socket); + + +/** * Check if the file exist on the system * @file A path to the file to check * @return TRUE if file exist otherwise FALSE --- src/validate.c.socket +++ src/validate.c @@ -312,12 +312,12 @@ int check_file(Service_T s) { Event_post(s, Event_Nonexist, STATE_SUCCEEDED, s->action_NONEXIST, "file exist"); } - if (!S_ISREG(s->inf->st_mode)) { - Event_post(s, Event_Invalid, STATE_FAILED, s->action_INVALID, "is not a regular file"); + if (!S_ISREG(s->inf->st_mode) && !S_ISSOCK(s->inf->st_mode)) { + Event_post(s, Event_Invalid, STATE_FAILED, s->action_INVALID, "is neither a regular file nor a socket"); return FALSE; } else { - DEBUG("'%s' is a regular file\n", s->name); - Event_post(s, Event_Invalid, STATE_SUCCEEDED, s->action_INVALID, "is a regular file"); + DEBUG("'%s' is a regular file or socket\n", s->name); + Event_post(s, Event_Invalid, STATE_SUCCEEDED, s->action_INVALID, "is a regular file or socket"); } if (s->checksum)
Do not run connection checks during startup timeout Philippe Kueck <projects at unixadm dot org> --- src/validate.c.timeout +++ src/validate.c @@ -213,6 +213,8 @@ int check_process(Service_T s) { /* Test each host:port and protocol in the service's portlist */ if (s->portlist) + /* skip further tests during startup timeout */ + if (s->inf->priv.process.uptime < s->start->timeout) return TRUE; for (pp = s->portlist; pp; pp = pp->next) check_connection(s, pp);
_______________________________________________ monit-dev mailing list monit-dev@nongnu.org https://lists.nongnu.org/mailman/listinfo/monit-dev