Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54b91af76c |
Binary file not shown.
Binary file not shown.
Binary file not shown.
45
src/main.c
45
src/main.c
@@ -1941,8 +1941,15 @@ int validate_event_expiration(cJSON* event, char* error_message, size_t error_si
|
||||
|
||||
// Initialize database connection and schema
|
||||
int init_database() {
|
||||
// Use configurable database path, falling back to default
|
||||
const char* db_path = get_config_value("database_path");
|
||||
// Priority 1: Command line database path override
|
||||
const char* db_path = getenv("C_RELAY_DATABASE_PATH_OVERRIDE");
|
||||
|
||||
// Priority 2: Configuration system (if available)
|
||||
if (!db_path) {
|
||||
db_path = get_config_value("database_path");
|
||||
}
|
||||
|
||||
// Priority 3: Default path
|
||||
if (!db_path) {
|
||||
db_path = DEFAULT_DATABASE_PATH;
|
||||
}
|
||||
@@ -3012,15 +3019,18 @@ void print_usage(const char* program_name) {
|
||||
printf("C Nostr Relay Server\n");
|
||||
printf("\n");
|
||||
printf("Options:\n");
|
||||
printf(" -p, --port PORT Listen port (default: %d)\n", DEFAULT_PORT);
|
||||
printf(" -c, --config FILE Configuration file path\n");
|
||||
printf(" -d, --config-dir DIR Configuration directory path\n");
|
||||
printf(" -h, --help Show this help message\n");
|
||||
printf(" -p, --port PORT Listen port (default: %d)\n", DEFAULT_PORT);
|
||||
printf(" -c, --config FILE Configuration file path\n");
|
||||
printf(" -d, --config-dir DIR Configuration directory path\n");
|
||||
printf(" -D, --database-path PATH Database file path (default: %s)\n", DEFAULT_DATABASE_PATH);
|
||||
printf(" -h, --help Show this help message\n");
|
||||
printf("\n");
|
||||
printf("Examples:\n");
|
||||
printf(" %s --config /path/to/config.json\n", program_name);
|
||||
printf(" %s --config-dir ~/.config/c-relay-dev\n", program_name);
|
||||
printf(" %s --port 9999 --config-dir /etc/c-relay\n", program_name);
|
||||
printf(" %s --database-path /var/lib/c-relay/relay.db\n", program_name);
|
||||
printf(" %s --database-path ./test.db --port 7777\n", program_name);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@@ -3028,6 +3038,7 @@ int main(int argc, char* argv[]) {
|
||||
int port = DEFAULT_PORT;
|
||||
char* config_dir_override = NULL;
|
||||
char* config_file_override = NULL;
|
||||
char* database_path_override = NULL;
|
||||
|
||||
// Parse command line arguments
|
||||
for (int i = 1; i < argc; i++) {
|
||||
@@ -3065,6 +3076,13 @@ int main(int argc, char* argv[]) {
|
||||
log_error("Config directory argument requires a value");
|
||||
return 1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-D") == 0 || strcmp(argv[i], "--database-path") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
database_path_override = argv[++i];
|
||||
} else {
|
||||
log_error("Database path argument requires a value");
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
log_error("Unknown argument");
|
||||
print_usage(argv[0]);
|
||||
@@ -3086,12 +3104,27 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
printf(BLUE BOLD "=== C Nostr Relay Server ===" RESET "\n");
|
||||
|
||||
// Apply database path override BEFORE any database operations
|
||||
if (database_path_override) {
|
||||
log_info("Database path override specified from command line");
|
||||
printf(" Override path: %s\n", database_path_override);
|
||||
// Set environment variable so init_database can use the correct path
|
||||
setenv("C_RELAY_DATABASE_PATH_OVERRIDE", database_path_override, 1);
|
||||
}
|
||||
|
||||
// Initialize database FIRST (required for configuration system)
|
||||
if (init_database() != 0) {
|
||||
log_error("Failed to initialize database");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Store database path override in configuration if specified
|
||||
if (database_path_override) {
|
||||
if (set_database_config("database_path", database_path_override, "command_line") != 0) {
|
||||
log_warning("Failed to store database path override in configuration");
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize nostr library BEFORE configuration system
|
||||
// (required for Nostr event generation in config files)
|
||||
if (nostr_init() != 0) {
|
||||
|
||||
BIN
test_db.db-shm
Normal file
BIN
test_db.db-shm
Normal file
Binary file not shown.
BIN
test_db.db-wal
Normal file
BIN
test_db.db-wal
Normal file
Binary file not shown.
Reference in New Issue
Block a user