Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new system loader setting for file descriptor limit #954

Merged
merged 4 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ExecStartPre=/bin/mkdir -p /run/${{app_name}}
ExecStartPre=/bin/chown ${{daemon_user}}:${{daemon_group}} /run/${{app_name}}
ExecStartPre=/bin/chmod 755 /run/${{app_name}}
PermissionsStartOnly=true
LimitNOFILE=${{file_descriptor_limit}}

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ fi

start() {
[ -x $exec ] || exit 5
# Set the file descriptor limit
ulimit -n ${{file_descriptor_limit}} ${{file_descriptor_limit}}
if [ $? -ne 0 ]; then
echo -n $"Failed to set file descriptor limit: ${{file_descriptor_limit}}"
fi
echo -n $"Starting $prog: "
daemon --check $prog --user $DAEMON_USER --pidfile $PIDFILE "$RUN_CMD"
retval=$?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ ${{stop_facilities}}
respawn
respawn limit ${{retries}} ${{retryTimeout}}

# Set maximum number of open file descriptors
limit nofile ${{file_descriptor_limit}} ${{file_descriptor_limit}}

pre-start script
[ -d /var/run/${{app_name}} ] || install -m 755 -o ${{daemon_user}} -g ${{daemon_group}} -d /var/run/${{app_name}}
end script
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ trait LinuxKeys {
SettingKey[Option[String]]("daemon-group-gid", "GID of daemonGroup")
val daemonShell =
SettingKey[String]("daemon-shell", "Shell provided for the daemon user")
val fileDescriptorLimit = SettingKey[Option[String]](
"file-descriptor-limit",
"Maximum number of open file descriptors for the spawned application"
)

val linuxPackageMappings = TaskKey[Seq[LinuxPackageMapping]](
"linux-package-mappings",
Expand Down
10 changes: 7 additions & 3 deletions src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ object LinuxPlugin extends AutoPlugin {
stopRunlevels := None,
requiredStartFacilities := None,
requiredStopFacilities := None,
fileDescriptorLimit := Some("1024"),
termTimeout := 10,
killTimeout := 10,
// Default linux bashscript replacements
Expand All @@ -88,7 +89,8 @@ object LinuxPlugin extends AutoPlugin {
daemonUserUid = (daemonUserUid in Linux).value,
daemonGroup = (daemonGroup in Linux).value,
daemonGroupGid = (daemonGroupGid in Linux).value,
daemonShell = (daemonShell in Linux).value
daemonShell = (daemonShell in Linux).value,
fileDescriptorLimit = (fileDescriptorLimit in Linux).value
),
linuxScriptReplacements += controlScriptFunctionsReplacement(
/* Add key for control-functions */ ),
Expand Down Expand Up @@ -155,7 +157,8 @@ object LinuxPlugin extends AutoPlugin {
daemonUserUid: Option[String],
daemonGroup: String,
daemonGroupGid: Option[String],
daemonShell: String): Seq[(String, String)] =
daemonShell: String,
fileDescriptorLimit: Option[String]): Seq[(String, String)] =
Seq(
"author" -> author,
"descr" -> description,
Expand All @@ -168,7 +171,8 @@ object LinuxPlugin extends AutoPlugin {
"daemon_user_uid" -> daemonUserUid.getOrElse(""),
"daemon_group" -> daemonGroup,
"daemon_group_gid" -> daemonGroupGid.getOrElse(""),
"daemon_shell" -> daemonShell
"daemon_shell" -> daemonShell,
"file_descriptor_limit" -> fileDescriptorLimit.getOrElse("")
)

/**
Expand Down
3 changes: 3 additions & 0 deletions src/sphinx/archetypes/systemloaders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ General Settings
``retryTimeout``
Timeout between retries in seconds

``fileDescriptorLimit``
Maximum number of open file descriptors for the spawned application. The default value is 1024.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️



SystemV
-------
Expand Down