wolfgangj.scm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ;; wolfgangj.scm -- Personal dmd configuration of Wolfgang Jährling.
  2. ;; Copyright (C) 2002, 2003 Wolfgang Jährling <wolfgang@pro-linux.de>
  3. ;;
  4. ;; This file is part of the GNU Shepherd.
  5. ;;
  6. ;; The GNU Shepherd is free software; you can redistribute it and/or modify it
  7. ;; under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;; your option) any later version.
  10. ;;
  11. ;; The GNU Shepherd is distributed in the hope that it will be useful, but
  12. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;;
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with the GNU Shepherd. If not, see <http://www.gnu.org/licenses/>.
  18. ;; A few notes about the computer this setup is for: It is a PC
  19. ;; running Debian GNU/Linux 3.0, on which I am usually using screen,
  20. ;; which is why I need few terminals. I am using it to connect to the
  21. ;; internet via ISDN, but I'm also using it in my local network, in
  22. ;; which case it is running Apache. Because I don't want to have
  23. ;; Apache running when I am online, I made Apache conflict with the
  24. ;; ISDN setup.
  25. (use-modules (srfi srfi-1))
  26. ;; Laziness.
  27. (define (number->symbol num)
  28. (string->symbol (number->string num)))
  29. ;; Even more laziness.
  30. (define cat string-append)
  31. ;; Some values for this system.
  32. (define getty "/sbin/getty")
  33. (define ifconfig "/sbin/ifconfig")
  34. (define isdnctrl "/usr/sbin/isdnctrl")
  35. (define inet-interface "ippp0")
  36. (define inet-dial (cat isdnctrl " dial " inet-interface))
  37. (define inet-hangup (cat isdnctrl " hangup " inet-interface))
  38. (define local-interface "eth0")
  39. (define local-ip "192.168.0.9")
  40. (define init.d-dir "/etc/init.d/")
  41. (define apache (cat init.d-dir "apache"))
  42. (define inet (cat init.d-dir "isdnutils"))
  43. (define exim (cat init.d-dir "exim"))
  44. ;; Create a service providing a terminal.
  45. (define (make-term num)
  46. (let ((sym (symbol-append 'term- (number->symbol num))))
  47. (make <service>
  48. #:provides (list sym)
  49. #:respawn? #t
  50. #:start (make-forkexec-constructor getty "38400"
  51. (cat "tty" (number->string num)))
  52. #:stop-delay? #t)))
  53. ;; Number of terminals created by default.
  54. (define default-terms 3)
  55. ;; How many terms have been created with `add-new-term'.
  56. (define term-counter 0)
  57. ;; Add a new terminal to the list of registered services.
  58. (define (add-new-term)
  59. (set! term-counter (+ term-counter 1))
  60. (register-services (make-term term-counter)))
  61. (register-services
  62. (make <service>
  63. #:provides '(term)
  64. #:actions (make-actions
  65. (create "Create a new terminal."
  66. (lambda (running)
  67. (add-new-term)))
  68. (counter-set "Set the terminal creation counter."
  69. (lambda (running num)
  70. (set! term-counter (string->number num))))
  71. (status "Display the terminal creation counter."
  72. (lambda (running)
  73. (local-output "Terminal counter is at ~a."
  74. term-counter)))))
  75. (make <service>
  76. #:provides '(apache insecurity)
  77. #:requires '(local-net)
  78. #:start (make-system-constructor apache " start")
  79. #:stop (make-system-destructor apache " stop"))
  80. (make <service>
  81. #:provides '(inet insecurity)
  82. #:start (make-system-constructor inet " start")
  83. #:stop (make-system-destructor inet " stop")
  84. #:actions (make-actions
  85. (dial "Connect to the big, evil internet."
  86. (lambda (running)
  87. (system inet-dial)
  88. #t))
  89. (hangup "Cut the internet connection."
  90. (lambda (running)
  91. (system inet-hangup)
  92. #t))))
  93. (make <service>
  94. #:provides '(local-net)
  95. #:start (make-system-constructor ifconfig " " local-interface " " local-ip)
  96. #:stop (make-system-destructor ifconfig " " local-interface " down"))
  97. (make <service>
  98. #:provides '(exim mailer-daemon)
  99. #:requires '(inet)
  100. #:start (make-system-constructor exim " start")
  101. #:stop (make-system-destructor exim " stop")))
  102. ;; Create a few terminals.
  103. (letrec ((loop (lambda (i)
  104. (and (not (zero? i))
  105. (begin
  106. (add-new-term)
  107. (loop (- i 1)))))))
  108. (loop default-terms))
  109. ;; Go into background.
  110. (action 'shepherd 'daemonize)
  111. ;; Setup internet, a mailer and a few terms.
  112. (for-each start
  113. (append '(term inet mailer-daemon)
  114. (map (lambda (x)
  115. (symbol-append 'term- (number->symbol x)))
  116. (iota default-terms 1))))