Compiling cpulimit with spksrc for synology NAS
Read the disclaimer
This article discribes how to compile cpulimit for synology devices, package it and install it.
I've set up a forked repository of spksrc at https://github.com/youpla/spksrc
There I publish some tools.
You can get cpulimit sources at https://github.com/opsengine/cpulimit
The package described in this guide is will download the content from that repository.
cpulimit is a simple program which attempts to limit the cpu usage of a process expressed in percentage, not in cpu time.
The apprehensible quality of this software is allowing you to run demanding software without rendering the NAS unusable.
In order to compile the software there are two possibilities.
- a virtual machine
- a docker container
In this example I'll rely on a virtual machine running Ubuntu. There are many steps involved in getting a virtual machine ready that are beyond this article scope, here are some basic steps:
- chose an hypervisor
- install Ubuntu
- install the prerequisites
- clone a repository
- for that clone run : "make setup"
- get your architecture
- compile the package
Steps detail
Hypervisor
Hypervisor are software enabling to run virtual machines.
https://itsfoss.com/install-linux-in-virtualbox/
Hyper-v (Microsoft)
Windows 10 home edition, you can activate it :
https://www.itechtics.com/enable-hyper-v-windows-10-home/
https://www.itechtics.com/enable-hyper-v-windows-10-home/
Windows 10 pro, it's a feature you can activate through the gui:
Microsoft offers pre-configured Ubuntu virtual machines for hyper-v:
This one is really : click "create virtual machine" and you are ready.
Install the prerequisites
It's documented here : https://github.com/SynoCommunity/spksrc
On the Ubuntu host in a terminal window :
On the Ubuntu host in a terminal window :
- sudo dpkg --add-architecture i386 && sudo apt-get update
- sudo apt install autogen automake bc bison build-essential check cmake curl cython debootstrap expect flex g++-multilib gettext git gperf imagemagick intltool libbz2-dev libc6-i386 libcppunit-dev libffi-dev libgc-dev libgmp3-dev libltdl-dev libmount-dev libncurses-dev libpcre3-dev libssl-dev libtool libunistring-dev lzip mercurial ncurses-dev php pkg-config python3 python3-distutils scons subversion swig unzip xmlto zlib1g-dev
- sudo apt install python-pip
- sudo pip install -U setuptools pip wheel httpie
Clone the repository and make setup
It's documented here : https://github.com/SynoCommunity/spksrc/wiki/Developers-HOW-TO
- on the ubuntu host
- start a terminal
- choose a folder for the git clone root
- git clone https://github.com/youpla/spksrc.git
- cd spksrc/
- make setup
Get your architecture
It's documented here : https://github.com/SynoCommunity/spksrc/wiki/Architecture-per-Synology-model
In this case a "Marvel armada 375"
In order to build a package :
make arch-armada375
or
make arch-8876720
Compile the (cpulimit) package for your architecture
in a terminal navigate to the cpulimit folderexample:
/home/userprofile/test-git/spksrc/spk/cpulimit
make arch-armada375
Install the package
Go to the file explorer and find the generated file.
example
/home/userprofile/test-git/spksrc/packages/cpulimit_armada375-6.1_0.2-0.spk
example
/home/userprofile/test-git/spksrc/packages/cpulimit_armada375-6.1_0.2-0.spk
For test purpose, you can use the synology online demo https://demo.synology.com/
This demo device runs on intel xeon
make arch-x64
It will compile : cpulimit_x64-6.1_0.2-0.spk
It will compile : cpulimit_x64-6.1_0.2-0.spk
Testing
See :
https://dayandnightcoding.blogspot.com/2020/04/testing-package-compiled-with-spksrc.html
The package cpulimit has been tested for install and uninstall on my DS-115 with no noticed problem. The blog disclaimer still applies.
https://dayandnightcoding.blogspot.com/2020/04/testing-package-compiled-with-spksrc.html
The package cpulimit has been tested for install and uninstall on my DS-115 with no noticed problem. The blog disclaimer still applies.
Cpulimit tweaking
In the latest synology OS version, cpulimit cannot operate on certain process.
This workaround may open a security breach, it's unfortunately the only one I got so far, by adding the s bit : this is not a security best practice.
more about s bit : https://linuxconfig.org/how-to-use-special-permissions-the-setuid-setgid-and-sticky-bits
Based on https://github.com/youpla/spksrc/blob/master/spk/cpulimit/src/installer.sh
ln -s ${INSTALL_DIR}/bin/cpulimit /usr/local/bin/cpulimit
cpulimit will be installed in /usr/local/bin/cpulimit
in order to tweak it with s bit :
sudo chmod u+s /usr/local/bin/cpulimit
in order to tweak it with s bit :
sudo chmod u+s /usr/local/bin/cpulimit