Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AE14E200D2B for ; Thu, 2 Nov 2017 14:10:10 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id ACA32160BE5; Thu, 2 Nov 2017 13:10:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CB8991609EE for ; Thu, 2 Nov 2017 14:10:09 +0100 (CET) Received: (qmail 39837 invoked by uid 500); 2 Nov 2017 13:10:09 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 39828 invoked by uid 99); 2 Nov 2017 13:10:08 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Nov 2017 13:10:08 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 89FE23A01E5 for ; Thu, 2 Nov 2017 13:10:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1814072 - in /commons/proper/daemon/trunk/src: changes/changes.xml native/unix/man/jsvc.1.xml native/unix/native/arguments.c native/unix/native/arguments.h native/unix/native/help.c native/unix/native/jsvc-unix.c site/xdoc/jsvc.xml Date: Thu, 02 Nov 2017 13:10:05 -0000 To: commits@commons.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20171102131007.89FE23A01E5@svn01-us-west.apache.org> archived-at: Thu, 02 Nov 2017 13:10:10 -0000 Author: markt Date: Thu Nov 2 13:10:04 2017 New Revision: 1814072 URL: http://svn.apache.org/viewvc?rev=1814072&view=rev Log: Fix DAEMON-334 Add a restarts options to jsvc to control the number of permitted restarts after a system crash. Patch provided by Brett Delle Grazie Modified: commons/proper/daemon/trunk/src/changes/changes.xml commons/proper/daemon/trunk/src/native/unix/man/jsvc.1.xml commons/proper/daemon/trunk/src/native/unix/native/arguments.c commons/proper/daemon/trunk/src/native/unix/native/arguments.h commons/proper/daemon/trunk/src/native/unix/native/help.c commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c commons/proper/daemon/trunk/src/site/xdoc/jsvc.xml Modified: commons/proper/daemon/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/changes/changes.xml?rev=1814072&r1=1814071&r2=1814072&view=diff ============================================================================== --- commons/proper/daemon/trunk/src/changes/changes.xml (original) +++ commons/proper/daemon/trunk/src/changes/changes.xml Thu Nov 2 13:10:04 2017 @@ -130,6 +130,10 @@ Add support for Java 9 commoand line arguments to jsvc. + + Add a restarts options to jsvc to control the number of permitted + restarts after a system crash. + Modified: commons/proper/daemon/trunk/src/native/unix/man/jsvc.1.xml URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/man/jsvc.1.xml?rev=1814072&r1=1814071&r2=1814072&view=diff ============================================================================== --- commons/proper/daemon/trunk/src/native/unix/man/jsvc.1.xml (original) +++ commons/proper/daemon/trunk/src/native/unix/man/jsvc.1.xml Thu Nov 2 13:10:04 2017 @@ -47,6 +47,7 @@ -check -user user -wait waittime + -restarts max restart count -umask mask -stop -verbose:class|gc|jni @@ -146,6 +147,14 @@ + + max restart count + + maximum automatic restart count + -1=infinite (default), 0=none, 1..(INT_MAX-1)=fixed count + + + mask Modified: commons/proper/daemon/trunk/src/native/unix/native/arguments.c URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/arguments.c?rev=1814072&r1=1814071&r2=1814072&view=diff ============================================================================== --- commons/proper/daemon/trunk/src/native/unix/native/arguments.c (original) +++ commons/proper/daemon/trunk/src/native/unix/native/arguments.c Thu Nov 2 13:10:04 2017 @@ -158,6 +158,7 @@ static arg_data *parse(int argc, char *a args->chck = false; /* Don't do a check-only startup */ args->stop = false; /* Stop a running jsvc */ args->wait = 0; /* Wait until jsvc has started the JVM */ + args->restarts = -1; /* Infinite restarts by default */ args->install = false; /* Don't install as a service */ args->remove = false; /* Don't remove the installed service */ args->service = false; /* Don't run as a service */ @@ -274,6 +275,15 @@ static arg_data *parse(int argc, char *a return NULL; } } + else if (!strcmp(argv[x], "-restarts")) { + temp = optional(argc, argv, x++); + if (temp) + args->restarts = atoi(temp); + if (args->restarts < -1) { + log_error("Invalid max restarts [-1,0,...)"); + return NULL; + } + } else if (!strcmp(argv[x], "-umask")) { temp = optional(argc, argv, x++); if (temp == NULL) { @@ -488,6 +498,7 @@ arg_data *arguments(int argc, char *argv log_debug("| Check Only: %s", IsEnabledDisabled(args->chck)); log_debug("| Stop: %s", IsTrueFalse(args->stop)); log_debug("| Wait: %d", args->wait); + log_debug("| Restarts: %d", args->restarts); log_debug("| Run as service: %s", IsYesNo(args->service)); log_debug("| Install service: %s", IsYesNo(args->install)); log_debug("| Remove service: %s", IsYesNo(args->remove)); Modified: commons/proper/daemon/trunk/src/native/unix/native/arguments.h URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/arguments.h?rev=1814072&r1=1814071&r2=1814072&view=diff ============================================================================== --- commons/proper/daemon/trunk/src/native/unix/native/arguments.h (original) +++ commons/proper/daemon/trunk/src/native/unix/native/arguments.h Thu Nov 2 13:10:04 2017 @@ -60,6 +60,8 @@ typedef struct { bool stop; /** number of seconds to until service started */ int wait; + /** max restarts **/ + int restarts; /** Install as a service (win32) */ bool install; /** Remove when installed as a service (win32) */ Modified: commons/proper/daemon/trunk/src/native/unix/native/help.c URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/help.c?rev=1814072&r1=1814071&r2=1814072&view=diff ============================================================================== --- commons/proper/daemon/trunk/src/native/unix/native/help.c (original) +++ commons/proper/daemon/trunk/src/native/unix/native/help.c Thu Nov 2 13:10:04 2017 @@ -95,6 +95,9 @@ void help(home_data *data) printf(" -wait \n"); printf(" wait waittime seconds for the service to start\n"); printf(" waittime should multiple of 10 (min=10)\n"); + printf(" -restarts \n"); + printf(" maximum automatic restarts (integer)\n"); + printf(" -1=infinite (default), 0=none, 1..(INT_MAX-1)=fixed restart count\n"); printf(" -stop\n"); printf(" stop the service using the file given in the -pidfile option\n"); printf(" -keepstdin\n"); Modified: commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c?rev=1814072&r1=1814071&r2=1814072&view=diff ============================================================================== --- commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c (original) +++ commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c Thu Nov 2 13:10:04 2017 @@ -126,9 +126,9 @@ static void handler(int sig) case SIGUSR1: log_debug("Caught SIGUSR1: Reopening logs"); doreopen = true; - break; + break; case SIGUSR2: - log_debug("Caught SIGUSR2: Scheduling a custom signal"); + log_debug("Caught SIGUSR2: Scheduling a custom signal"); dosignal = true; break; default: @@ -1262,6 +1262,7 @@ static int run_controller(arg_data *args gid_t gid) { pid_t pid = 0; + int restarts = 0; struct sigaction act; controller_pid = getpid(); @@ -1315,7 +1316,16 @@ static int run_controller(arg_data *args /* See java_abort123 (we use this return code to restart when the JVM aborts) */ if (!stopping) { if (status == 123) { + if (args->restarts == 0) { + log_debug("Service failure, restarts disabled"); + return 1; + } + if (args->restarts != -1 && args->restarts <= restarts) { + log_debug("Service failure, restart limit reached, aborting"); + return 1; + } log_debug("Reloading service"); + restarts++; /* prevent looping */ if (laststart + 60 > time(NULL)) { log_debug("Waiting 60 s to prevent looping"); @@ -1343,6 +1353,8 @@ static int run_controller(arg_data *args log_debug("Waiting 60 s to prevent looping"); sleep(60); } + /* Normal or user controlled termination, reset restart counter */ + restarts = 0; continue; } } Modified: commons/proper/daemon/trunk/src/site/xdoc/jsvc.xml URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/site/xdoc/jsvc.xml?rev=1814072&r1=1814071&r2=1814072&view=diff ============================================================================== --- commons/proper/daemon/trunk/src/site/xdoc/jsvc.xml (original) +++ commons/proper/daemon/trunk/src/site/xdoc/jsvc.xml Thu Nov 2 13:10:04 2017 @@ -181,11 +181,31 @@ Where options include: -wait <waittime> wait waittime seconds for the service to start waittime should multiple of 10 (min=10) + -restarts <maxrestarts> + maximum automatic restarts (integer) + -1=infinite (default), 0=none, 1..(INT_MAX-1)=fixed restart count -stop stop the service using the file given in the -pidfile option -keepstdin does not redirect stdin to /dev/null - + --add-modules=<module name> + Java 9 --add-modules option. Passed as it is to JVM + --module-path=<module path> + Java 9 --module-path option. Passed as it is to JVM + --upgrade-module-path=<module path> + Java 9 --upgrade-module-path option. Passed as it is to JVM + --add-reads=<module name> + Java 9 --add-reads option. Passed as it is to JVM + --add-exports=<module name> + Java 9 --add-exports option. Passed as it is to JVM + --add-opens=<module name> + Java 9 --add-opens option. Passed as it is to JVM + --limit-modules=<module name> + Java 9 --limit-modules option. Passed as it is to JVM + --patch-module=<module name> + Java 9 --patch-module option. Passed as it is to JVM + --illegal-access=<value> + Java 9 --illegal-access option. Passed as it is to JVM. Refer java help for possible values.