aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com_reload.c12
-rw-r--r--src/com_start.c3
-rw-r--r--src/com_stop.c3
-rw-r--r--src/genrc.88
-rw-r--r--src/genrc.c9
-rw-r--r--src/genrc.h1
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)
if (genrc_no_reload)
return com_restart();
pidlist_init(&pids);
if (get_pid_list(genrc_pid_closure, &pids))
return 1;
+ if (genrc_verbose) {
+ printf("Reloading %s: sending %s to %s ",
+ genrc_program, strsignal(genrc_signal_reload),
+ pids.pidc > 1 ? "PIDs" : "PID");
+ printf("%lu", (unsigned long)pids.pidv[0]);
+ if (pids.pidc > 1) {
+ int i;
+ for (i = 0; i < pids.pidc; i++ )
+ printf(",%lu", (unsigned long)pids.pidv[i]);
+ }
+ putchar('\n');
+ }
pidlist_kill(&pids, genrc_signal_reload);
return 0;
}
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)
if (running) {
genrc_error("%s is already running", genrc_program);
return 1;
}
}
+ if (genrc_verbose)
+ printf("Starting %s\n", genrc_program);
+
if ((p = getenv("GENRC_SENTINEL")) && *p == '1')
return sentinel();
pid = fork();
if (pid == -1) {
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)
if (pids.pidc == 0) {
genrc_error("%s not running", genrc_program);
return 1;
}
+ if (genrc_verbose)
+ printf("Stopping %s\n", genrc_program);
+
gettimeofday(&stoptime, NULL);
stoptime.tv_sec += genrc_timeout;
ratio = 1;
while (pids.pidc) {
gettimeofday(&before, NULL);
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 @@
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with genrc. If not, see <http://www.gnu.org/licenses/>.
-.TH GENRC 8 "May 15, 2018" "GENRC" "Genrc User Manual"
+.TH GENRC 8 "May 17, 2018" "GENRC" "Genrc User Manual"
.SH NAME
genrc \- generic system initialization script helper
.SH SYNOPSIS
.nh
\fBgenrc\fR\
- [\fB\-h\fR]\
+ [\fB\-hv\fR]\
[\fB\-F\fR \fIPIDFILE\fR]\
[\fB\-P\fR \fISOURCE\fR]\
[\fB\-c\fR \fICOMMAND\fR]\
[\fB\-p\fR \fIPROGRAM\fR]\
[\fB\-t\fR \fISECONDS\fR]\
[\fB\-\-command=\fICOMMAND\fR]\
@@ -34,12 +34,13 @@ genrc \- generic system initialization script helper
[\fB\-\-program=\fIPROGRAM\fR]\
[\fB\-\-sentinel\fR]\
[\fB\-\-signal\-reload=\fISIG\fR]\
[\fB\-\-signal\-stop=\fISIG\fR]\
[\fB\-\-timeout=\fISECONDS\fR]\
[\fB\-\-usage\fR]\
+ [\fB\-\-verbose\fR]\
{\
\fBstart\fR\
|\
\fBstop\fR\
|\
\fBrestart\fR\
@@ -190,12 +191,15 @@ Time to wait for the program to start up or terminate.
.TP
\fB\-\-usage\fR
Display a short usage summary.
.TP
\fB\-\-version\fR
Display program version and exit.
+.TP
+\fB\-v\fR, \fB\-\-verbose\fR
+Print verbose messages (e.g. "Starting \fIPROGNAME\fR").
.SH PID SOURCES
.TP
\fBFILE:\fIFILENAME\fR
Read PID from the file \fIFILENAME\fR.
.TP
\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;
unsigned genrc_timeout = 5;
int genrc_no_reload;
int genrc_signal_stop = SIGTERM;
int genrc_signal_reload = SIGHUP;
GENRC_PID_CLOSURE *genrc_pid_closure;
char *genrc_create_pidfile;
+int genrc_verbose;
enum {
OPT_USAGE = 256,
OPT_VERSION,
OPT_SIGNAL_RELOAD,
@@ -38,15 +39,16 @@ struct option longopts[] = {
{ "signal-reload", required_argument, 0, OPT_SIGNAL_RELOAD },
{ "no-reload", no_argument, 0, OPT_NO_RELOAD },
{ "signal-stop", required_argument, 0, OPT_SIGNAL_STOP },
{ "sentinel", no_argument, 0, 'S' },
{ "create-pidfile", required_argument, 0, OPT_CREATE_PIDFILE },
{ "version", no_argument, 0, OPT_VERSION },
+ { "verbose", no_argument, 0, 'v' },
{ NULL }
};
-char shortopts[] = "c:hF:P:p:St:";
+char shortopts[] = "c:hF:P:p:St:v";
struct sigdefn {
char const *sig_name;
int sig_no;
};
@@ -399,12 +401,15 @@ main(int argc, char **argv)
case OPT_SIGNAL_RELOAD:
setenv("GENRC_SIGNAL_RELOAD", optarg, 1);
break;
case OPT_SIGNAL_STOP:
setenv("GENRC_SIGNAL_STOP", optarg, 1);
break;
+ case 'v':
+ genrc_verbose++;
+ break;
default:
exit(1);
}
}
if ((p = getenv("GENRC_COMMAND")) != NULL)
@@ -465,13 +470,13 @@ main(int argc, char **argv)
} else if (genrc_create_pidfile) {
p = xmalloc(6 + strlen(genrc_create_pidfile));
strcat(strcpy(p, "FILE:"), genrc_create_pidfile);
genrc_pid_closure = get_pid_closure(p);
free(p);
} else {
- genrc_pid_closure = get_pid_closure("PROC");
+ genrc_pid_closure = get_pid_closure(DEFAULT_PID_SOURCE);
}
argc -= optind;
if (argc == 0)
usage_error("missing command verb");
if (argc > 1)
diff --git a/src/genrc.h b/src/genrc.h
index 13b40d7..a6e81e8 100644
--- a/src/genrc.h
+++ b/src/genrc.h
@@ -129,12 +129,13 @@ extern char *genrc_pid_from;
extern unsigned genrc_timeout;
extern int genrc_no_reload;
extern int genrc_signal_reload;
extern int genrc_signal_stop;
extern GENRC_PID_CLOSURE *genrc_pid_closure;
extern char *genrc_create_pidfile;
+extern int genrc_verbose;
int sentinel(void);
int com_start(void);
int com_status(void);
int com_stop(void);

Return to:

Send suggestions and report system problems to the System administrator.