You've already forked fruix-bootstrap
105 lines
4.0 KiB
Scheme
105 lines
4.0 KiB
Scheme
(define-module (fruix shepherd freebsd)
|
|
#:use-module (shepherd service)
|
|
#:use-module (shepherd support)
|
|
#:use-module (ice-9 popen)
|
|
#:export (freebsd-rc-service
|
|
freebsd-loopback-alias-service
|
|
freebsd-tmpfs-service
|
|
freebsd-user-group-service))
|
|
|
|
(define (run-command program . args)
|
|
(let ((status (apply system* program args)))
|
|
(unless (zero? status)
|
|
(error "command failed" (cons program args) status))
|
|
#t))
|
|
|
|
(define (run-command/ignore-errors program . args)
|
|
(apply system* program args)
|
|
#t)
|
|
|
|
(define* (freebsd-rc-service provision script-name
|
|
#:key
|
|
(requirement '())
|
|
(documentation
|
|
"Manage a FreeBSD rc.d service through 'service'."))
|
|
(service provision
|
|
#:documentation documentation
|
|
#:requirement requirement
|
|
#:start (lambda _
|
|
(run-command "/usr/sbin/service" script-name "onestart")
|
|
#t)
|
|
#:stop (lambda _
|
|
(run-command "/usr/sbin/service" script-name "onestop")
|
|
#f)
|
|
#:respawn? #f))
|
|
|
|
(define* (freebsd-loopback-alias-service provision address
|
|
#:key
|
|
(interface "lo0")
|
|
(cidr "32")
|
|
(requirement '())
|
|
(documentation
|
|
"Add and remove a loopback alias on FreeBSD."))
|
|
(service provision
|
|
#:documentation documentation
|
|
#:requirement requirement
|
|
#:start (lambda _
|
|
(run-command "/sbin/ifconfig" interface "alias"
|
|
(string-append address "/" cidr))
|
|
#t)
|
|
#:stop (lambda _
|
|
(run-command "/sbin/ifconfig" interface "-alias" address)
|
|
#f)
|
|
#:respawn? #f))
|
|
|
|
(define* (freebsd-tmpfs-service provision mount-point
|
|
#:key
|
|
(size "1m")
|
|
(mode "0750")
|
|
(requirement '())
|
|
(documentation
|
|
"Mount and unmount a tmpfs filesystem on FreeBSD."))
|
|
(service provision
|
|
#:documentation documentation
|
|
#:requirement requirement
|
|
#:start (lambda _
|
|
(run-command "/bin/mkdir" "-p" mount-point)
|
|
(run-command "/sbin/mount" "-t" "tmpfs"
|
|
"-o" (string-append "size=" size ",mode=" mode)
|
|
"tmpfs" mount-point)
|
|
#t)
|
|
#:stop (lambda _
|
|
(run-command "/sbin/umount" mount-point)
|
|
#f)
|
|
#:respawn? #f))
|
|
|
|
(define* (freebsd-user-group-service provision user group
|
|
#:key
|
|
uid
|
|
gid
|
|
home
|
|
(shell "/usr/sbin/nologin")
|
|
(comment "Fruix Shepherd prototype account")
|
|
(requirement '())
|
|
(documentation
|
|
"Create and remove a temporary FreeBSD user/group pair."))
|
|
(service provision
|
|
#:documentation documentation
|
|
#:requirement requirement
|
|
#:start (lambda _
|
|
(run-command "/usr/sbin/pw" "groupadd" group
|
|
"-g" (number->string gid))
|
|
(run-command "/usr/sbin/pw" "useradd" user
|
|
"-u" (number->string uid)
|
|
"-g" group
|
|
"-d" home
|
|
"-m"
|
|
"-s" shell
|
|
"-c" comment)
|
|
#t)
|
|
#:stop (lambda _
|
|
(run-command/ignore-errors "/usr/sbin/pw" "userdel" user "-r")
|
|
(run-command/ignore-errors "/usr/sbin/pw" "groupdel" group)
|
|
#f)
|
|
#:respawn? #f))
|