From 3e532f46aad63b1b82623364419825b0bb8c424d Mon Sep 17 00:00:00 2001 From: eleksir Date: Mon, 29 Apr 2024 14:11:55 +0300 Subject: [PATCH] Add System V Init script and systemd unit, update README.md --- README.md | 12 ++++++++ contrib/reniced.init | 64 +++++++++++++++++++++++++++++++++++++++++ contrib/reniced.service | 10 +++++++ 3 files changed, 86 insertions(+) create mode 100644 contrib/reniced.init create mode 100644 contrib/reniced.service diff --git a/README.md b/README.md index a8c571b..33eb51b 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,18 @@ Note2: MacOS has too tight (or intrusive) security measures, so running somethin task. Reniced can be run via sudo as daemon or backbround process (say, in tmux). On linux systems usually there is no such obstacle and if reniced run from user with id=0, its config should be placed at **/etc/reniced.yaml** +## Install as systemd service + +Supplied systemd unit is ready to install in system as-is and should work ok. It expect to see reniced at +**/usr/sbin/reniced** and assume that reniced runs as foreground task - in config file "daemon" setting either absent or +set to false. + +## Install as System V Init service + +Unlike supplpied systemd unit, supplied System V Init script assumes reniced runs as daemon (in config file "daemon" +setting must be set to true). Script also expects to find pid-file at **/var/run/reniced.pid** and executable itself at +**/usr/sbin/reniced**. + ## Special "thanks" To security assholes that disrupt workflows and make this world worse. diff --git a/contrib/reniced.init b/contrib/reniced.init new file mode 100644 index 0000000..18e5ce5 --- /dev/null +++ b/contrib/reniced.init @@ -0,0 +1,64 @@ +#!/bin/bash +# Start/stop/restart reniced. + +### BEGIN INIT INFO +# Provides: reniced +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start the reniced service. +# Description: Service that periodically checks and changes runtime niceness of given (by name) processes. +### END INIT INFO + + +# Start reniced: +_start() { + echo -n "Starting Reniced daemon: /usr/sbin/reniced" + /usr/sbin/reniced + echo +} + +# Stop reniced: +_stop() { + echo -n "Stopping Reniced daemon..." + if [ -r /var/run/reniced.pid ]; then + kill -HUP "$(cat /var/run/reniced.pid)" + rm -f "/var/run/reniced.pid" + else + killall -HUP -q reniced + fi + echo +} + +# Restart renicedd: +_restart() { + _stop + sleep 1 + _start +} + +# Check if reniced is running +_status() { + if [ -e /var/run/reniced.pid ]; then + echo "reniced is running as pid $(cat /run/reniced.pid)." + else + echo "reniced is stopped." + exit 1 + fi +} + +case "$1" in +'start') + _start + ;; +'stop') + _stop + ;; +'restart') + _restart + ;; +'status') + _status + ;; +*) + echo "usage $0 start|stop|restart|status" +esac diff --git a/contrib/reniced.service b/contrib/reniced.service new file mode 100644 index 0000000..88df780 --- /dev/null +++ b/contrib/reniced.service @@ -0,0 +1,10 @@ +[Unit] +Description=Reniced Service + +[Service] +ExecStart=/usr/sbin/reniced +Restart=always +RestartSec=5 + +[Install] +WantedBy=multi-user.target