1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
| | # GNU Shepherd --- Ensure replacing services works properly
# Copyright © 2014, 2016 Ludovic Courtès <ludo@gnu.org>
# Copyright © 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
#
# This file is part of the GNU Shepherd.
#
# The GNU Shepherd is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# The GNU Shepherd is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the GNU Shepherd. If not, see <http://www.gnu.org/licenses/>.
shepherd --version
herd --version
socket="t-socket-$$"
conf="t-conf-$$"
rconf="t-rconf-$$"
log="t-log-$$"
stamp="t-stamp-$$"
pid="t-pid-$$"
herd="herd -s $socket"
trap "rm -f $socket $conf $rconf $stamp $log;
test -f $pid && kill \`cat $pid\` || true; rm -f $pid" EXIT
cat > "$conf"<<EOF
(use-modules (srfi srfi-26))
(register-services
(make <service>
#:provides '(test)
#:start (const #t)
#:actions (make-actions
(say-hello (lambda _
(call-with-output-file "$stamp"
(lambda (port)
(display "Hello" port))))))
#:respawn? #f))
EOF
rm -f "$pid" "$stamp" "$socket"
shepherd -I -s "$socket" -c "$conf" --pid="$pid" --log="$log" &
while ! test -f "$pid"; do sleep 0.5 ; done
$herd start test
if ! $herd say-hello test; then
echo "say-hello failed"
exit 1
fi
cat > "$rconf"<<EOF
(register-services
(make <service>
#:provides '(test)
#:start (const #t)
#:actions (make-actions
(say-goodbye (lambda _
(call-with-output-file "$stamp"
(lambda (port)
(display "Goodbye" port))))))
#:respawn? #f))
EOF
$herd load root "$rconf"
if ! $herd say-hello test; then
echo "say-hello failed after setting replacement"
exit 1
fi
if test "`cat $stamp`" != "Hello"; then
echo "Output file had the wrong contents! Was:"
cat $stamp
exit 1
fi
$herd stop test
$herd start test
if $herd say-hello test; then
echo "say-hello should have failed after stop/start"
exit 1
fi
if ! $herd say-goodbye test; then
echo "say-goodbye failed after replacement"
exit 1
fi
if test "`cat $stamp`" != "Goodbye"; then
echo "Output file had the wrong contents! Was:"
cat $stamp
exit 1
fi
|