Del seaf-init and ccnet-init commands (#348)
This commit is contained in:
parent
d50359c908
commit
33536cc56c
3 changed files with 12 additions and 176 deletions
|
@ -46,12 +46,14 @@ class ServerCtl(object):
|
|||
if self.db == 'mysql':
|
||||
create_mysql_dbs()
|
||||
|
||||
os.mkdir (self.central_conf_dir, 0o755)
|
||||
os.mkdir (self.seafile_conf_dir, 0o755)
|
||||
os.mkdir (self.ccnet_conf_dir, 0o755)
|
||||
|
||||
self.init_ccnet()
|
||||
self.init_seafile()
|
||||
|
||||
def init_ccnet(self):
|
||||
os.mkdir (self.central_conf_dir, 0o755)
|
||||
os.mkdir (self.ccnet_conf_dir, 0o755)
|
||||
if self.db == 'mysql':
|
||||
self.add_ccnet_db_conf()
|
||||
else:
|
||||
|
@ -83,17 +85,15 @@ CONNECTION_CHARSET = utf8
|
|||
fp.write(ccnet_db_conf)
|
||||
|
||||
def init_seafile(self):
|
||||
cmd = [
|
||||
'seaf-server-init',
|
||||
'--central-config-dir',
|
||||
self.central_conf_dir,
|
||||
'--seafile-dir',
|
||||
self.seafile_conf_dir,
|
||||
'--fileserver-port',
|
||||
'8082',
|
||||
]
|
||||
seafile_conf = join(self.central_conf_dir, 'seafile.conf')
|
||||
seafile_fileserver_conf = '''\
|
||||
[fileserver]
|
||||
port=8082
|
||||
'''
|
||||
with open(seafile_conf, 'a+') as fp:
|
||||
fp.write('\n')
|
||||
fp.write(seafile_fileserver_conf)
|
||||
|
||||
shell(cmd)
|
||||
if self.db == 'mysql':
|
||||
self.add_seafile_db_conf()
|
||||
else:
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
|
||||
#AM_CPPFLAGS = @GLIB2_CFLAGS@
|
||||
|
||||
bin_PROGRAMS = seaf-server-init
|
||||
|
||||
seaf_server_init_SOURCES = seaf-server-init.c ../common/seaf-db.c
|
||||
|
||||
seaf_server_init_LDADD = @GLIB2_LIBS@ -lpthread @MYSQL_LIBS@ -lsqlite3
|
||||
|
||||
seaf_server_init_CPPFLAGS = @GLIB2_CFLAGS@ @MSVC_CFLAGS@ @MYSQL_CFLAGS@
|
||||
|
||||
EXTRA_DIST = seafile-admin
|
||||
|
||||
bin_SCRIPTS = seafile-admin
|
||||
|
|
|
@ -1,156 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include "../common/seaf-db.h"
|
||||
|
||||
static int
|
||||
save_config_file (GKeyFile *key_file, const char *path)
|
||||
{
|
||||
GError *error = NULL;
|
||||
char *config = g_key_file_to_data (key_file, NULL, &error);
|
||||
if (error) {
|
||||
fprintf (stderr, "Failed to save config file to %s: %s\n",
|
||||
path, error->message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *fp = g_fopen (path, "w");
|
||||
if (fp == NULL) {
|
||||
fprintf (stderr, "Failed to save config file: %s %s.\n",
|
||||
path, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
fputs (config, fp);
|
||||
fclose (fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *short_opts = "hvd:p:P:F:";
|
||||
static const struct option long_opts[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "seafile-dir", required_argument, NULL, 'd' },
|
||||
{ "central-config-dir", required_argument, NULL, 'F' },
|
||||
{ "port", required_argument, NULL, 'p' },
|
||||
{ "fileserver-port", required_argument, NULL, 'P' },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
struct seaf_server_config {
|
||||
char *central_config_dir;
|
||||
char *seafile_dir;
|
||||
char *port;
|
||||
char *fileserver_port;
|
||||
};
|
||||
|
||||
static struct seaf_server_config config = {
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
void usage(int code) {
|
||||
fprintf (stderr,
|
||||
"\nUsage: seaf-server-init [OPTIONS]\n"
|
||||
"Initialize your seafile server configuration\n\n"
|
||||
"Required arguments are:\n\n"
|
||||
" -h, --help output help and quit\n"
|
||||
" -v, --verbose output more information\n"
|
||||
" -d, --seafile-dir specify a directory to put your seafile server config and data\n"
|
||||
" -p, --port specify a port to to transmit data\n"
|
||||
" -P, --fileserver-port specify the port to use by fileserver\n"
|
||||
);
|
||||
exit(code);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
gboolean verbose = FALSE;
|
||||
|
||||
if (argc == 1)
|
||||
usage(1);
|
||||
|
||||
int c;
|
||||
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != EOF) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage(0);
|
||||
break;
|
||||
case 'v':
|
||||
verbose = TRUE;
|
||||
break;
|
||||
case 'F':
|
||||
config.central_config_dir = strdup(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
config.seafile_dir = strdup(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
config.port = strdup(optarg);
|
||||
break;
|
||||
case 'P':
|
||||
config.fileserver_port = strdup(optarg);
|
||||
break;
|
||||
default:
|
||||
usage(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.seafile_dir && !config.central_config_dir) {
|
||||
fprintf (stderr, "You must specify seafile data dir\n");
|
||||
usage(1);
|
||||
}
|
||||
|
||||
/* Generate config file. */
|
||||
GKeyFile *key_file = g_key_file_new ();
|
||||
|
||||
if (config.port) {
|
||||
g_key_file_set_string (key_file, "network", "port", config.port);
|
||||
}
|
||||
|
||||
if (config.fileserver_port) {
|
||||
g_key_file_set_string (key_file, "fileserver", "port", config.fileserver_port);
|
||||
} else {
|
||||
/* fileserver port defaults to 8082 */
|
||||
g_key_file_set_string (key_file, "fileserver", "port", "8082");
|
||||
}
|
||||
|
||||
struct stat st;
|
||||
if (g_lstat (config.seafile_dir, &st) < 0) {
|
||||
if (g_mkdir (config.seafile_dir, 0700) < 0) {
|
||||
fprintf (stderr, "Directory %s cannot be created.\n", config.seafile_dir);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (config.central_config_dir && g_lstat (config.central_config_dir, &st) < 0) {
|
||||
if (g_mkdir (config.central_config_dir, 0700) < 0) {
|
||||
fprintf (stderr, "Directory %s cannot be created.\n", config.central_config_dir);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
const char *confdir = config.central_config_dir ? config.central_config_dir : config.seafile_dir;
|
||||
char *seafile_conf = g_build_filename (confdir, "seafile.conf", NULL);
|
||||
|
||||
if (verbose)
|
||||
printf ("Generating config files: %s\n", seafile_conf);
|
||||
|
||||
if (save_config_file (key_file, seafile_conf) < 0)
|
||||
return 1;
|
||||
|
||||
printf ("Done.\n");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue