Previous: , Up: System Configuration   [Contents][Index]


6.2.11 Defining Services

The (gnu services …) modules define several procedures that allow users to declare the operating system’s services (see Using the Configuration System). These procedures are monadic procedures—i.e., procedures that return a monadic value in the store monad (see The Store Monad). For examples of such procedures, See Services.

The monadic value returned by those procedures is a service definition—a structure as returned by the service form. Service definitions specifies the inputs the service depends on, and an expression to start and stop the service. Behind the scenes, service definitions are “translated” into the form suitable for the configuration file of dmd, the init system (see Services in GNU dmd Manual).

As an example, here is what the nscd-service procedure looks like:

(define (nscd-service)
  (with-monad %store-monad
    (return (service
             (documentation "Run libc's name service cache daemon.")
             (provision '(nscd))
             (activate #~(begin
                           (use-modules (guix build utils))
                           (mkdir-p "/var/run/nscd")))
             (start #~(make-forkexec-constructor
                       (string-append #$glibc "/sbin/nscd")
                       "-f" "/dev/null" "--foreground"))
             (stop #~(make-kill-destructor))
             (respawn? #f)))))

The activate, start, and stop fields are G-expressions (see G-Expressions). The activate field contains a script to run at “activation” time; it makes sure that the /var/run/nscd directory exists before nscd is started.

The start and stop fields refer to dmd’s facilities to start and stop processes (see Service De- and Constructors in GNU dmd Manual). The provision field specifies the name under which this service is known to dmd, and documentation specifies on-line documentation. Thus, the commands deco start ncsd, deco stop nscd, and deco doc nscd will do what you would expect (see Invoking deco in GNU dmd Manual).


Previous: , Up: System Configuration   [Contents][Index]