4 ## Run the command discarding all of its output.
9 ## Restart the services we know about.
11 echo -n
"Restarting services:"
13 ## Make sure that the server is actually running.
14 if ! silently tripectl version
; then
15 echo " tripe server not running."
19 ## Find out which of our services are actually configured to start.
20 ## We'll assume that a link to the service script is a good indication.
21 need_restart
=$
(perl
-e
'
22 for my $svc (@ARGV) { $svc{$svc} = 1; }
23 for my $link (</etc/tripe/services/*>) {
25 my $targ = readlink $link;
26 next unless defined $targ;
28 m#/usr/lib/(?:[^/]+/)?tripe/services/([^/]+)#;
29 next unless exists $svc{$1};
33 ## If there's nothing to do then don't bother with the rest.
35 for svc
in $need_restart; do any
=t
; break; done
36 case $any in nil
) echo " none configured."; return 0 ;; esac
38 ## Restart the services. This is more than a little tricky.
39 for svc
in $need_restart; do
41 ## Find out about the service.
42 set -- $
("$svc" --version
)
43 name
="$1" version
="$2"
45 ## Write some progress.
48 ## If there's an instance of the service running already then we ask it
49 ## to quit. This is where everything gets complicated.
50 if silently tripectl svcensure
"$name"; then
52 ## So, what we want to do is ask the service to quit, and make sure it
53 ## actually has done before starting the new version. Conveniently,
54 ## the server emits a notification when a service quits. Now all we
55 ## have to do is wait a reasonable time for the notification.
57 ## So we read the output of tripectl(1). Of course, to do this, we
58 ## must keep its standard input open, so we'll sleep for a bit. We can
59 ## use this to implement our timeout. The only problem is curtailing
60 ## the wait early if (as we expect) the service actually quits on time.
61 ## The answer is /very/ cheesy: we'll report the process-id of our
62 ## sleep(1) process through the server's notification mechanism. Then,
63 ## when we see the `SVCRELEASE', we kill the sleep(1) and return
66 echo svcsubmit
"$name" quit
68 echo notify tripe-peer-services.postinst.$$ SLEEPKID
=$sleepkid
74 "NOTE USER tripe-peer-services.postinst.$$ SLEEPKID="*)
77 "NOTE SVCRELEASE $name")
89 ## Restart the service. Pass `--startup' because (a) the server might
90 ## have started recently, and failed to start our services, and (b) our
91 ## services are (modulo some annoying warning messages) idempotent
93 if ! "$svc" --daemon
--startup
; then echo -n
" (FAILED)"; fi
101 ## If the service is currently running, then ask it to stop.
102 if tripectl
>/dev
/null
2>&1 svcensure
$name && \
103 ! tripectl
>/dev
/null
2>&1 svcensure
$name $version~
105 tripectl svcsubmit
$name quit
108 ## Remove the symbolic link if it's there.
109 if [ -L
/etc
/tripe
/services
/$name ]; then
110 case $
(readlink
/etc
/tripe
/services
/$name) in
111 /usr
/lib
/tripe
/services
/$name)
112 rm /etc
/tripe
/services
/$name
122 ## Apply upgrades iteratively until we catch up with reality.
125 ## Here, we killed the `watch' service.
126 if dpkg
--compare-versions
"$v" lt-nl
1.0.0pre14~
; then
127 retire_service watch
1.0.0pre14
130 ## No more updates to apply.
138 restart_services conntrack connect