<div dir="ltr"><div><div><div><div><div><div><div><div>Understood.<br><br></div>I didn't think that systemd paid one bit of attention to the settings controlled by pam_limits?<br><br></div>I'm only interested in a user instance that is lingering and operates outside of a session.<br></div><br></div>My goal is that the child processes of the user instance will have limits that I set. If I understand correctly, if those limits are to be higher than the system's hard limits, then the user instance itself must have those higher limits set on it, yes?<br><br></div>I appreciate that the user instance doesn't need higher limits itself and that it is weird that the children of the user instance will have difference limits than a logged in user, but that's fine.<br><br></div>It seems to me that the only use of the defaults set in /etc/systemd/user.conf is to further restrict the user instance's children beyond  whatever restrictions are set by the system itself. I had mistakenly believed that since /etc/systemd/user.conf was a restricted file, that setting it would override system settings but it doesn't because it's read by the user instance after it's already running at the user.<br><br></div>Thanks for the tip regarding /etc/systemd/system/user@.service.d/whatever.conf.<br><br></div>I did previously know that user@.service would work. For my application, I'm interested in a single special user only however. I don't want these customizations to apply to all users. <br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Nov 19, 2017 at 12:22 PM, Mantas Mikulėnas <span dir="ltr"><<a href="mailto:grawity@gmail.com" target="_blank">grawity@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div class="gmail_quote"><div dir="ltr">On Sun, Nov 19, 2017, 22:01 Jeff Solomon <<a href="mailto:jsolomon8080@gmail.com" target="_blank">jsolomon8080@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div>Hi,<br></div><div><br></div><div>Two questions.</div><div><br></div>I want to raise the "number of files" limits for the user instance.<br><br></div>First, I set DefaultLimitNOFILE to something higher than the global system default in /etc/systemd/user.conf and I rebooted.<br><br></div>Then I confirmed that the setting has taken effect:</div><div><br></div><div>"systemctl --user show" showed the new DefaultLimitNOFILE and the unit itself showed the higher setting of LimitNOFILE when I ran "systemctl --user show foo".<br><br></div>So far everything worked as expected.<br><br></div>However, when I checked "cat /proc/<pid>/limits" on the ExecStart process of foo.service, I don't see the "number of files" limit has changed.<br><br></div>What did I do wrong?<br><br></div>Second question: if I want to raise the limit just for a single user, how would I go about it?<br><br>Making a change in user.conf would make it apply in all user instances (assuming I could get it to work).<br><br></div>I have found that if I create /etc/systemd/system/user@<uid><wbr>.service and add LimitNOFILE to the [Service] section of that file, then it will do two things. First, it actually works whereas editing user.conf did not. Second, the change only applies to user <uid> and not all users.<br><br></div>I assume I'm not getting how systemd is supposed to work. So please enlighten me.<br><br></div>Thanks,<br><br></div>Jeff<br></div></div></blockquote></div><div><br></div><div><span style="font-size:13px"><br></span></div></span><div><span style="font-size:13px">First reason:</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">Limit* in user@.service is set by init before it starts the user instance. Init is privileged and can raise limits above the current hard limit. (The same could be done via pam_limit.)</span></div><div><br></div><div>DefaultLimit* in user.conf is set by the user instance itself, which runs under your uid and does not have any special privileges. It cannot raise the limits beyond the current hard limit, just as the `ulimit` command cannot.</div><div><br></div><div>Second reason:</div><div><br></div><div>The defaults are for units – not for the service manager itself.</div><div><br></div><div>So although<span style="font-size:13px"> the defaults are *read* successfully, they will only be applied when you start a service.</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">If you want to raise limits for all users, best to do that via pam_limits. (Letting --user services have different limits than directly launched programs is likely to result in confusion.)</span></div><div><span style="font-size:13px"><br></span></div><div><span style="font-size:13px">If you want to override user@.service, you *do not have* to create an instance for every uid; you can just have "/etc/systemd/system/user@.<wbr>service"; that's how it looks in /usr/lib anyway.</span></div><div><span style="font-size:13px"><br></span></div><div>Though a better method is to use drop-in configuration to only extend the service with your new options, while still loading the rest from /usr. Search the systemd.unit manpage for "drop-in", and put your extensions in "/etc/systemd/system/user@.<wbr>service.d/whatever.conf".</div><span class="HOEnZb"><font color="#888888"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div></div>
</blockquote></div><div dir="ltr">-- <br></div><div class="m_5132032680034782269gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><p dir="ltr">Mantas Mikulėnas <<a href="mailto:grawity@gmail.com" target="_blank">grawity@gmail.com</a>><br>
Sent from my phone</p>
</div></div>
</font></span></blockquote></div><br></div>