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


6.6.3 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). Examples of such procedures include:

mingetty-service

return the definition of a service that runs mingetty to offer a login service on the given console tty;

nscd-service

return a definition for libc’s name service cache daemon (nscd);

guix-service

return a definition for a service that runs guix-daemon (see Invoking guix-daemon).

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)
  (mlet %store-monad ((nscd (package-file glibc "sbin/nscd")))
    (return (service
             (documentation "Run libc's name service cache daemon.")
             (provision '(nscd))
             (start `(make-forkexec-constructor ,nscd "-f" "/dev/null"
                                                "--foreground"))
             (stop  `(make-kill-destructor))

             (respawn? #f)
             (inputs `(("glibc" ,glibc)))))))

The inputs field specifies that this service depends on the glibc package—the package that contains the nscd program. The start and stop fields are expressions that make use of 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]