forked from cory/tildefriends
admin: Global settings can be specified on the command-line. Removed some previous, less thorough ways of configuring things. #102
This commit is contained in:
41
src/main.c
41
src/main.c
@ -1217,9 +1217,6 @@ typedef struct tf_run_args_t
|
||||
{
|
||||
const char* script;
|
||||
const char* network_key;
|
||||
int ssb_port;
|
||||
int http_port;
|
||||
int https_port;
|
||||
const char* db_path;
|
||||
int count;
|
||||
const char* args;
|
||||
@ -1244,9 +1241,6 @@ static int _tf_run_task(const tf_run_args_t* args, int index)
|
||||
tf_printf("setting zip path to %s\n", args->zip);
|
||||
tf_task_set_zip_path(task, args->zip);
|
||||
tf_task_set_ssb_network_key(task, args->network_key);
|
||||
tf_task_set_ssb_port(task, args->ssb_port ? args->ssb_port + index : 0);
|
||||
tf_task_set_http_port(task, args->http_port ? args->http_port + index : 0);
|
||||
tf_task_set_https_port(task, args->https_port ? args->https_port + index : 0);
|
||||
tf_task_set_args(task, args->args);
|
||||
tf_task_set_one_proc(task, args->one_proc);
|
||||
const char* db_path = args->db_path;
|
||||
@ -1301,7 +1295,14 @@ static int _tf_run_task(const tf_run_args_t* args, int index)
|
||||
tf_task_activate(task);
|
||||
tf_ssb_set_verbose(tf_task_get_ssb(task), args->verbose);
|
||||
tf_ssb_start_periodic(tf_task_get_ssb(task));
|
||||
if (args->http_port || args->https_port)
|
||||
tf_ssb_t* ssb = tf_task_get_ssb(task);
|
||||
sqlite3* db = tf_ssb_acquire_db_reader(ssb);
|
||||
int64_t http_port = 0;
|
||||
int64_t https_port = 0;
|
||||
tf_ssb_db_get_global_setting_int64(db, "http_port", &http_port);
|
||||
tf_ssb_db_get_global_setting_int64(db, "https_port", &https_port);
|
||||
tf_ssb_release_db_reader(ssb, db);
|
||||
if (http_port || https_port)
|
||||
{
|
||||
if (args->zip)
|
||||
{
|
||||
@ -1417,9 +1418,6 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
const char* default_db_path = _get_db_path();
|
||||
tf_run_args_t args = {
|
||||
.count = 1,
|
||||
.http_port = 12345,
|
||||
.https_port = 12346,
|
||||
.ssb_port = 8008,
|
||||
.db_path = default_db_path,
|
||||
};
|
||||
bool show_usage = false;
|
||||
@ -1436,10 +1434,7 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
{
|
||||
static const struct option k_options[] = {
|
||||
{ "script", required_argument, NULL, 's' },
|
||||
{ "ssb-port", required_argument, NULL, 'b' },
|
||||
{ "ssb-network-key", required_argument, NULL, 'k' },
|
||||
{ "http-port", required_argument, NULL, 'p' },
|
||||
{ "https-port", required_argument, NULL, 'q' },
|
||||
{ "db-path", required_argument, NULL, 'd' },
|
||||
{ "count", required_argument, NULL, 'n' },
|
||||
{ "args", required_argument, NULL, 'a' },
|
||||
@ -1448,7 +1443,7 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
};
|
||||
int c = getopt_long(argc, argv, "s:b:k:p:q:d:n:a:oz:vh", k_options, NULL);
|
||||
int c = getopt_long(argc, argv, "s:k:d:n:a:oz:vh", k_options, NULL);
|
||||
if (c == -1)
|
||||
{
|
||||
break;
|
||||
@ -1467,15 +1462,6 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
case 'k':
|
||||
args.network_key = optarg;
|
||||
break;
|
||||
case 'b':
|
||||
args.ssb_port = atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
args.http_port = atoi(optarg);
|
||||
break;
|
||||
case 'q':
|
||||
args.https_port = atoi(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
args.db_path = optarg;
|
||||
break;
|
||||
@ -1502,13 +1488,11 @@ static int _tf_command_run(const char* file, int argc, char* argv[])
|
||||
tf_printf("\n%s run [options]\n\n", file);
|
||||
tf_printf("options\n");
|
||||
tf_printf(" -s, --script script Script to run (default: core/core.js).\n");
|
||||
tf_printf(" -b, --ssb-port port Port on which to run SSB (default: 8008, 0 disables).\n");
|
||||
tf_printf(" -p, --http-port port Port on which to run Tilde Friends web server (default: 12345).\n");
|
||||
tf_printf(" -q, --https-port port Port on which to run secure Tilde Friends web server (default: 12346).\n");
|
||||
tf_printf(" -d, --db-path path SQLite database path (default: %s).\n", default_db_path);
|
||||
tf_printf(" -k, --ssb-network-key key SSB network key to use.\n");
|
||||
tf_printf(" -n, --count count Number of instances to run.\n");
|
||||
tf_printf(" -a, --args args Arguments of the format key=value,foo=bar,verbose=true.\n");
|
||||
tf_printf(" -a, --args args Arguments of the format key=value,foo=bar,verbose=true (note: these are persisted to the database).\n");
|
||||
tf_util_document_settings(" ");
|
||||
tf_printf(" -o, --one-proc Run everything in one process (unsafely!).\n");
|
||||
tf_printf(" -z, --zip path Zip archive from which to load files.\n");
|
||||
tf_printf(" -v, --verbose Log raw messages.\n");
|
||||
@ -1847,9 +1831,6 @@ void tf_run_thread_start(const char* zip_path)
|
||||
tf_run_thread_data_t* data = tf_malloc(sizeof(tf_run_thread_data_t));
|
||||
tf_run_args_t args = {
|
||||
.count = 1,
|
||||
.http_port = 12345,
|
||||
.https_port = 12346,
|
||||
.ssb_port = 8008,
|
||||
.db_path = "db.sqlite",
|
||||
.one_proc = true,
|
||||
.zip = zip_path,
|
||||
|
Reference in New Issue
Block a user