[PATCH 2/2] init: add the support for upstart
Federico Simoncelli
fsimonce at redhat.com
Mon Aug 6 16:28:53 UTC 2012
Signed-off-by: Federico Simoncelli <fsimonce at redhat.com>
---
init.d/sanlock | 11 +++++++++++
init.d/sanlock.upstart | 14 ++++++++++++++
init.d/wdmd | 11 +++++++++++
init.d/wdmd.upstart | 14 ++++++++++++++
sanlock.spec | 1 +
src/main.c | 12 +++++++++---
src/sanlock.8 | 3 +++
src/sanlock_internal.h | 3 ++-
wdmd/main.c | 9 +++++++--
wdmd/wdmd.8 | 4 ++++
10 files changed, 76 insertions(+), 6 deletions(-)
create mode 100644 init.d/sanlock.upstart
create mode 100644 init.d/wdmd.upstart
diff --git a/init.d/sanlock b/init.d/sanlock
index 83b35e8..e7d8002 100644
--- a/init.d/sanlock
+++ b/init.d/sanlock
@@ -28,10 +28,20 @@ exec="/usr/sbin/$prog"
SANLOCKUSER="sanlock"
SANLOCKOPTS="-U $SANLOCKUSER -G $SANLOCKUSER"
+INITCTL="/sbin/initctl"
[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+initctl_check() {
+ if [ -x "$INITCTL" ] && $INITCTL status $prog &> /dev/null; then
+ logger -t "$prog" \
+ -s "$prog is managed by upstart use initctl instead"
+ exit 14
+ fi
+}
+
start() {
+ initctl_check
[ -x $exec ] || exit 5
if [ ! -d /var/run/$prog ]; then
@@ -48,6 +58,7 @@ start() {
}
stop() {
+ initctl_check
PID=$(pidofproc -p $runfile $prog)
echo -n $"Sending stop signal $prog ($PID): "
diff --git a/init.d/sanlock.upstart b/init.d/sanlock.upstart
new file mode 100644
index 0000000..f65616e
--- /dev/null
+++ b/init.d/sanlock.upstart
@@ -0,0 +1,14 @@
+# sanlock upstart job
+start on stopped rc RUNLEVEL=[345]
+stop on runlevel [!345]
+
+respawn
+
+script
+ SANLOCKUSER="sanlock"
+ SANLOCKOPTS="-U $SANLOCKUSER -G $SANLOCKUSER"
+
+ [ -f /etc/sysconfig/sanlock ] && . /etc/sysconfig/sanlock
+
+ exec /usr/sbin/sanlock daemon -F $SANLOCKOPTS
+end script
diff --git a/init.d/wdmd b/init.d/wdmd
index af45561..60f454d 100644
--- a/init.d/wdmd
+++ b/init.d/wdmd
@@ -28,9 +28,18 @@ exec="/usr/sbin/$prog"
WDMDGROUP="sanlock"
WDMDOPTS="-G $WDMDGROUP"
+INITCTL="/sbin/initctl"
[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+initctl_check() {
+ if [ -x "$INITCTL" ] && $INITCTL status $prog &> /dev/null; then
+ logger -t "$prog" \
+ -s "$prog is managed by upstart use initctl instead"
+ exit 14
+ fi
+}
+
watchdog_check() {
if [ ! -c /dev/watchdog ]; then
echo -n $"Loading the softdog kernel module: "
@@ -41,6 +50,7 @@ watchdog_check() {
}
start() {
+ initctl_check
watchdog_check
[ -x $exec ] || exit 5
@@ -59,6 +69,7 @@ start() {
}
stop() {
+ initctl_check
PID=$(pidofproc -p $runfile $prog)
echo -n $"Sending stop signal $prog ($PID): "
diff --git a/init.d/wdmd.upstart b/init.d/wdmd.upstart
new file mode 100644
index 0000000..502d1b8
--- /dev/null
+++ b/init.d/wdmd.upstart
@@ -0,0 +1,14 @@
+# wdmd upstart job
+start on stopped rc RUNLEVEL=[345]
+stop on runlevel [!345]
+
+respawn
+
+script
+ WDMDUSER="sanlock"
+ WDMDOPTS="-G $WDMDUSER"
+
+ [ -f /etc/sysconfig/wdmd ] && . /etc/sysconfig/wdmd
+
+ exec /usr/sbin/wdmd -F $WDMDOPTS
+end script
diff --git a/sanlock.spec b/sanlock.spec
index 05c9c95..5217b74 100644
--- a/sanlock.spec
+++ b/sanlock.spec
@@ -108,6 +108,7 @@ fi
%files
%defattr(-,root,root,-)
+%doc init.d/sanlock.upstart init.d/wdmd.upstart
%if 0%{?fedora} >= 16
/lib/systemd/systemd-sanlock
/lib/systemd/systemd-wdmd
diff --git a/src/main.c b/src/main.c
index 247b3f4..4cac8d9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1523,7 +1523,7 @@ static int do_daemon(void)
/* TODO: copy comprehensive daemonization method from libvirtd */
- if (!com.debug) {
+ if (!com.debug && !com.foreground) {
if (daemon(0, 0) < 0) {
log_tool("cannot fork daemon\n");
exit(EXIT_FAILURE);
@@ -1698,6 +1698,7 @@ static void print_usage(void)
printf("\n");
printf("sanlock daemon [options]\n");
printf(" -D no fork and print all logging to stderr\n");
+ printf(" -F foreground (no fork)\n");
printf(" -Q 0|1 quiet error messages for common lock contention (0)\n");
printf(" -R 0|1 renewal debugging, log debug info about renewals (0)\n");
printf(" -L <pri> write logging at priority level and up to logfile (3 LOG_ERR))\n");
@@ -1898,13 +1899,18 @@ static int read_command_line(int argc, char *argv[])
optchar = p[1];
i++;
- /* the only option that does not have optionarg */
+ /* options that does not have optionarg */
if (optchar == 'D') {
- com.debug = 1;
+ com.foreground = 1;
log_stderr_priority = LOG_DEBUG;
continue;
}
+ if (optchar == 'F') {
+ com.foreground = 1;
+ continue;
+ }
+
if (i >= argc) {
log_tool("option '%c' requires arg", optchar);
exit(EXIT_FAILURE);
diff --git a/src/sanlock.8 b/src/sanlock.8
index e716264..55c26d5 100644
--- a/src/sanlock.8
+++ b/src/sanlock.8
@@ -206,6 +206,9 @@ COMMAND can be one of three primary top level choices
.BR -D " "
no fork and print all logging to stderr
+.BR -F " "
+foreground (no fork)
+
.BR -Q " 0|1"
quiet error messages for common lock contention
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index a69b367..366e961 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -250,7 +250,8 @@ EXTERN struct client *client;
struct command_line {
int type; /* COM_ */
int action; /* ACT_ */
- int debug;
+ int debug; /* -D */
+ int foreground; /* -F */
int debug_renew;
int quiet_fail;
int use_watchdog;
diff --git a/wdmd/main.c b/wdmd/main.c
index 17687be..2ded9f9 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -55,6 +55,7 @@ static int fire_timeout = DEFAULT_FIRE_TIMEOUT;
static int high_priority = DEFAULT_HIGH_PRIORITY;
static int daemon_quit;
static int daemon_debug;
+static int daemon_foreground;
static int socket_gid;
static time_t last_keepalive;
static char lockfile_path[PATH_MAX];
@@ -943,6 +944,7 @@ static void print_usage_and_exit(int status)
printf("--version, -V print version\n");
printf("--help, -h print usage\n");
printf("-D debug: no fork and print all logging to stderr\n");
+ printf("-F foreground (no fork)\n");
printf("-H <num> use high priority features (1 yes, 0 no, default %d)\n",
DEFAULT_HIGH_PRIORITY);
printf("-G <groupname> group ownership for the socket\n");
@@ -987,7 +989,7 @@ int main(int argc, char *argv[])
{0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "hVDH:G:",
+ c = getopt_long(argc, argv, "hVDFH:G:",
long_options, &option_index);
if (c == -1)
break;
@@ -1002,6 +1004,9 @@ int main(int argc, char *argv[])
case 'D':
daemon_debug = 1;
break;
+ case 'F':
+ daemon_foreground = 1;
+ break;
case 'G':
socket_gid = group_to_gid(optarg);
break;
@@ -1011,7 +1016,7 @@ int main(int argc, char *argv[])
}
}
- if (!daemon_debug) {
+ if (!daemon_debug && !daemon_foreground) {
if (daemon(0, 0) < 0) {
fprintf(stderr, "cannot fork daemon\n");
exit(EXIT_FAILURE);
diff --git a/wdmd/wdmd.8 b/wdmd/wdmd.8
index 2df7297..5d913b3 100644
--- a/wdmd/wdmd.8
+++ b/wdmd/wdmd.8
@@ -66,6 +66,10 @@ added in the future.)
Enable debugging to stderr and don't fork.
.TP
+.B \-F
+Keep wdmd in foreground.
+
+.TP
.BI \-H " num"
Enable (1) or disable (0) high priority features such as realtime
scheduling priority and mlockall.
--
1.7.1
More information about the sanlock-devel
mailing list