From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: Invoking user shepherd; Was: Re: Defining *user* services in Guix Date: Tue, 13 Jun 2017 10:06:16 +0200 Message-ID: <87fuf448hz.fsf@gnu.org> References: <87o9vowfn0.fsf@gmail.com> <20170422203131.610f2a30@scratchpost.org> <878tmsghzk.fsf@gnu.org> <87inlvdr76.fsf@gmail.com> <87r30hbbi7.fsf@gmail.com> <87fugwsx2s.fsf@elephly.net> <8737cu7z0s.fsf@gnu.org> <877f24pnem.fsf@gmail.com> <87mvavk243.fsf@gnu.org> <20170611032900.6ac194b9@scratchpost.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKgqI-0003W4-TU for guix-devel@gnu.org; Tue, 13 Jun 2017 04:06:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKgqH-0002gj-N2 for guix-devel@gnu.org; Tue, 13 Jun 2017 04:06:26 -0400 In-Reply-To: <20170611032900.6ac194b9@scratchpost.org> (Danny Milosavljevic's message of "Sun, 11 Jun 2017 03:29:00 +0200") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Danny Milosavljevic Cc: guix-devel@gnu.org Hello! Danny Milosavljevic skribis: > For a real user shepherd, it would be nice if when I logged in twice usin= g the same user account (without logging out in-between - so resulting in t= wo sessions of that user) it would still only have one shepherd instance fo= r that user account in total - and if that instance (and remaining user pro= cesses for that matter) went away only when I logged out from *all* session= s of that user. > > I thought I could fake that by just trying to invoke shepherd on each ses= sion start and have it fail on the second attempt - but apparently we will = happily start an infinite number of shepherds for one user. Is that on pur= pose? > > The relevant place (in shepherd) is: > > (define (open-server-socket file-name) > "Open a socket at FILE-NAME, and listen for connections there." > (with-fluids ((%default-port-encoding "UTF-8")) > (let ((sock (socket PF_UNIX SOCK_STREAM 0)) > (address (make-socket-address AF_UNIX file-name))) > (false-if-exception (delete-file file-name)) ; <=3D=3D=3D=3D=3D [d= annym: WTF. Would it be better to try to connect first?] > (bind sock address) > (listen sock 10) > sock))) > > Probably not good. The =E2=80=98delete-file=E2=80=99 was to avoid EADDRINUSE but I wonder if i= t=E2=80=99s really a good idea. > Maybe better: > > (define (server-present? file-name) > "Open a socket at FILE-NAME, and connect to the server, if any. Return= #t if that worked." > (with-fluids ((%default-port-encoding "UTF-8")) > (let ((sock (socket PF_UNIX SOCK_STREAM 0)) > (address (make-socket-address AF_UNIX file-name))) > (false-if-exception (connect sock address))))) ; probably missing a= "[catch] close". How to do that best? That=E2=80=99s a pretty good test. Note that (gnu services herd) and (shep= herd comm) already provide an =E2=80=98open-connection=E2=80=99 procedure to do = that. >From a shell script, you can also simply run =E2=80=9Cherd status root=E2= =80=9D and check the exit status. > I'm trying to find the right place to insert my "dbus-daemon" invocation = for providing the user bus (note: not session bus)... What=E2=80=99s the difference between a =E2=80=9Cuser bus=E2=80=9D and a = =E2=80=9Csession bus=E2=80=9D? In general, my understanding is that the user dbus-daemon (session bus?) is started on demand. > Should we make a system shepherd service that invokes the user shepherd s= ervice on behalf of users? Would that be that safe? The =E2=80=9Cguix user=E2=80=9D approach that Mathieu shown is more flexibl= e than having to do something in the =E2=80=98operating-system=E2=80=99 declaration IMO. > Or should we just expect the user to put a (shepherd with fix) invocation= into their HOME startup scripts like .xinitrc ? Note that if we did that = there's some session-specific stuff in the session's environment that sheph= erd will inherit. Probably not that bad if invoked early enough. Currently that=E2=80=99s what I do: my ~/.xinitrc runs shepherd and that=E2= =80=99s it. HTH, Ludo=E2=80=99.