Skip to content

Commit

Permalink
Support seafevents.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuihaikuo committed Jan 7, 2019
1 parent 106ee11 commit a0c393f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions controller/seafile-controller.c
Expand Up @@ -35,6 +35,8 @@ char *topdir = NULL;

char *seafile_ld_library_path = NULL;

gboolean has_seafevents = TRUE;

static const char *short_opts = "hvftc:d:l:g:G:P:F:";
static const struct option long_opts[] = {
{ "help", no_argument, NULL, 'h', },
Expand Down Expand Up @@ -348,6 +350,53 @@ setup_env ()
setup_python_path();
}

static int
start_seafevents() {
if (!has_seafevents)
return 0;

static char *seafevents_config_file = NULL;
static char *seafevents_log_file = NULL;

if (seafevents_config_file == NULL)
seafevents_config_file = g_build_filename (topdir,
"conf/seafevents.conf",
NULL);

if (!g_file_test (seafevents_config_file, G_FILE_TEST_EXISTS)) {
seaf_warning("No seafevents.\n");
has_seafevents = FALSE;
g_free (seafevents_config_file);
return 0;
}

if (seafevents_log_file == NULL)
seafevents_log_file = g_build_filename (ctl->logdir,
"seafevents.log",
NULL);

char *argv[] = {
(char *)get_python_executable(),
"-m", "seafevents.main",
"--config-file", seafevents_config_file,
"--logfile", seafevents_log_file,
"-P", ctl->pidfile[PID_SEAFEVENTS],
NULL
};

int pid = spawn_process (argv);

g_free (seafevents_config_file);
g_free (seafevents_log_file);

if (pid <= 0) {
seaf_warning ("Failed to spawn seafevents.\n");
return -1;
}

return 0;
}

static int
start_seafdav() {
static char *seafdav_log_file = NULL;
Expand Down Expand Up @@ -446,6 +495,11 @@ check_process (void *data)
}
}

if (has_seafevents && need_restart(PID_SEAFEVENTS)) {
seaf_message ("seafevents need restart...\n");
start_seafevents ();
}

return TRUE;
}

Expand Down Expand Up @@ -541,6 +595,11 @@ on_ccnet_connected ()
if (start_seaf_server () < 0)
controller_exit(1);

if (has_seafevents && need_restart(PID_SEAFEVENTS)) {
if (start_seafevents() < 0)
controller_exit(1);
}

if (ctl->seafdav_config.enabled) {
if (need_restart(PID_SEAFDAV)) {
if (start_seafdav() < 0)
Expand Down Expand Up @@ -592,6 +651,8 @@ stop_ccnet_server ()
kill_by_force(PID_CCNET);
kill_by_force(PID_SERVER);
kill_by_force(PID_SEAFDAV);
if (has_seafevents)
kill_by_force(PID_SEAFEVENTS);
}

static void
Expand All @@ -608,6 +669,7 @@ init_pidfile_path (SeafileController *ctl)
ctl->pidfile[PID_CCNET] = g_build_filename (pid_dir, "ccnet.pid", NULL);
ctl->pidfile[PID_SERVER] = g_build_filename (pid_dir, "seaf-server.pid", NULL);
ctl->pidfile[PID_SEAFDAV] = g_build_filename (pid_dir, "seafdav.pid", NULL);
ctl->pidfile[PID_SEAFEVENTS] = g_build_filename (pid_dir, "seafevents.pid", NULL);
}

static int
Expand Down
1 change: 1 addition & 0 deletions controller/seafile-controller.h
Expand Up @@ -26,6 +26,7 @@ enum {
PID_CCNET = 0,
PID_SERVER,
PID_SEAFDAV,
PID_SEAFEVENTS,
N_PID
};

Expand Down

0 comments on commit a0c393f

Please sign in to comment.