Merge Official Source

This commit is contained in:
Xiaokailnol
2026-01-18 16:35:08 +08:00
commit 4f3df77363
12 changed files with 230 additions and 0 deletions

37
cpulimit/Makefile Executable file
View File

@@ -0,0 +1,37 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=cpulimit
PKG_VERSION:=0.3.2
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/denji/cpulimit/tar.gz/$(PKG_VERSION)?
PKG_HASH:=0c61d394407fdd0547b53e6435ecb817d2e3ba914b48aa9f48ccf42c8278d3a6
PKG_BUILD_PARALLEL:=1
PKG_LICENSE_FILES:=LICENSE
MAKE_PATH:=src
include $(INCLUDE_DIR)/package.mk
define Package/cpulimit
SECTION:=utils
CATEGORY:=Utilities
TITLE:=CPU usage limiter
URL:=https://github.com/denji/cpulimit
endef
define Package/cpulimit/description
Cpulimit is a tool which limits the CPU usage of a process
(expressed in percentage, not in CPU time).
endef
TARGET_CFLAGS += -D_GNU_SOURCE
define Package/cpulimit/install
$(INSTALL_DIR) $(1)/usr/bin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/cpulimit $(1)/usr/bin/
endef
$(eval $(call BuildPackage,cpulimit))

View File

@@ -0,0 +1,21 @@
--- a/src/process_group.c
+++ b/src/process_group.c
@@ -24,17 +24,10 @@
#include <limits.h>
#include <sys/time.h>
#include <signal.h>
-
-#if defined(__APPLE__) || defined(__FREEBSD__)
- #include <libgen.h>
-#endif
+#include <libgen.h>
#include <assert.h>
-#ifdef __sun__
- #include <libgen.h>
-#endif
-
#include "process_iterator.h"
#include "process_group.h"
#include "list.h"

19
luci-app-cpulimit/Makefile Executable file
View File

@@ -0,0 +1,19 @@
#
# Copyright (C) 2008-2014 The LuCI Team <luci@lists.subsignal.org>
#
# This is free software, licensed under the Apache License, Version 2.0 .
#
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-cpulimit
PKG_VERSION:=1.0
PKG_RELEASE:=1
LUCI_TITLE:=cpulimit configuration module
LUCI_PKGARCH:=all
LUCI_DEPENDS:=+cpulimit
include $(TOPDIR)/feeds/luci/luci.mk
# call BuildPackage - OpenWrt buildroot signature

View File

@@ -0,0 +1,12 @@
module("luci.controller.cpulimit", package.seeall)
function index()
if not nixio.fs.access("/etc/config/cpulimit") then
return
end
local page = entry({"admin", "system", "cpulimit"}, cbi("cpulimit"), _("cpulimit"), 65)
page.dependent = true
page.acl_depends = { "luci-app-cpulimit" }
end

View File

@@ -0,0 +1,40 @@
m = Map("cpulimit")
m.title = translate("cpulimit")
m.description = translate("cpulimit")
s = m:section(TypedSection, "list", translate("Settings"))
s.template = "cbi/tblsection"
s.anonymous = true
s.addremove = true
enable = s:option(Flag, "enabled", translate("enable"))
enable.optional = false
enable.rmempty = false
exename = s:option(Value, "exename", translate("exename"))
exename.description = translate("name of the executable program file or path name")
exename.optional = false
exename.rmempty = false
exename.default = "/usr/bin/transmission-daemon"
exename:value("transmission","/usr/bin/transmission-daemon")
exename:value("samba","/usr/sbin/smbd")
exename:value("mount.ntfs-3g","mount.ntfs-3g")
exename:value("vsftpd","/usr/sbin/vsftpd")
exename:value("pure-ftpd","/usr/sbin/pure-ftpd")
limit = s:option(Value, "limit", translate("limit"))
limit.optional = false
limit.rmempty = false
limit.default = "50"
limit:value("100","100%")
limit:value("90","90%")
limit:value("80","80%")
limit:value("70","70%")
limit:value("60","60%")
limit:value("50","50%")
limit:value("40","40%")
limit:value("30","30%")
limit:value("20","20%")
limit:value("10","10%")
return m

View File

@@ -0,0 +1,17 @@
msgid "cpulimit"
msgstr "CPU占用率限制"
msgid "Use cpulimit to restrict app's cpu usage."
msgstr "利用cpulimit限制应用程序的CPU使用率"
msgid "Usage restrictions"
msgstr "使用率限制"
msgid "exename"
msgstr "进程名称"
msgid "name of the executable program file or path name"
msgstr "可执行文件名称,或包含路径的应用程序"
msgid "limit"
msgstr "占用率限制(自定义时使用不含'%'的整数)"

View File

@@ -0,0 +1 @@
zh-cn

View File

@@ -0,0 +1,6 @@
config 'list'
option 'exename' '/usr/bin/transmission-daemon'
option 'limit' '50'
option 'enabled' '0'

View File

@@ -0,0 +1,17 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
. /lib/functions.sh
START=50
DEFAULT=/etc/default/cpulimit
start() {
/usr/bin/cpulimit.sh start &
}
stop() {
killall -9 cpulimit
}

View File

@@ -0,0 +1,13 @@
#!/bin/sh
uci -q batch <<-EOF >/dev/null
delete ucitrack.@cpulimit[-1]
add ucitrack cpulimit
set ucitrack.@cpulimit[-1].init=cpulimit
commit ucitrack
EOF
/etc/init.d/cpulimit enable
rm -f /tmp/luci-indexcache
exit 0

View File

@@ -0,0 +1,36 @@
#!/bin/sh
. /lib/functions.sh
cpulimit_get(){
echo cpulimit_get
config_get enabled $1 enabled
[ $enabled -gt 0 ] || return 1
config_get limit $1 limit
config_get exename $1 exename
eval exepid=$(pgrep $exename)
cpulimit -l $limit -p $exepid &
echo cpulimit -l $limit -p $exepid
}
stop() {
killall -9 cpulimit
# ps -a|grep cpulimit|while read line
# do
# killall cpulimit>/dev/null 2>&1
# done
}
case "$1" in
"start")
echo start
killall -9 cpulimit
config_load cpulimit
config_foreach cpulimit_get list
echo end
exit 0
;;
"stop")echo stop; killall -9 cpulimit;;
esac

View File

@@ -0,0 +1,11 @@
{
"luci-app-cpulimit": {
"description": "Grant UCI access for luci-app-cpulimit",
"read": {
"uci": [ "cpulimit" ]
},
"write": {
"uci": [ "cpulimit" ]
}
}
}