mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-5536: add systemd socket activation
Systemd has a socket activation feature where a mariadb.socket definition defines the sockets to listen to, and passes those file descriptors directly to mariadbd to use when a connection occurs. The new functionality is utilized when starting as follows: systemctl start mariadb.socket The mariadb.socket definition only needs to contain the network information, ListenStream= directives, the mariadb.service definition is still used for service instigation. When mariadbd is started in this way, the socket, port, bind-address backlog are all assumed to be self contained in the mariadb.socket definition and as such the mariadb settings and command line arguments of these network settings are ignored. See man systemd.socket for how to limit this to specific ports. Extra ports, those specified with extra_port in socket activation mode, are those with a FileDescriptorName=extra. These need to be in a separate service name like mariadb-extra.socket and these require a Service={mariadb.service} directive to map to the original service. Extra ports need systemd v227 or greater (not RHEL/Centos7 - v219) when FileDescriptorName= was added, otherwise the extra ports are treated like ordinary ports. The number of sockets isn't limited when using systemd socket activation (except by operating system limits on file descriptors and a minimal amount of memory used per file descriptor). The systemd sockets passed can include any ownership or permissions, including those the mariadbd process wouldn't normally have the permission to create. This implementation is compatible with mariadb.service definitions. Those services started with: systemctl start mariadb.service does actually start the mariadb.service and used all the my.cnf settings of sockets and ports like it previously did.
This commit is contained in:
committed by
Daniel Black
parent
fa0ad2fb11
commit
460d480c74
@@ -304,6 +304,22 @@ inline_mysql_socket_set_state(MYSQL_SOCKET socket, enum PSI_socket_state state)
|
||||
}
|
||||
#endif /* HAVE_PSI_SOCKET_INTERFACE */
|
||||
|
||||
/**
|
||||
@def mysql_socket_fd(K, F)
|
||||
Create a socket.
|
||||
@c mysql_socket_fd is a replacement for @c socket.
|
||||
@param K PSI_socket_key for this instrumented socket
|
||||
@param F File descriptor
|
||||
*/
|
||||
|
||||
#ifdef HAVE_PSI_SOCKET_INTERFACE
|
||||
#define mysql_socket_fd(K, F) \
|
||||
inline_mysql_socket_fd(K, F)
|
||||
#else
|
||||
#define mysql_socket_fd(K, F) \
|
||||
inline_mysql_socket_fd(F)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@def mysql_socket_socket(K, D, T, P)
|
||||
Create a socket.
|
||||
@@ -578,6 +594,39 @@ static inline void inline_mysql_socket_register(
|
||||
}
|
||||
#endif
|
||||
|
||||
/** mysql_socket_fd */
|
||||
|
||||
static inline MYSQL_SOCKET
|
||||
inline_mysql_socket_fd
|
||||
(
|
||||
#ifdef HAVE_PSI_SOCKET_INTERFACE
|
||||
PSI_socket_key key,
|
||||
#endif
|
||||
int fd)
|
||||
{
|
||||
MYSQL_SOCKET mysql_socket= MYSQL_INVALID_SOCKET;
|
||||
mysql_socket.fd= fd;
|
||||
|
||||
DBUG_ASSERT(mysql_socket.fd != INVALID_SOCKET);
|
||||
#ifdef HAVE_PSI_SOCKET_INTERFACE
|
||||
mysql_socket.m_psi= PSI_SOCKET_CALL(init_socket)
|
||||
(key, (const my_socket*)&mysql_socket.fd, NULL, 0);
|
||||
#endif
|
||||
/**
|
||||
Currently systemd socket activation is the user of this
|
||||
function. Its API (man sd_listen_fds) says FD_CLOSE_EXEC
|
||||
is already called. If there becomes another user, we
|
||||
can call it again without detriment.
|
||||
|
||||
If needed later:
|
||||
#if defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
|
||||
(void) fcntl(mysql_socket.fd, F_SETFD, FD_CLOEXEC);
|
||||
#endif
|
||||
*/
|
||||
|
||||
return mysql_socket;
|
||||
}
|
||||
|
||||
/** mysql_socket_socket */
|
||||
|
||||
static inline MYSQL_SOCKET
|
||||
|
Reference in New Issue
Block a user