Reload configuration through control socket
I also kept the SIGHUP handler, which many people will expect to see. The control socket is better, though - it will tell you if there is a problem.
This commit is contained in:
parent
f0a57eab4c
commit
d82fcc88f3
5 changed files with 27 additions and 4 deletions
|
@ -93,9 +93,15 @@ and if
|
|||
.Xr tincd 8
|
||||
didn't succeed to connect to an uplink the first time after it started,
|
||||
it defaults to the maximum time of 15 minutes.
|
||||
.It reload
|
||||
Partially rereads configuration files.
|
||||
Connections to hosts whose host config files are removed are closed.
|
||||
New outgoing connections specified in
|
||||
.Pa tinc.conf
|
||||
will be made.
|
||||
.El
|
||||
.Sh BUGS
|
||||
The "start", "restart", and "reload" commands are not yet implemented.
|
||||
The "start" and "restart" commands are not yet implemented.
|
||||
.Pp
|
||||
If you find any bugs, report them to tinc@tinc-vpn.org.
|
||||
.Sh SEE ALSO
|
||||
|
|
|
@ -130,6 +130,12 @@ static void handle_control_data(struct bufferevent *event, void *data) {
|
|||
goto respond;
|
||||
}
|
||||
|
||||
if(req.type == REQ_RELOAD) {
|
||||
logger(LOG_NOTICE, _("Got '%s' command"), "reload");
|
||||
res.res_errno = reload_configuration();
|
||||
goto respond;
|
||||
}
|
||||
|
||||
logger(LOG_DEBUG, _("Malformed control command received"));
|
||||
res.res_errno = EINVAL;
|
||||
|
||||
|
|
11
src/net.c
11
src/net.c
|
@ -234,13 +234,16 @@ static void sigterm_handler(int signal, short events, void *data) {
|
|||
}
|
||||
|
||||
static void sighup_handler(int signal, short events, void *data) {
|
||||
logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
|
||||
reload_configuration();
|
||||
}
|
||||
|
||||
int reload_configuration(void) {
|
||||
connection_t *c;
|
||||
splay_node_t *node, *next;
|
||||
char *fname;
|
||||
struct stat s;
|
||||
static time_t last_config_check = 0;
|
||||
|
||||
logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
|
||||
|
||||
/* Reread our own configuration file */
|
||||
|
||||
|
@ -250,7 +253,7 @@ static void sighup_handler(int signal, short events, void *data) {
|
|||
if(!read_server_config()) {
|
||||
logger(LOG_ERR, _("Unable to reread configuration file, exitting."));
|
||||
event_loopexit(NULL);
|
||||
return;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
/* Close connections to hosts that have a changed or deleted host config file */
|
||||
|
@ -278,6 +281,8 @@ static void sighup_handler(int signal, short events, void *data) {
|
|||
/* Try to make outgoing connections */
|
||||
|
||||
try_outgoing_connections();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void retry(void) {
|
||||
|
|
|
@ -157,6 +157,7 @@ extern void handle_meta_connection_data(int, short, void *);
|
|||
extern void regenerate_key();
|
||||
extern void purge(void);
|
||||
extern void retry(void);
|
||||
extern int reload_configuration(void);
|
||||
|
||||
#ifndef HAVE_MINGW
|
||||
#define closesocket(s) close(s)
|
||||
|
|
|
@ -92,6 +92,7 @@ static void usage(bool status) {
|
|||
" purge Purge unreachable nodes\n"
|
||||
" debug N Set debug level\n"
|
||||
" retry Retry all outgoing connections\n"
|
||||
" reload Partial reload of configuration\n"
|
||||
"\n"));
|
||||
printf(_("Report bugs to tinc@tinc-vpn.org.\n"));
|
||||
}
|
||||
|
@ -601,6 +602,10 @@ int main(int argc, char *argv[], char *envp[]) {
|
|||
return send_ctl_request_cooked(fd, REQ_RETRY, NULL, 0) != -1;
|
||||
}
|
||||
|
||||
if(!strcasecmp(argv[optind], "reload")) {
|
||||
return send_ctl_request_cooked(fd, REQ_RELOAD, NULL, 0) != -1;
|
||||
}
|
||||
|
||||
fprintf(stderr, _("Unknown command `%s'.\n"), argv[optind]);
|
||||
usage(true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue