#include "citadel_dirs.h"
-// yeah, this wouldn't work in a multithreaded program.
+// support for getz() -- (globals would not be appropriate in a multithreaded program)
static int gmaxlen = 0;
static char *gdeftext = NULL;
getz(yesno, 1, NULL, "Do you wish to continue? ");
puts(yesno);
if (tolower(yesno[0]) != 'y') {
- cmdexit = 1;
+ cmdexit = 101;
}
if (!cmdexit) {
printf("Checking connectivity to Citadel in %s...\n", ctdldir);
local_admin_socket = uds_connectsock("citadel-admin.socket");
if (local_admin_socket < 0) {
- cmdexit = 1;
+ cmdexit = 102;
}
}
serv_gets(local_admin_socket, buf);
puts(buf);
if (buf[0] != '2') {
- cmdexit = 1;
+ cmdexit = 103;
}
}
serv_gets(local_admin_socket, buf);
puts(buf);
if (buf[0] != '2') {
- cmdexit = 1;
+ cmdexit = 104;
}
}
remote_server_socket = tcp_connectsock(remote_host, remote_port);
if (remote_server_socket < 0) {
- cmdexit = 1;
+ cmdexit = 105;
}
}
serv_gets(remote_server_socket, buf);
puts(buf);
if (buf[0] != '2') {
- cmdexit = 1;
+ cmdexit = 106;
}
}
serv_gets(remote_server_socket, buf);
puts(buf);
if (buf[0] != '3') {
- cmdexit = 1;
+ cmdexit = 107;
}
}
serv_gets(remote_server_socket, buf);
puts(buf);
if (buf[0] != '2') {
- cmdexit = 1;
+ cmdexit = 108;
}
}
serv_gets(remote_server_socket, buf);
if (buf[0] != '1') {
printf("\n\033[31m%s\033[0m\n", buf);
- cmdexit = 3;
+ cmdexit = 109;
}
}
serv_gets(local_admin_socket, buf);
if (buf[0] != '4') {
printf("\n\033[31m%s\033[0m\n", buf);
- cmdexit = 3;
+ cmdexit = 110;
}
}
if ( (cmdexit == 0) && (progress < 100) ) {
printf("\033[31mERROR: source stream ended before 100 percent of data was received.\033[0m\n");
- ctdlmigrate_exit(86);
+ cmdexit = 111;
}
- // FIXME restart the local server here
+ if (!cmdexit) {
+ printf("\033[36mMigration is complete. Restarting the target server.\033[0m\n");
+ serv_puts(local_admin_socket, "DOWN 1");
+ serv_gets(local_admin_socket, buf);
+ puts(buf);
+ printf("\033[36mIt is recommended that you shut down the source server now.\033[0m\n");
+ printf("\033[36mRemember to copy over your SSL keys and file libraries if appropriate.\033[0m\n");
+ }
close(remote_server_socket);
close(local_admin_socket);
-
-/*
- * Main source module for the Citadel server
- *
- * Copyright (c) 1987-2018 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
+// System management commands for Citadel server
+//
+// Copyright (c) 1987-2021 by the citadel.org team
+//
+// This program is open source software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License, version 3.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
#include <stdio.h>
#include <libcitadel.h>
#include "ctdl_module.h"
-/*
- * Shut down the server
- */
+// Shut down or restart the server
void cmd_down(char *argbuf) {
char *Reply ="%d Shutting down server. Goodbye.\n";
if (CtdlAccessCheck(ac_aide)) return;
- if (!IsEmptyStr(argbuf))
- {
+ if (!IsEmptyStr(argbuf)) {
int state = CIT_OK;
restart_server = extract_int(argbuf, 0);
}
-/*
- * Halt the server without exiting the server process.
- */
+// Halt the server without exiting the server process.
void cmd_halt(char *argbuf) {
-
if (CtdlAccessCheck(ac_aide)) return;
cprintf("%d Halting server. Goodbye.\n", CIT_OK);
}
-/*
- * Schedule or cancel a server shutdown
- */
-void cmd_scdn(char *argbuf)
-{
+// Schedule or cancel a server shutdown
+void cmd_scdn(char *argbuf) {
int new_state;
int state = CIT_OK;
char *Reply = "%d %d\n";
}
-/*****************************************************************************/
-/* MODULE INITIALIZATION STUFF */
-/*****************************************************************************/
+// ****************************************************************************
+// * MODULE INITIALIZATION STUFF *
+// ****************************************************************************
CTDL_MODULE_INIT(syscmd)
{
CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
}
- /* return our id for the Log */
+ // return our id for the log
return "syscmd";
}