aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-01-28 18:55:32 +0100
committerChristian Grothoff <christian@grothoff.org>2024-01-28 18:55:32 +0100
commit964365ebdeb18e8c2de2abab9bf1dd59ed2b664b (patch)
treeca8e3f1fd4b7a5025bf16ffcb68ccb88429addcc
parenteddf1b211be54925dedf22ee748b019fa471c96b (diff)
work on #8030 for merchant
-rw-r--r--debian/taler-merchant.taler-merchant-depositcheck.service3
-rw-r--r--debian/taler-merchant.taler-merchant-exchange.service3
-rw-r--r--debian/taler-merchant.taler-merchant-webhook.service3
-rw-r--r--debian/taler-merchant.taler-merchant-wirewatch.service3
-rw-r--r--src/backend/taler-merchant-depositcheck.c11
-rw-r--r--src/backend/taler-merchant-exchange.c9
-rw-r--r--src/backend/taler-merchant-webhook.c20
-rw-r--r--src/backend/taler-merchant-wirewatch.c50
-rw-r--r--src/include/platform.h28
9 files changed, 102 insertions, 28 deletions
diff --git a/debian/taler-merchant.taler-merchant-depositcheck.service b/debian/taler-merchant.taler-merchant-depositcheck.service
index 4b744e8d..2888e10b 100644
--- a/debian/taler-merchant.taler-merchant-depositcheck.service
+++ b/debian/taler-merchant.taler-merchant-depositcheck.service
@@ -6,8 +6,9 @@ After=postgres.service
User=taler-merchant-httpd
Type=simple
Restart=always
+RestartMode=direct
RestartSec=1s
-RestartPreventExitStatus=9
+RestartPreventExitStatus=2 3 4 5 6 9
ExecStart=/usr/bin/taler-merchant-depositcheck -c /etc/taler/taler.conf
PrivateTmp=yes
PrivateDevices=yes
diff --git a/debian/taler-merchant.taler-merchant-exchange.service b/debian/taler-merchant.taler-merchant-exchange.service
index e37546ef..8f0c33b1 100644
--- a/debian/taler-merchant.taler-merchant-exchange.service
+++ b/debian/taler-merchant.taler-merchant-exchange.service
@@ -6,8 +6,9 @@ After=postgres.service
User=taler-merchant-exchange
Type=simple
Restart=always
+RestartMode=direct
RestartSec=1s
-RestartPreventExitStatus=9
+RestartPreventExitStatus=2 3 4 5 6 9
ExecStart=/usr/bin/taler-merchant-exchange -c /etc/taler/taler.conf
PrivateTmp=yes
PrivateDevices=yes
diff --git a/debian/taler-merchant.taler-merchant-webhook.service b/debian/taler-merchant.taler-merchant-webhook.service
index dfef261d..be2a7794 100644
--- a/debian/taler-merchant.taler-merchant-webhook.service
+++ b/debian/taler-merchant.taler-merchant-webhook.service
@@ -6,8 +6,9 @@ After=postgres.service
User=taler-merchant-httpd
Type=simple
Restart=always
+RestartMode=direct
RestartSec=1s
-RestartPreventExitStatus=9
+RestartPreventExitStatus=2 3 4 5 6 9
ExecStart=/usr/bin/taler-merchant-webhook -c /etc/taler/taler.conf
PrivateTmp=yes
PrivateDevices=yes
diff --git a/debian/taler-merchant.taler-merchant-wirewatch.service b/debian/taler-merchant.taler-merchant-wirewatch.service
index afdcd574..d4e3a3f7 100644
--- a/debian/taler-merchant.taler-merchant-wirewatch.service
+++ b/debian/taler-merchant.taler-merchant-wirewatch.service
@@ -6,8 +6,9 @@ After=postgres.service
User=taler-merchant-httpd
Type=simple
Restart=always
+RestartMode=direct
RestartSec=1s
-RestartPreventExitStatus=9
+RestartPreventExitStatus=2 3 4 5 6 9
ExecStart=/usr/bin/taler-merchant-wirewatch -c /etc/taler/taler.conf
PrivateTmp=yes
PrivateDevices=yes
diff --git a/src/backend/taler-merchant-depositcheck.c b/src/backend/taler-merchant-depositcheck.c
index 90fbeb6e..ecb6b24e 100644
--- a/src/backend/taler-merchant-depositcheck.c
+++ b/src/backend/taler-merchant-depositcheck.c
@@ -811,7 +811,7 @@ child_done_cb (void *cls,
(int) type,
(int) exit_code);
GNUNET_SCHEDULER_shutdown ();
- global_ret = 1;
+ global_ret = EXIT_NOTINSTALLED;
return;
}
GNUNET_OS_process_destroy (c->process);
@@ -843,7 +843,7 @@ restart_child (void *cls)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
"exec");
- global_ret = 1;
+ global_ret = EXIT_NO_RESTART;
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -930,6 +930,8 @@ run (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"No exchanges found in configuration\n");
+ global_ret = EXIT_NOTCONFIGURED;
+ GNUNET_SCHEDULER_shutdown ();
return;
}
return;
@@ -942,6 +944,7 @@ run (void *cls,
{
GNUNET_break (0);
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NO_RESTART;
return;
}
if (NULL ==
@@ -950,7 +953,7 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to initialize DB subsystem\n");
GNUNET_SCHEDULER_shutdown ();
- global_ret = 1;
+ global_ret = EXIT_NOTCONFIGURED;
return;
}
if (GNUNET_OK !=
@@ -959,7 +962,7 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to connect to database\n");
GNUNET_SCHEDULER_shutdown ();
- global_ret = 1;
+ global_ret = EXIT_NO_RESTART;
return;
}
{
diff --git a/src/backend/taler-merchant-exchange.c b/src/backend/taler-merchant-exchange.c
index c74d4f74..f77ca3a5 100644
--- a/src/backend/taler-merchant-exchange.c
+++ b/src/backend/taler-merchant-exchange.c
@@ -404,7 +404,7 @@ update_transaction_status (const struct Inquiry *w,
if (qs < 0)
{
GNUNET_break (0);
- global_ret = 1;
+ global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -816,7 +816,7 @@ wire_transfer_cb (void *cls,
{
/* Always report on DB error as well to enable diagnostics */
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
- global_ret = 1;
+ global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -1170,6 +1170,7 @@ run (void *cls,
{
GNUNET_break (0);
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NO_RESTART;
return;
}
if (NULL ==
@@ -1178,6 +1179,7 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to initialize DB subsystem\n");
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NOTCONFIGURED;
return;
}
if (GNUNET_OK !=
@@ -1186,6 +1188,7 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to connect to database\n");
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NO_RESTART;
return;
}
{
@@ -1217,6 +1220,8 @@ main (int argc,
char *const *argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_timetravel ('T',
+ "timetravel"),
GNUNET_GETOPT_option_flag ('t',
"test",
"run in test mode and exit when idle",
diff --git a/src/backend/taler-merchant-webhook.c b/src/backend/taler-merchant-webhook.c
index 60ad3240..80db78fd 100644
--- a/src/backend/taler-merchant-webhook.c
+++ b/src/backend/taler-merchant-webhook.c
@@ -183,9 +183,7 @@ handle_webhook_response (void *cls,
case GNUNET_DB_STATUS_HARD_ERROR:
case GNUNET_DB_STATUS_SOFT_ERROR:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Delete returned: %d\n",
+ "Failed to delete webhook, delete returned: %d\n",
qs);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
@@ -232,10 +230,9 @@ handle_webhook_response (void *cls,
case GNUNET_DB_STATUS_HARD_ERROR:
case GNUNET_DB_STATUS_SOFT_ERROR:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Next in %s Rval: %d\n",
- GNUNET_TIME_relative2s (next_attempt, true),
+ "Failed to update pending webhook to next in %s Rval: %d\n",
+ GNUNET_TIME_relative2s (next_attempt,
+ true),
qs);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
@@ -441,7 +438,7 @@ select_work (void *cls)
case GNUNET_DB_STATUS_HARD_ERROR:
case GNUNET_DB_STATUS_SOFT_ERROR:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed!\n");
+ "Failed to lookup pending webhooks!\n");
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
@@ -459,7 +456,7 @@ select_work (void *cls)
case GNUNET_DB_STATUS_HARD_ERROR:
case GNUNET_DB_STATUS_SOFT_ERROR:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed!\n");
+ "Failed to lookup future webhook!\n");
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
@@ -509,6 +506,7 @@ run (void *cls,
{
GNUNET_break (0);
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NO_RESTART;
return;
}
if (NULL ==
@@ -517,6 +515,7 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to initialize DB subsystem\n");
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NOTCONFIGURED;
return;
}
if (GNUNET_OK !=
@@ -525,6 +524,7 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to connect to database\n");
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NO_RESTART;
return;
}
{
@@ -560,6 +560,8 @@ main (int argc,
"test",
"run in test mode and exit when idle",
&test_mode),
+ GNUNET_GETOPT_option_timetravel ('T',
+ "timetravel"),
GNUNET_GETOPT_option_version (VERSION "-" VCS_VERSION),
GNUNET_GETOPT_OPTION_END
};
diff --git a/src/backend/taler-merchant-wirewatch.c b/src/backend/taler-merchant-wirewatch.c
index c5fcff7d..a40a3e90 100644
--- a/src/backend/taler-merchant-wirewatch.c
+++ b/src/backend/taler-merchant-wirewatch.c
@@ -149,6 +149,17 @@ static unsigned int batch_size = 32;
*/
static int test_mode;
+/**
+ * #GNUNET_YES if we are in persistent mode and do
+ * not exit on #config_changed.
+ */
+static int persist_mode;
+
+/**
+ * Set to true if we are shutting down due to a
+ * configuration change.
+ */
+static bool config_changed_flag;
/**
* Save progress in DB.
@@ -487,7 +498,7 @@ start_watch (
payto_uri);
GNUNET_free (w);
GNUNET_SCHEDULER_shutdown ();
- global_ret = 1;
+ global_ret = EXIT_NOTCONFIGURED;
return;
}
@@ -518,6 +529,12 @@ config_changed (void *cls,
(void) cls;
(void) extra;
(void) extra_size;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Configuration changed, %s\n",
+ 0 == persist_mode
+ ? "restarting"
+ : "reinitializing");
+ config_changed_flag = true;
GNUNET_SCHEDULER_shutdown ();
}
@@ -549,6 +566,7 @@ run (void *cls,
{
GNUNET_break (0);
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NO_RESTART;
return;
}
if (NULL ==
@@ -557,6 +575,7 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to initialize DB subsystem\n");
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NOTCONFIGURED;
return;
}
if (GNUNET_OK !=
@@ -565,6 +584,7 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to connect to database\n");
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NO_RESTART;
return;
}
{
@@ -590,14 +610,16 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to obtain wirewatch accounts from database\n");
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NO_RESTART;
return;
}
- if ( (0 == qs) &&
+ if ( (NULL == w_head) &&
(GNUNET_YES == test_mode) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"No active wirewatch accounts in database and in test mode. Exiting.\n");
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_SUCCESS;
return;
}
}
@@ -616,6 +638,12 @@ main (int argc,
char *const *argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_flag ('p',
+ "persist",
+ "run in persist mode and do not exit on configuration changes",
+ &persist_mode),
+ GNUNET_GETOPT_option_timetravel ('T',
+ "timetravel"),
GNUNET_GETOPT_option_flag ('t',
"test",
"run in test mode and exit when idle",
@@ -630,13 +658,17 @@ main (int argc,
&argc, &argv))
return EXIT_INVALIDARGUMENT;
TALER_OS_init ();
- ret = GNUNET_PROGRAM_run (
- argc, argv,
- "taler-merchant-wirewatch",
- gettext_noop (
- "background process that watches for incoming wire transfers to the merchant bank account"),
- options,
- &run, NULL);
+ do {
+ config_changed_flag = false;
+ ret = GNUNET_PROGRAM_run (
+ argc, argv,
+ "taler-merchant-wirewatch",
+ gettext_noop (
+ "background process that watches for incoming wire transfers to the merchant bank account"),
+ options,
+ &run, NULL);
+ } while ( (1 == persist_mode) &&
+ config_changed_flag);
GNUNET_free_nz ((void *) argv);
if (GNUNET_SYSERR == ret)
return EXIT_INVALIDARGUMENT;
diff --git a/src/include/platform.h b/src/include/platform.h
index 61d3e402..6adeaf58 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -277,22 +277,42 @@ atoll (const char *nptr);
/* LSB-style exit status codes */
#ifndef EXIT_INVALIDARGUMENT
+/**
+ * Command-line arguments are invalid.
+ * Restarting useless.
+ */
#define EXIT_INVALIDARGUMENT 2
#endif
#ifndef EXIT_NOTIMPLEMENTED
+/**
+ * The requested operation is not implemented.
+ * Restarting useless.
+ */
#define EXIT_NOTIMPLEMENTED 3
#endif
#ifndef EXIT_NOPERMISSION
+/**
+ * Permissions needed to run are not available.
+ * Restarting useless.
+ */
#define EXIT_NOPERMISSION 4
#endif
#ifndef EXIT_NOTINSTALLED
+/**
+ * Key resources are not installed.
+ * Restarting useless.
+ */
#define EXIT_NOTINSTALLED 5
#endif
#ifndef EXIT_NOTCONFIGURED
+/**
+ * Key configuration settings are missing or invalid.
+ * Restarting useless.
+ */
#define EXIT_NOTCONFIGURED 6
#endif
@@ -300,6 +320,14 @@ atoll (const char *nptr);
#define EXIT_NOTRUNNING 7
#endif
+#ifndef EXIT_NO_RESTART
+/**
+ * Exit code from 'main' if we do not want to be restarted,
+ * except by manual intervention (hard failure).
+ */
+#define EXIT_NO_RESTART 9
+#endif
+
#endif /* PLATFORM_H_ */