How to break complicated ExecStart line while still having comments in the middle?

Solution 1:

I think this is what @sven suggests:

#
# Listen locally on port 10001 and tunnel it to someserver
# Listen on someserver port 3128 and tunnel it to localhost
#
ExecStart=/bin/ssh -NT \
    -o ExitOnForwardFailure=yes \
    -o ServerAliveInterval=60 \
    -o ServerAliveCountMax=3 \
    -L 172.16.12.34:10001:localhost:10001 \
    -R3128:127.0.0.1:3128 \
    someserver

Doesn't look too bad to me.

Solution 2:

  1. Write a script instead.
  2. No one is preventing you to write the line and then leave additional comments explaining it.

Solution 3:

Just dont forget \ at the end of lines with comments. Systemd will cut them and not use in command

ExecStart=/bin/ssh -NT \
    -o ExitOnForwardFailure=yes \
    -o ServerAliveInterval=60 \
    -o ServerAliveCountMax=3 \
    # local tunnel for this \
    -L 172.16.12.34:10001:localhost:10001 \
    # remote tunnel for that \
    -R3128:127.0.0.1:3128 \
    someserver