Skip to content

Commit 5c8c640

Browse files
authored
Merge pull request #198 from haiwen/add-seafevents
Support seafevents.
2 parents 466fce2 + 39ffb0a commit 5c8c640

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

controller/seafile-controller.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,42 @@ setup_env ()
348348
setup_python_path();
349349
}
350350

351+
static int
352+
start_seafevents() {
353+
if (!ctl->has_seafevents)
354+
return 0;
355+
356+
static char *seafevents_config_file = NULL;
357+
static char *seafevents_log_file = NULL;
358+
359+
if (seafevents_config_file == NULL)
360+
seafevents_config_file = g_build_filename (topdir,
361+
"conf/seafevents.conf",
362+
NULL);
363+
if (seafevents_log_file == NULL)
364+
seafevents_log_file = g_build_filename (ctl->logdir,
365+
"seafevents.log",
366+
NULL);
367+
368+
char *argv[] = {
369+
(char *)get_python_executable(),
370+
"-m", "seafevents.main",
371+
"--config-file", seafevents_config_file,
372+
"--logfile", seafevents_log_file,
373+
"-P", ctl->pidfile[PID_SEAFEVENTS],
374+
NULL
375+
};
376+
377+
int pid = spawn_process (argv);
378+
379+
if (pid <= 0) {
380+
seaf_warning ("Failed to spawn seafevents.\n");
381+
return -1;
382+
}
383+
384+
return 0;
385+
}
386+
351387
static int
352388
start_seafdav() {
353389
static char *seafdav_log_file = NULL;
@@ -446,6 +482,11 @@ check_process (void *data)
446482
}
447483
}
448484

485+
if (ctl->has_seafevents && need_restart(PID_SEAFEVENTS)) {
486+
seaf_message ("seafevents need restart...\n");
487+
start_seafevents ();
488+
}
489+
449490
return TRUE;
450491
}
451492

@@ -541,6 +582,11 @@ on_ccnet_connected ()
541582
if (start_seaf_server () < 0)
542583
controller_exit(1);
543584

585+
if (ctl->has_seafevents && need_restart(PID_SEAFEVENTS)) {
586+
if (start_seafevents() < 0)
587+
controller_exit(1);
588+
}
589+
544590
if (ctl->seafdav_config.enabled) {
545591
if (need_restart(PID_SEAFDAV)) {
546592
if (start_seafdav() < 0)
@@ -592,6 +638,8 @@ stop_ccnet_server ()
592638
kill_by_force(PID_CCNET);
593639
kill_by_force(PID_SERVER);
594640
kill_by_force(PID_SEAFDAV);
641+
if (ctl->has_seafevents)
642+
kill_by_force(PID_SEAFEVENTS);
595643
}
596644

597645
static void
@@ -608,6 +656,7 @@ init_pidfile_path (SeafileController *ctl)
608656
ctl->pidfile[PID_CCNET] = g_build_filename (pid_dir, "ccnet.pid", NULL);
609657
ctl->pidfile[PID_SERVER] = g_build_filename (pid_dir, "seaf-server.pid", NULL);
610658
ctl->pidfile[PID_SEAFDAV] = g_build_filename (pid_dir, "seafdav.pid", NULL);
659+
ctl->pidfile[PID_SEAFEVENTS] = g_build_filename (pid_dir, "seafevents.pid", NULL);
611660
}
612661

613662
static int
@@ -661,6 +710,18 @@ seaf_controller_init (SeafileController *ctl,
661710
return -1;
662711
}
663712

713+
char *seafevents_config_file = g_build_filename (topdir,
714+
"conf/seafevents.conf",
715+
NULL);
716+
717+
if (!g_file_test (seafevents_config_file, G_FILE_TEST_EXISTS)) {
718+
seaf_message ("No seafevents.\n");
719+
ctl->has_seafevents = FALSE;
720+
} else {
721+
ctl->has_seafevents = TRUE;
722+
}
723+
g_free (seafevents_config_file);
724+
664725
init_pidfile_path (ctl);
665726
setup_env ();
666727

controller/seafile-controller.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum {
2626
PID_CCNET = 0,
2727
PID_SERVER,
2828
PID_SEAFDAV,
29+
PID_SEAFEVENTS,
2930
N_PID
3031
};
3132

@@ -56,5 +57,7 @@ struct _SeafileController {
5657
char *pidfile[N_PID];
5758

5859
SeafDavConfig seafdav_config;
60+
61+
gboolean has_seafevents;
5962
};
6063
#endif

0 commit comments

Comments
 (0)