diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-05-17 16:52:43 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-05-17 16:52:43 +0300 |
commit | 77fd1d9465ab1eb6431d8b0c5f570c9dc92b5dcf (patch) | |
tree | 567284867495ac56cbd26c7f60e1bd5f857b763a | |
parent | 6627f1c1d8acc2d53a9502a096123c0163bf731a (diff) | |
download | genrc-77fd1d9465ab1eb6431d8b0c5f570c9dc92b5dcf.tar.gz genrc-77fd1d9465ab1eb6431d8b0c5f570c9dc92b5dcf.tar.bz2 |
New option: --verbose
-rw-r--r-- | src/com_reload.c | 12 | ||||
-rw-r--r-- | src/com_start.c | 3 | ||||
-rw-r--r-- | src/com_stop.c | 3 | ||||
-rw-r--r-- | src/genrc.8 | 8 | ||||
-rw-r--r-- | src/genrc.c | 9 | ||||
-rw-r--r-- | src/genrc.h | 1 |
6 files changed, 32 insertions, 4 deletions
diff --git a/src/com_reload.c b/src/com_reload.c index fd12e7d..7a0f768 100644 --- a/src/com_reload.c +++ b/src/com_reload.c | |||
@@ -13,11 +13,23 @@ com_reload(void) | |||
13 | 13 | ||
14 | if (genrc_no_reload) | 14 | if (genrc_no_reload) |
15 | return com_restart(); | 15 | return com_restart(); |
16 | pidlist_init(&pids); | 16 | pidlist_init(&pids); |
17 | if (get_pid_list(genrc_pid_closure, &pids)) | 17 | if (get_pid_list(genrc_pid_closure, &pids)) |
18 | return 1; | 18 | return 1; |
19 | if (genrc_verbose) { | ||
20 | printf("Reloading %s: sending %s to %s ", | ||
21 | genrc_program, strsignal(genrc_signal_reload), | ||
22 | pids.pidc > 1 ? "PIDs" : "PID"); | ||
23 | printf("%lu", (unsigned long)pids.pidv[0]); | ||
24 | if (pids.pidc > 1) { | ||
25 | int i; | ||
26 | for (i = 0; i < pids.pidc; i++ ) | ||
27 | printf(",%lu", (unsigned long)pids.pidv[i]); | ||
28 | } | ||
29 | putchar('\n'); | ||
30 | } | ||
19 | pidlist_kill(&pids, genrc_signal_reload); | 31 | pidlist_kill(&pids, genrc_signal_reload); |
20 | return 0; | 32 | return 0; |
21 | } | 33 | } |
22 | 34 | ||
23 | 35 | ||
diff --git a/src/com_start.c b/src/com_start.c index 93c324e..65c1775 100644 --- a/src/com_start.c +++ b/src/com_start.c | |||
@@ -95,12 +95,15 @@ com_start(void) | |||
95 | if (running) { | 95 | if (running) { |
96 | genrc_error("%s is already running", genrc_program); | 96 | genrc_error("%s is already running", genrc_program); |
97 | return 1; | 97 | return 1; |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | if (genrc_verbose) | ||
102 | printf("Starting %s\n", genrc_program); | ||
103 | |||
101 | if ((p = getenv("GENRC_SENTINEL")) && *p == '1') | 104 | if ((p = getenv("GENRC_SENTINEL")) && *p == '1') |
102 | return sentinel(); | 105 | return sentinel(); |
103 | 106 | ||
104 | pid = fork(); | 107 | pid = fork(); |
105 | if (pid == -1) { | 108 | if (pid == -1) { |
106 | system_error(errno, "fork"); | 109 | system_error(errno, "fork"); |
diff --git a/src/com_stop.c b/src/com_stop.c index 1cb4452..d57fa5e 100644 --- a/src/com_stop.c +++ b/src/com_stop.c | |||
@@ -32,12 +32,15 @@ com_stop(void) | |||
32 | 32 | ||
33 | if (pids.pidc == 0) { | 33 | if (pids.pidc == 0) { |
34 | genrc_error("%s not running", genrc_program); | 34 | genrc_error("%s not running", genrc_program); |
35 | return 1; | 35 | return 1; |
36 | } | 36 | } |
37 | 37 | ||
38 | if (genrc_verbose) | ||
39 | printf("Stopping %s\n", genrc_program); | ||
40 | |||
38 | gettimeofday(&stoptime, NULL); | 41 | gettimeofday(&stoptime, NULL); |
39 | stoptime.tv_sec += genrc_timeout; | 42 | stoptime.tv_sec += genrc_timeout; |
40 | ratio = 1; | 43 | ratio = 1; |
41 | while (pids.pidc) { | 44 | while (pids.pidc) { |
42 | gettimeofday(&before, NULL); | 45 | gettimeofday(&before, NULL); |
43 | if (timercmp(&before, &stoptime, >)) | 46 | if (timercmp(&before, &stoptime, >)) |
diff --git a/src/genrc.8 b/src/genrc.8 index 920252e..b750894 100644 --- a/src/genrc.8 +++ b/src/genrc.8 | |||
@@ -10,19 +10,19 @@ | |||
10 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | .\" GNU General Public License for more details. | 12 | .\" GNU General Public License for more details. |
13 | .\" | 13 | .\" |
14 | .\" You should have received a copy of the GNU General Public License | 14 | .\" You should have received a copy of the GNU General Public License |
15 | .\" along with genrc. If not, see <http://www.gnu.org/licenses/>. | 15 | .\" along with genrc. If not, see <http://www.gnu.org/licenses/>. |
16 | .TH GENRC 8 "May 15, 2018" "GENRC" "Genrc User Manual" | 16 | .TH GENRC 8 "May 17, 2018" "GENRC" "Genrc User Manual" |
17 | .SH NAME | 17 | .SH NAME |
18 | genrc \- generic system initialization script helper | 18 | genrc \- generic system initialization script helper |
19 | .SH SYNOPSIS | 19 | .SH SYNOPSIS |
20 | .nh | 20 | .nh |
21 | \fBgenrc\fR\ | 21 | \fBgenrc\fR\ |
22 | [\fB\-h\fR]\ | 22 | [\fB\-hv\fR]\ |
23 | [\fB\-F\fR \fIPIDFILE\fR]\ | 23 | [\fB\-F\fR \fIPIDFILE\fR]\ |
24 | [\fB\-P\fR \fISOURCE\fR]\ | 24 | [\fB\-P\fR \fISOURCE\fR]\ |
25 | [\fB\-c\fR \fICOMMAND\fR]\ | 25 | [\fB\-c\fR \fICOMMAND\fR]\ |
26 | [\fB\-p\fR \fIPROGRAM\fR]\ | 26 | [\fB\-p\fR \fIPROGRAM\fR]\ |
27 | [\fB\-t\fR \fISECONDS\fR]\ | 27 | [\fB\-t\fR \fISECONDS\fR]\ |
28 | [\fB\-\-command=\fICOMMAND\fR]\ | 28 | [\fB\-\-command=\fICOMMAND\fR]\ |
@@ -34,12 +34,13 @@ genrc \- generic system initialization script helper | |||
34 | [\fB\-\-program=\fIPROGRAM\fR]\ | 34 | [\fB\-\-program=\fIPROGRAM\fR]\ |
35 | [\fB\-\-sentinel\fR]\ | 35 | [\fB\-\-sentinel\fR]\ |
36 | [\fB\-\-signal\-reload=\fISIG\fR]\ | 36 | [\fB\-\-signal\-reload=\fISIG\fR]\ |
37 | [\fB\-\-signal\-stop=\fISIG\fR]\ | 37 | [\fB\-\-signal\-stop=\fISIG\fR]\ |
38 | [\fB\-\-timeout=\fISECONDS\fR]\ | 38 | [\fB\-\-timeout=\fISECONDS\fR]\ |
39 | [\fB\-\-usage\fR]\ | 39 | [\fB\-\-usage\fR]\ |
40 | [\fB\-\-verbose\fR]\ | ||
40 | {\ | 41 | {\ |
41 | \fBstart\fR\ | 42 | \fBstart\fR\ |
42 | |\ | 43 | |\ |
43 | \fBstop\fR\ | 44 | \fBstop\fR\ |
44 | |\ | 45 | |\ |
45 | \fBrestart\fR\ | 46 | \fBrestart\fR\ |
@@ -190,12 +191,15 @@ Time to wait for the program to start up or terminate. | |||
190 | .TP | 191 | .TP |
191 | \fB\-\-usage\fR | 192 | \fB\-\-usage\fR |
192 | Display a short usage summary. | 193 | Display a short usage summary. |
193 | .TP | 194 | .TP |
194 | \fB\-\-version\fR | 195 | \fB\-\-version\fR |
195 | Display program version and exit. | 196 | Display program version and exit. |
197 | .TP | ||
198 | \fB\-v\fR, \fB\-\-verbose\fR | ||
199 | Print verbose messages (e.g. "Starting \fIPROGNAME\fR"). | ||
196 | .SH PID SOURCES | 200 | .SH PID SOURCES |
197 | .TP | 201 | .TP |
198 | \fBFILE:\fIFILENAME\fR | 202 | \fBFILE:\fIFILENAME\fR |
199 | Read PID from the file \fIFILENAME\fR. | 203 | Read PID from the file \fIFILENAME\fR. |
200 | .TP | 204 | .TP |
201 | \fBCONFIG:\fILANG\fB:\fIFILENAME\fB:\fIFQRN\fR | 205 | \fBCONFIG:\fILANG\fB:\fIFILENAME\fB:\fIFQRN\fR |
diff --git a/src/genrc.c b/src/genrc.c index 3f89d03..92b0fac 100644 --- a/src/genrc.c +++ b/src/genrc.c | |||
@@ -13,12 +13,13 @@ char *genrc_pid_from; | |||
13 | unsigned genrc_timeout = 5; | 13 | unsigned genrc_timeout = 5; |
14 | int genrc_no_reload; | 14 | int genrc_no_reload; |
15 | int genrc_signal_stop = SIGTERM; | 15 | int genrc_signal_stop = SIGTERM; |
16 | int genrc_signal_reload = SIGHUP; | 16 | int genrc_signal_reload = SIGHUP; |
17 | GENRC_PID_CLOSURE *genrc_pid_closure; | 17 | GENRC_PID_CLOSURE *genrc_pid_closure; |
18 | char *genrc_create_pidfile; | 18 | char *genrc_create_pidfile; |
19 | int genrc_verbose; | ||
19 | 20 | ||
20 | 21 | ||
21 | enum { | 22 | enum { |
22 | OPT_USAGE = 256, | 23 | OPT_USAGE = 256, |
23 | OPT_VERSION, | 24 | OPT_VERSION, |
24 | OPT_SIGNAL_RELOAD, | 25 | OPT_SIGNAL_RELOAD, |
@@ -38,15 +39,16 @@ struct option longopts[] = { | |||
38 | { "signal-reload", required_argument, 0, OPT_SIGNAL_RELOAD }, | 39 | { "signal-reload", required_argument, 0, OPT_SIGNAL_RELOAD }, |
39 | { "no-reload", no_argument, 0, OPT_NO_RELOAD }, | 40 | { "no-reload", no_argument, 0, OPT_NO_RELOAD }, |
40 | { "signal-stop", required_argument, 0, OPT_SIGNAL_STOP }, | 41 | { "signal-stop", required_argument, 0, OPT_SIGNAL_STOP }, |
41 | { "sentinel", no_argument, 0, 'S' }, | 42 | { "sentinel", no_argument, 0, 'S' }, |
42 | { "create-pidfile", required_argument, 0, OPT_CREATE_PIDFILE }, | 43 | { "create-pidfile", required_argument, 0, OPT_CREATE_PIDFILE }, |
43 | { "version", no_argument, 0, OPT_VERSION }, | 44 | { "version", no_argument, 0, OPT_VERSION }, |
45 | { "verbose", no_argument, 0, 'v' }, | ||
44 | { NULL } | 46 | { NULL } |
45 | }; | 47 | }; |
46 | char shortopts[] = "c:hF:P:p:St:"; | 48 | char shortopts[] = "c:hF:P:p:St:v"; |
47 | 49 | ||
48 | struct sigdefn { | 50 | struct sigdefn { |
49 | char const *sig_name; | 51 | char const *sig_name; |
50 | int sig_no; | 52 | int sig_no; |
51 | }; | 53 | }; |
52 | 54 | ||
@@ -399,12 +401,15 @@ main(int argc, char **argv) | |||
399 | case OPT_SIGNAL_RELOAD: | 401 | case OPT_SIGNAL_RELOAD: |
400 | setenv("GENRC_SIGNAL_RELOAD", optarg, 1); | 402 | setenv("GENRC_SIGNAL_RELOAD", optarg, 1); |
401 | break; | 403 | break; |
402 | case OPT_SIGNAL_STOP: | 404 | case OPT_SIGNAL_STOP: |
403 | setenv("GENRC_SIGNAL_STOP", optarg, 1); | 405 | setenv("GENRC_SIGNAL_STOP", optarg, 1); |
404 | break; | 406 | break; |
407 | case 'v': | ||
408 | genrc_verbose++; | ||
409 | break; | ||
405 | default: | 410 | default: |
406 | exit(1); | 411 | exit(1); |
407 | } | 412 | } |
408 | } | 413 | } |
409 | 414 | ||
410 | if ((p = getenv("GENRC_COMMAND")) != NULL) | 415 | if ((p = getenv("GENRC_COMMAND")) != NULL) |
@@ -465,13 +470,13 @@ main(int argc, char **argv) | |||
465 | } else if (genrc_create_pidfile) { | 470 | } else if (genrc_create_pidfile) { |
466 | p = xmalloc(6 + strlen(genrc_create_pidfile)); | 471 | p = xmalloc(6 + strlen(genrc_create_pidfile)); |
467 | strcat(strcpy(p, "FILE:"), genrc_create_pidfile); | 472 | strcat(strcpy(p, "FILE:"), genrc_create_pidfile); |
468 | genrc_pid_closure = get_pid_closure(p); | 473 | genrc_pid_closure = get_pid_closure(p); |
469 | free(p); | 474 | free(p); |
470 | } else { | 475 | } else { |
471 | genrc_pid_closure = get_pid_closure("PROC"); | 476 | genrc_pid_closure = get_pid_closure(DEFAULT_PID_SOURCE); |
472 | } | 477 | } |
473 | 478 | ||
474 | argc -= optind; | 479 | argc -= optind; |
475 | if (argc == 0) | 480 | if (argc == 0) |
476 | usage_error("missing command verb"); | 481 | usage_error("missing command verb"); |
477 | if (argc > 1) |