• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2# Copyright 2022 gRPC authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Run this script as root
17
18clean() {
19    echo "Cleaning..."
20    systemctl stop sdsockact.socket
21    systemctl stop sdsockact.service
22    systemctl daemon-reload
23    rm /tmp/greeter_server
24    rm /tmp/greeter_client
25    rm /etc/systemd/system/sdsockact.service
26    rm /etc/systemd/system/sdsockact.socket
27}
28
29fail() {
30    clean
31    echo "FAIL: $@" >&2
32    exit 1
33}
34
35pass() {
36    echo "SUCCESS: $1"
37}
38
39bazel build --define=use_systemd=true //examples/cpp/systemd_socket_activation:all || fail "Failed to build sd_sock_act"
40cp ../../../bazel-bin/examples/cpp/systemd_socket_activation/server /tmp/greeter_server
41cp ../../../bazel-bin/examples/cpp/systemd_socket_activation/client /tmp/greeter_client
42
43cat << EOF > /etc/systemd/system/sdsockact.service
44[Service]
45ExecStart=/tmp/greeter_server
46EOF
47
48cat << EOF > /etc/systemd/system/sdsockact.socket
49[Socket]
50ListenStream=/tmp/server
51ReusePort=true
52
53[Install]
54WantedBy=sockets.target
55EOF
56
57systemctl daemon-reload
58systemctl enable sdsockact.socket
59systemctl start sdsockact.socket
60
61pushd /tmp
62./greeter_client | grep "Hello"
63if [ $? -ne 0 ]; then
64    popd
65    fail "Response not received"
66fi
67
68popd
69pass "Response received"
70clean
71