unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] write the daemon's pid to a file.
@ 2013-12-08 11:13 John Darrington
  2013-12-08 15:35 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: John Darrington @ 2013-12-08 11:13 UTC (permalink / raw)
  To: guix-devel


[-- Attachment #1.1: Type: text/plain, Size: 370 bytes --]

I don't know what you will think of this patch.  But I found that it makes 
running guix under debian a whole lot easier.  I suspect the same will be
true for many other OSes too.

J'


-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://sks-keyservers.net or any PGP keyserver for public key.


[-- Attachment #1.2: 0001-guix-daemon-New-option-pid-file-FILE.patch --]
[-- Type: text/x-diff, Size: 2921 bytes --]

From 20f5f5c28b773bb4e6164cd4e8df35ef62e3dffd Mon Sep 17 00:00:00 2001
From: John Darrington <john@darrington.wattle.id.au>
Date: Sat, 30 Nov 2013 15:30:48 +0100
Subject: [PATCH] guix-daemon: New option --pid-file=FILE

* Added a new option to write the daemon's pid to a file.  This is
necessary for the clean integration into sysV like systems such as
used by Debian and other vendors.
---
 nix/nix-daemon/guix-daemon.cc |    9 +++++++++
 nix/sync-with-upstream        |   16 ++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc
index 4f9fa4c..d703324 100644
--- a/nix/nix-daemon/guix-daemon.cc
+++ b/nix/nix-daemon/guix-daemon.cc
@@ -67,6 +67,7 @@ builds derivations on behalf of its clients.";
 #define GUIX_OPT_CHROOT_DIR 10
 #define GUIX_OPT_LISTEN 11
 #define GUIX_OPT_NO_SUBSTITUTES 12
+#define GUIX_OPT_PID_FILE 13
 
 static const struct argp_option options[] =
   {
@@ -94,6 +95,8 @@ static const struct argp_option options[] =
       "Perform builds as a user of GROUP" },
     { "no-substitutes", GUIX_OPT_NO_SUBSTITUTES, 0, 0,
       "Do not use substitutes" },
+    { "pid-file", GUIX_OPT_PID_FILE, "FILE", 0,
+      "Write the daemon's process ID to FILE" },
     { "cache-failures", GUIX_OPT_CACHE_FAILURES, 0, 0,
       "Cache build failures" },
     { "lose-logs", GUIX_OPT_LOSE_LOGS, 0, 0,
@@ -171,6 +174,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case GUIX_OPT_SYSTEM:
       settings.thisSystem = arg;
       break;
+    case GUIX_OPT_PID_FILE:
+      settings.nixDaemonPidFile = arg;
+      break;
     default:
       return (error_t) ARGP_ERR_UNKNOWN;
     }
@@ -247,6 +253,9 @@ main (int argc, char *argv[])
       printMsg (lvlDebug,
 		format ("listening on `%1%'") % settings.nixDaemonSocketFile);
 
+      if (settings.nixDaemonPidFile != "")
+	writeFile (settings.nixDaemonPidFile, int2String(getpid()));
+
       run (nothing);
     }
   catch (std::exception &e)
diff --git a/nix/sync-with-upstream b/nix/sync-with-upstream
index 535763d..d60406f 100755
--- a/nix/sync-with-upstream
+++ b/nix/sync-with-upstream
@@ -70,3 +70,19 @@ cp -v "$top_srcdir/nix-upstream/AUTHORS" "$top_srcdir/nix"
 # Substitutions.
 sed -i "$top_srcdir/nix/libstore/gc.cc"					\
     -e 's|/nix/find-runtime-roots\.pl|/guix/list-runtime-roots|g'
+
+
+patch -p 1 << EOF
+--- a/nix/libstore/globals.hh	2013-11-30 18:13:33.000000000 +0100
++++ b/nix/libstore/globals.hh	2013-11-30 18:15:32.000000000 +0100
+@@ -53,6 +53,9 @@
+     /* File name of the socket the daemon listens to.  */
+     Path nixDaemonSocketFile;
+ 
++    /* File name of the to which the daemon PID will be written.  */
++    Path nixDaemonPidFile;
++
+     /* Whether to keep temporary directories of failed builds. */
+     bool keepFailed;
+EOF
+ 
-- 
1.7.10.4


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] write the daemon's pid to a file.
  2013-12-08 11:13 [PATCH] write the daemon's pid to a file John Darrington
@ 2013-12-08 15:35 ` Ludovic Courtès
  2013-12-08 16:06   ` [PATCH] write the daemon's pid to a file.el John Darrington
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2013-12-08 15:35 UTC (permalink / raw)
  To: John Darrington; +Cc: guix-devel

John Darrington <john@darrington.wattle.id.au> skribis:

> I don't know what you will think of this patch.  But I found that it makes 
> running guix under debian a whole lot easier.  I suspect the same will be
> true for many other OSes too.

How does it help exactly?  On GNU, it’s started by dmd, which knows its PID.
I’d expect it to be the same with other init systems, no?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] write the daemon's pid to a file.el
  2013-12-08 15:35 ` Ludovic Courtès
@ 2013-12-08 16:06   ` John Darrington
  0 siblings, 0 replies; 3+ messages in thread
From: John Darrington @ 2013-12-08 16:06 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1694 bytes --]

Debian uses a script and a program start-stop-daemon.  FRom the man page:

       Note: unless --pidfile is specified, start-stop-daemon behaves  similar  to  killall(1).   start-stop-daemon  will  scan  the
       process  table  looking  for any processes which match the process name, uid, and/or gid (if specified). Any matching process
       will prevent --start from starting the daemon. All matching processes will be sent the TERM signal (or the one specified  via
       --signal  or --retry) if --stop is specified. For daemons which have long-lived children which need to live through a --stop,
       you must specify a pidfile.

Of course, one can get the pid by doing

 guix-daemon --blah-blah & 
 pid=$!

But the problem here is that the & means you never know when the daemon has actually started,
which leads to race conditions.  Again, there are tricks to work around that, but having the daemon 
write its own pid makes it a lot easier.

J'

On Sun, Dec 08, 2013 at 04:35:40PM +0100, Ludovic Courtès wrote:
     John Darrington <john@darrington.wattle.id.au> skribis:
     
     > I don't know what you will think of this patch.  But I found that it makes 
     > running guix under debian a whole lot easier.  I suspect the same will be
     > true for many other OSes too.
     
     How does it help exactly?  On GNU, it’s started by dmd, which knows its PID.
     I’d expect it to be the same with other init systems, no?
     
     Thanks,
     Ludo’.

-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://sks-keyservers.net or any PGP keyserver for public key.


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-12-08 16:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-08 11:13 [PATCH] write the daemon's pid to a file John Darrington
2013-12-08 15:35 ` Ludovic Courtès
2013-12-08 16:06   ` [PATCH] write the daemon's pid to a file.el John Darrington

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).