Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
StandardOutput does not truncate existing file
Post Body

I'm trying to run iperf as a service and log its output to a normal file in /var/log. Here is my unit file:

[Unit]
Description=iPerf TCP Server
After=network-online.target

[Service]
User=iperf
Restart=always
ExecStart=/usr/bin/iperf --server --window 132k --interval 2 --port 5001
StandardOutput=file:/var/log/iperf-tcp.log
StandardError=inherit

[Install]
WantedBy=multi-user.target

The problem I'm having is that if the service is started (or restarted) while the log file has non-zero size, the log file never gets overwritten. But if I truncate the file to zero bytes and restart the service, it starts writing again until the next time the service is restarted.

I noticed the man page for systemd says the following:

https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=

If path refers to a regular file on the filesystem, it is opened (created if it doesn't exist yet) for writing at the beginning of the file, but without truncating it.

So one, what is the point of writing at the beginning of a file if it's not been truncated? And two, more importantly, what can I do to get systemd to truncate the log file?

I am running Ubuntu 18.04, which is running systemd 237, and so it does not have the append option.

Author
Account Strength
100%
Account Age
8 years
Verified Email
Yes
Verified Flair
No
Total Karma
40,488
Link Karma
2,029
Comment Karma
36,519
Profile updated: 4 hours ago
Posts updated: 8 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago