Skip to content

Commit 8daaf8d

Browse files
committed
Add systemd service file
1 parent 04efb3f commit 8daaf8d

File tree

9 files changed

+71
-5
lines changed

9 files changed

+71
-5
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM alpine:3.14 AS builder
2-
RUN apk add --no-cache musl-dev gcc cmake make
2+
RUN apk add --no-cache musl-dev gcc cmake make libcap
33

44
COPY . /usr/local/src/mdns-reflector
55
WORKDIR /usr/local/src/mdns-reflector
@@ -9,6 +9,8 @@ RUN mkdir -p build \
99
&& make VERBOSE=1 \
1010
&& make install DESTDIR=install
1111

12+
RUN setcap cap_net_raw+ep build/install/usr/local/bin/mdns-reflector
13+
1214
FROM alpine:3.14
1315
COPY --from=builder /usr/local/src/mdns-reflector/build/install/ /
1416
CMD ["/usr/local/bin/mdns-reflector", "-h"]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ make install
5252
`mdns-reflector` is easy to use. Just run the following command on a multi-homed host:
5353

5454
```sh
55-
mdns-reflector -f eth0 eth1
55+
mdns-reflector -fn eth0 eth1
5656
```
5757

5858
where `eth0` and `eth1` are the interfaces that you want to reflect mDNS for.
@@ -62,13 +62,13 @@ Run `mdns-reflector -h` for help.
6262
Similarly, run with Docker in the foreground:
6363

6464
```sh
65-
docker run --net=host yuxzhu/mdns-reflector:latest -f eth0 eth1
65+
docker run --net=host yuxzhu/mdns-reflector:latest -fn eth0 eth1
6666
```
6767

6868
Or run with Docker as a daemon:
6969

7070
```sh
71-
docker run -d --restart=always --net=host yuxzhu/mdns-reflector:latest -f eth0 eth1
71+
docker run -d --restart=always --net=host yuxzhu/mdns-reflector:latest -fn eth0 eth1
7272
```
7373

7474
## License

debian/copyright

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Files: *
2+
Copyright: 2021 Yuxiang Zhu <me@yux.im>
3+
License: GPL-3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
.
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
.
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
.
17+
On Debian systems, the full text of the GNU General Public
18+
License version 3 can be found in the file
19+
'/usr/share/common-licenses/GPL-3'.

debian/docs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.md

debian/install

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
misc/mdns-reflector etc/default
2+
misc/mdns-reflector.service lib/systemd/system

debian/postinst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
set -e
3+
setcap cap_net_raw+ep /usr/bin/mdns-reflector

mdns-reflector.spec

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ License: GPLv3+
77
URL: https://github.com/vfreex/mdns-reflector
88
Source0: %{name}-%{version}.tar.gz
99

10+
BuildRequires: systemd
1011
BuildRequires: gcc
1112
BuildRequires: make
1213
%if 0%{?rhel} == 7
@@ -19,6 +20,11 @@ BuildRequires: cmake
1920
%endif
2021

2122

23+
Requires(post): systemd
24+
Requires(preun): systemd
25+
Requires(postun): systemd
26+
27+
2228
%description
2329
mDNS Reflector (mdns-reflector) is a lightweight and performant multicast DNS (mDNS) reflector with a modern design.
2430
It reflects mDNS queries and responses among multiple LANs, which allows you to run untrusted IoT devices
@@ -38,14 +44,28 @@ mDNS Reflector supports zone based reflection and IPv6.
3844

3945
%install
4046
%cmake_install
47+
install -d $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
48+
install misc/mdns-reflector $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/mdns-reflector
49+
install -d $RPM_BUILD_ROOT%{_unitdir}
50+
install -t $RPM_BUILD_ROOT%{_unitdir} misc/mdns-reflector.service
4151

4252

4353
%files
44-
%{_bindir}/mdns-reflector
54+
%caps(cap_net_raw+ep) %{_bindir}/mdns-reflector
55+
%config(noreplace) %{_sysconfdir}/sysconfig/mdns-reflector
56+
%{_unitdir}/mdns-reflector.service
4557
%{!?_licensedir:%global license %%doc}
4658
%license COPYING
4759
%doc README.md
4860

61+
%post
62+
%systemd_post mdns-reflector.service
63+
64+
%preun
65+
%systemd_preun mdns-reflector.service
66+
67+
%postun
68+
%systemd_postun_with_restart mdns-reflector.service
4969

5070
%changelog
5171
* Wed Aug 18 2021 Yuxiang Zhu <me@yux.im>

misc/mdns-reflector

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
INTERFACES=
2+
LOGGING_LEVEL=info
3+
EXTRA_OPTIONS=
4+
DAEMON_ARGS=

misc/mdns-reflector.service

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=Multicast DNS (mDNS) reflector
3+
Wants=network-online.target
4+
After=network-online.target
5+
6+
[Service]
7+
Type=simple
8+
EnvironmentFile=-/etc/sysconfig/mdns-reflector
9+
EnvironmentFile=-/etc/default/mdns-reflector
10+
ExecStart=/usr/bin/mdns-reflector -fnl $LOGGING_LEVEL $DAEMON_ARGS $INTERFACES
11+
User=nobody
12+
Restart=on-failure
13+
14+
[Install]
15+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)