• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1adb can be configured to work with systemd-style socket activation,
2allowing the daemon to start automatically when the adb control port
3is forwarded across a network. You need two files, placed in the usual
4systemd service directories (e.g., ~/.config/systemd/user for a user
5service).
6
7adb.service:
8
9--- START adb.service CUT HERE ---
10[Unit]
11Description=adb
12After=adb.socket
13Requires=adb.socket
14[Service]
15Type=simple
16# FD 3 is part of the systemd interface
17ExecStart=/path/to/adb server nodaemon -L acceptfd:3
18--- END adb.service CUT HERE ---
19
20--- START adb.socket CUT HERE ---
21[Unit]
22Description=adb
23PartOf=adb.service
24[Socket]
25ListenStream=127.0.0.1:5037
26Accept=no
27[Install]
28WantedBy=sockets.target
29--- END adb.socket CUT HERE ---
30
31After installing the adb service, the adb server will be started
32automatically on any connection to 127.0.0.1:5037 (the default adb
33control port), even after adb kill-server kills the server.
34
35Other "superserver" launcher systems (like macOS launchd) can be
36configured analogously. The important part is that adb be started with
37"server" and "nodaemon" command line arguments and that the listen
38address (passed to -L) name a file descriptor that's ready to
39accept(2) connections and that's already bound to the desired address
40and listening. inetd-style pre-accepted sockets do _not_ work in this
41configuration: the file descriptor passed to acceptfd must be the
42serve socket, not the accepted connection socket.
43