Bug 750923 - systemd - should be able to set ulimits for daemons
Summary: systemd - should be able to set ulimits for daemons
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: systemd
Version: 16
Hardware: All
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: systemd-maint
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-11-02 20:20 UTC by Claudiu
Modified: 2011-11-06 11:37 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-11-06 11:37:20 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Claudiu 2011-11-02 20:20:22 UTC
Description of problem:

Systemd won't start mysql correctly. I only checked max open files, but I suppose there are problems with all custom values from my.cnf that require root privileges.
Due to this permission issue, open_files_limit is not processed and value for max open files remains default 1024-4096 (soft-hard), even after changing the limit with ulimit -n or editing /etc/security/limits.conf.

Also, if you delete the log file, on mysqld restart by systemctl it won't be automatically created and server won't start.

Disabling mysqld.service in systemd and using the old init system will solve these problems.



Version-Release number of selected component (if applicable):


How reproducible:
try to increase open files using configuration file, the values will not be processed.
Also, just delete your mysqld.log file and it won't be automatically created.

Steps to Reproduce:
1.
2.
3.
  
Actual results:


Expected results:
Fix systemd to give enough permissions for services.


Additional info:

Comment 1 Michal Schmidt 2011-11-03 09:26:05 UTC
mysqld.service specifies:
  User=mysql
  Group=mysql
so the intention of the maintainer was clearly for mysql to be started unprivileged.

Resource limits for a service can be set by systemd if needed. See "LimitNOFILE=" in "man systemd.exec".

The mysql-server package ships an empty log file with the right permissions. If it's deleted, "rpm -V mysql-server" will notice the problem:
  missing   c /var/log/mysqld.log
It would be possible to add a service unit to start before mysqld.service and ensure that the log file exists and has the right permissions, but maybe just saying "Don't delete the log file, but feel free to truncate it" is the right solution.

Reassigning to mysql for consideration.

Comment 2 Tom Lane 2011-11-03 14:06:13 UTC
(In reply to comment #1)
> It would be possible to add a service unit to start before mysqld.service and
> ensure that the log file exists and has the right permissions, but maybe just
> saying "Don't delete the log file, but feel free to truncate it" is the right
> solution.

Indeed.  The file is created by the RPM, and I don't see why someone would expect that randomly deleting it has no consequences for the service.

Now, having said that, the systemd-based service is more fragile than the initscript-based one, because the initscript would recreate the file at need; this was trivial to do in the initscript since it launched as root.  AFAIK it's not possible to do that in the systemd unit file because it will run all commands as the specified user (correct?).  We could, as Michal says,  invent a separate root-privileged unit file with no purpose other than to recreate the log file ... but that seems like overkill, and besides it's got failure modes of its own, like the user not choosing to enable the other service.

So I'm not inclined to do anything about this.  "Don't do that" seems sufficient.

Comment 3 Kay Sievers 2011-11-03 16:46:36 UTC
I guess that can be done with:
  PermissionsStartOnly=

Comment 4 Tom Lane 2011-11-03 18:07:11 UTC
(In reply to comment #3)
> I guess that can be done with:
>   PermissionsStartOnly=

hmm ... if we could apply that to *some* ExecStartPre commands, and not others, it might help.  As is, though, it's not nearly flexible enough.

Comment 5 Michal Schmidt 2011-11-04 10:36:40 UTC
(In reply to comment #2)
> it's got failure modes of its own, like the user not choosing to enable
> the other service.

This is not a problem as the main service can pull the other service using "Wants=".
Still I don't think it should be done.

Comment 6 Claudiu 2011-11-05 18:04:17 UTC
You closed the report without giving a solution for the main problem. Can you please make a fix for systemd running mysqld or similar services to load variables correctly? At this time, because it's starting unprivileged, mysqld will not process my.cnf variables that require root privileges. They are simply not loaded.

Comment 7 Tom Lane 2011-11-05 19:42:12 UTC
On the whole, I think it's a security improvement that we are no longer starting mysqld as root.  So I'm disinclined to undo that.  Exactly which configuration variables are you talking about, and what is the use-case for setting them?

Comment 8 Claudiu 2011-11-05 19:56:03 UTC
For example, open_files_limit in my.cnf can not be processed by mysql and daemon complains in log file as soft/hard limits for mysql will not go over 1024/4096. Even using ulimit or /etc/security/limits.conf to increase the limits will not help. This is a big problem in my opinion. That variable is just an example, actually anything requiring root privileges will not be processed. Just check please.

Comment 9 Tom Lane 2011-11-05 22:50:36 UTC
Well, it does seem like a reasonable feature request that a unit file be able to set the ulimit limits for the daemon it's about to launch.  If that's not supported at the unit-file level, the only way to be able to do it is to launch the daemon as root, which surely isn't a desirable solution.

Bouncing this back to the systemd queue ...

Comment 10 Michal Schmidt 2011-11-06 11:37:20 UTC
(In reply to comment #9)
> Well, it does seem like a reasonable feature request that a unit file be able
> to set the ulimit limits for the daemon it's about to launch.

Perfectly reasonable indeed. And as I mentioned in comment #1, it is already possible:
  Resource limits for a service can be set by systemd if needed.
  See "LimitNOFILE=" in "man systemd.exec".
To set it on your system, you can add a /etc/systemd/system/mysqld.service unit where you include the original unit:
 .include /lib/systemd/system/mysqld.service
and then add the options you need. (The ".include" mechanism is documented "man systemd.unit").


Note You need to log in before you can comment on or make changes to this bug.