From c29c2dbbfbdc70929dacb01e1bf05873c010e983 Mon Sep 17 00:00:00 2001 From: master Date: Thu, 6 Sep 2018 02:57:48 +0300 Subject: [PATCH] Update the work of scripts to interact with the systemd, improve the boot process, fix bugs. --- README.md | 40 ++--- zraid.deb/etc/default/zraid | 5 - zraid.deb/etc/init.d/zraid-manager | 69 -------- .../lib/systemd/system/libvirt-guests.service | 18 --- .../lib/systemd/system/zraid-monitor.service | 16 -- .../lib/systemd/system/zraid-start.service | 14 -- zramraid.deb/etc/default/zramraid | 5 + zramraid.deb/etc/init.d/zramraid-manager | 77 +++++++++ .../etc/zramraid}/messages.dat | 92 +++++------ .../etc/zramraid/zramraid-config | 23 +-- .../etc/zramraid/zramraid-maker | 25 +-- .../etc/zramraid/zramraid.conf | 0 .../lib/systemd/system/zramraid.service | 21 +++ .../zramraid-install | 148 +++++++++--------- 14 files changed, 267 insertions(+), 286 deletions(-) delete mode 100644 zraid.deb/etc/default/zraid delete mode 100755 zraid.deb/etc/init.d/zraid-manager delete mode 100644 zraid.deb/lib/systemd/system/libvirt-guests.service delete mode 100644 zraid.deb/lib/systemd/system/zraid-monitor.service delete mode 100644 zraid.deb/lib/systemd/system/zraid-start.service create mode 100644 zramraid.deb/etc/default/zramraid create mode 100755 zramraid.deb/etc/init.d/zramraid-manager rename {zraid.deb/etc/zraid => zramraid.deb/etc/zramraid}/messages.dat (57%) rename zraid.deb/etc/zraid/zraid-config => zramraid.deb/etc/zramraid/zramraid-config (97%) rename zraid.deb/etc/zraid/zraid-maker => zramraid.deb/etc/zramraid/zramraid-maker (98%) rename zraid.deb/etc/zraid/zraid.conf => zramraid.deb/etc/zramraid/zramraid.conf (100%) create mode 100644 zramraid.deb/lib/systemd/system/zramraid.service rename zraid.deb/zraid-install => zramraid.deb/zramraid-install (56%) diff --git a/README.md b/README.md index 15e817b..d651267 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PROJECT ZRAM-RAID +# PROJECT ZRAMRAID Description
This project is a derivative of all the experiments using virtualization XEN \ KVM, which we started in 2012. Then we did not like the speed of the disk subsystem in HVM mode for WINDOWS 2003-2012 servers.
@@ -9,11 +9,11 @@ The code is distributed under the GNU Public License.

BASH language code consists of 3 scripts:
1. install - installer script installer supports OS Debian
-2. zraid-config - script for configuration zraid media management
-3. zraid-maker - starting and stopping control script zraid media
+2. zramraid-config - script for configuration zraid media management
+3. zramraid-maker - starting and stopping control script zraid media
# How to use: -zraid-install --install
+zramraid-install --install
and..

1. Create an image of the required size, consider the size of allocated RAM to mirror your image!
@@ -21,17 +21,17 @@ example:
cat /proc/meminfo |grep MemAvailable
MemAvailable: 6638832 kB
or:
- zraid-config --list
+ zramraid-config --list
2. Create image:
fallocate -l 3G /home/kvm/disk0.img
-3. Create zram-raid:
- zraid-config --add md0:/home/kvm/disk0.img
+3. Create zramraid:
+ zramraid-config --add md0:/home/kvm/disk0.img
4. Check the configuration:
- zraid-config --list
-5. Start or restart zram-raid:
- /etc/init.d/zraid-manager restart
+ zramraid-config --list
+5. Start or restart zramraid:
+ /etc/init.d/zramraid-manager restart
or:
- systemctl restart zraid-manager
+ systemctl restart zramraid-manager
6. Result:
cat /proc/mdstat
Personalities : [raid1]
@@ -41,25 +41,27 @@ or:
unused devices:
To automatically start the system, you must correct the configuration file:
- editor /etc/defaults/zraid
+ editor /etc/defaults/zramraid
...
mode="auto";

- Now, when you start, ZRAM-RAID will start automatically.
+ Now, when you start, zramraid will start automatically.

Additional control parameters can be found from the parameter --help
example:
- zraid-config --help
- zraid-maker --help
- zraid-install --help
+ zramraid-config --help
+ zramraid-maker --help
+ zramraid-install --help
# Recommendations: - If you plan to use zram-raid together with KVM then we recommend making a change for the systemd:
+ If you plan to use zramraid together with KVM then we recommend making a change for the systemd:
editor /lib/systemd/system/libvirt-guests.service
...
- After=network.target libvirtd.service time-sync.target zraid-start.service
+ Requires=zramraid.service
...
* see example files from /lib/systemd/system
-version - 10.09.18 \ No newline at end of file +version - 27.06.18 +
+License: GPLv3 \ No newline at end of file diff --git a/zraid.deb/etc/default/zraid b/zraid.deb/etc/default/zraid deleted file mode 100644 index bcb98d3..0000000 --- a/zraid.deb/etc/default/zraid +++ /dev/null @@ -1,5 +0,0 @@ -## service start -# mode - startup parameter zraid system in manual or automatic mode, examples: mode="auto" or mode="manual" -# if "manual" zraid does not start automatically at startup, dafult - "manual" -# -mode="manual"; diff --git a/zraid.deb/etc/init.d/zraid-manager b/zraid.deb/etc/init.d/zraid-manager deleted file mode 100755 index 7b62fe4..0000000 --- a/zraid.deb/etc/init.d/zraid-manager +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash -### BEGIN INIT INFO -# Provides: zraid-manager -# Required-Start: udev $local_fs $remote_fs $time -# Required-Stop: $local_fs $remote_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: start the zraid -# Description: starts zraid using start-stop-daemon -### END INIT INFO -## version =05.08 -## переменная управления -parms=$1 -PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"; -source "/etc/default/zraid"; -## -zpath="/etc/zraid"; -if [[ "$parms" = '' ]]; - then - echo "/etc/init.d/zraid-manager {start|stop|restart|status}" - exit 0 -fi - -function zramBoot() { -if [ $(echo $(($(echo $USER|wc -m)-1))) == 0 ] - then - if [ $(echo "$mode"|grep "auto"|wc -m) == 0 ] - then - exit 0; - else - $zpath/zraid-maker --on - fi - exit 0; -fi -$zpath/zraid-maker --on -} - -### begin -case "$parms" in -# Обратите внимание: переменная взята в кавычки. -"start" | "start" ) -zramBoot; -exit 0 -;; - -"stop" | "stop" ) -$zpath/zraid-maker --off -exit 0 -;; - -"restart" | "restart" ) -$zpath/zraid-maker --off -sleep 3 -zramBoot; -exit 0 -;; - -"status" | "status" ) -$zpath/zraid-maker --status -exit 0 -;; - -* ) -# Выбор по-умолчанию. -echo -echo "no input parameters." -exit 1 -;; -esac diff --git a/zraid.deb/lib/systemd/system/libvirt-guests.service b/zraid.deb/lib/systemd/system/libvirt-guests.service deleted file mode 100644 index 9d638f7..0000000 --- a/zraid.deb/lib/systemd/system/libvirt-guests.service +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=Suspend Active Libvirt Guests -After=network.target libvirtd.service time-sync.target zraid-start.service -Documentation=man:libvirtd(8) -Documentation=http://libvirt.org - -[Service] -EnvironmentFile=-/etc/default/libvirt-guests -# Hack just call traditional service until we factor -# out the code -ExecStart=/usr/lib/libvirt/libvirt-guests.sh start -ExecStop=/usr/lib/libvirt/libvirt-guests.sh stop -Type=oneshot -RemainAfterExit=yes -StandardOutput=journal+console - -[Install] -WantedBy=multi-user.target diff --git a/zraid.deb/lib/systemd/system/zraid-monitor.service b/zraid.deb/lib/systemd/system/zraid-monitor.service deleted file mode 100644 index 071d4b0..0000000 --- a/zraid.deb/lib/systemd/system/zraid-monitor.service +++ /dev/null @@ -1,16 +0,0 @@ -# This file is part of mdadm. -# -# mdadm is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. - -[Unit] -Description=zraid array monitor -DefaultDependencies=no - -[Service] -ExecStart=/etc/init.d/zraid-manager status - -[Install] -WantedBy=multi-user.target diff --git a/zraid.deb/lib/systemd/system/zraid-start.service b/zraid.deb/lib/systemd/system/zraid-start.service deleted file mode 100644 index 2bc06da..0000000 --- a/zraid.deb/lib/systemd/system/zraid-start.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Activation of zraid -DefaultDependencies=no -After=local-fs.target systemd-modules-load.service -Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target libvirtd.service shutdown.target -Wants=systemd-udev-settle.service - -[Service] -ExecStart=/etc/init.d/zraid-manager boot -ExecStop=/etc/init.d/zraid-manager stop -Type=oneshot - -[Install] -WantedBy=local-fs.target diff --git a/zramraid.deb/etc/default/zramraid b/zramraid.deb/etc/default/zramraid new file mode 100644 index 0000000..fa3645a --- /dev/null +++ b/zramraid.deb/etc/default/zramraid @@ -0,0 +1,5 @@ +## service start +# mode - startup parameter zramraid system in manual or automatic mode, examples: mode="auto" or mode="manual" +# if "manual" zramraid does not start automatically at startup, dafult - "manual" +# +mode="manual"; diff --git a/zramraid.deb/etc/init.d/zramraid-manager b/zramraid.deb/etc/init.d/zramraid-manager new file mode 100755 index 0000000..9fa227b --- /dev/null +++ b/zramraid.deb/etc/init.d/zramraid-manager @@ -0,0 +1,77 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: zramraid-manager +# Required-Start: udev $local_fs $remote_fs $time +# Required-Stop: $local_fs $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: start the zraid +# Description: starts zraid using start-stop-daemon +### END INIT INFO +## version =25.06.18 +PARMS=$1 +PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/zramraid"; +DESC="Zram Raid" +NAME="zramraid" +SCRIPTNAME="zramraid-maker"; +ZPATH="/etc/zramraid" +MODE="/etc/default/zramraid"; +## + +if [[ "$PARMS" = '' ]]; + then + echo "/etc/init.d/zramraid-manager {start|stop|restart|status}" + exit 0 +fi + +function zRun() { +if [ ! $(echo $USER|grep root|wc -m) = 0 ] + then + if [ $(cat $MODE |grep mode|grep -v '#'|sed 's/\mode=//g'|sed 's/\"//g;s/\;//g'|grep auto|wc -m) == 0 ] + then + echo "$(date) $NAME: no autostart from boot! mode=manual - /etc/defaults/zramraid">>/var/log/zramraid.log + exit 0; + else + $ZPATH/$SCRIPTNAME --on + fi + exit 0; +fi +echo "$NAME:Sorry.. The only root privileges!" +exit 0; +} + +### begin +case "$PARMS" in +"start" | "start" ) +zRun; +exit 0 +;; + +"stop" | "stop" ) +$ZPATH/$SCRIPTNAME --off +exit 0 +;; + +"restart" | "restart" ) +$ZPATH/$SCRIPTNAME --off +sleep 3 +zRun; +exit 0 +;; + +"status" | "status" ) +$ZPATH/$SCRIPTNAME --status +exit 0 +;; + +"boot" | "boot" ) +zBoot; +exit 0 +;; + +* ) +echo +echo "no input parameters." +exit 1 +;; +esac diff --git a/zraid.deb/etc/zraid/messages.dat b/zramraid.deb/etc/zramraid/messages.dat similarity index 57% rename from zraid.deb/etc/zraid/messages.dat rename to zramraid.deb/etc/zramraid/messages.dat index 10fb92a..1f9f7da 100644 --- a/zraid.deb/etc/zraid/messages.dat +++ b/zramraid.deb/etc/zramraid/messages.dat @@ -1,14 +1,14 @@ { "ru_RU.UTF-8":{ "msg":[ - "Система zraid не запущена!", - "Нет параметров для zraid-maker!", - "Полный запуск системы zraid: zraid-maker --on", - "Полная остановка системы zraid: zraid-maker --off", - "Состояние системы zraid: zraid-maker --status", - "Проверка конфигрурации системы zraid: zraid-maker --test", + "Система zramraid не запущена!", + "Нет параметров для zramraid-maker!", + "Полный запуск системы zramraid: zramraid-maker --on", + "Полная остановка системы zramraid: zramraid-maker --off", + "Состояние системы zramraid: zramraid-maker --status", + "Проверка конфигрурации системы zramraid: zramraid-maker --test", "В системе отсутствует пакет jq!", - "Отсутствует файл конфигурации zraid.conf!", + "Отсутствует файл конфигурации zramraid.conf!", "В системе отсутствует пакет mdadm!", "В конфигурации нет указанных md устройств!", "Неверный параметр в конфигурации!", @@ -17,10 +17,10 @@ "Не найден файл!", "Общий обьем образов превышает установленный лимит памяти!", "Это устройство занято системой", - "Старт системы zraid...", - "Стоп системы zraid...", - "zraid - включен и активированы устройства:", - "zraid - отключен", + "Старт системы zramraid...", + "Стоп системы zramraid...", + "zramraid - включен и активированы устройства:", + "zramraid - отключен", "Лимит памяти:", "Ошибка устройства md:", "Ошибка образа:", @@ -32,42 +32,42 @@ "Извините, старая версия ядра, рекомендуется 3.14.x и выше!", "Ошибочное значение", "Допускается только", - "Помомощь: zraid-maker --help", + "Помомощь: zramraid-maker --help", "Памяти всего:", "Памяти свободно:", - "Нет параметров для zraid-config!", - "Создание пустого zraid.conf: zraid-config --config-default", - "Добавление устройства MD: zraid-config --add md[x]:image - пример: md1:/home/zraid/disk1.img", - "Удаление устройства MD: zraid-config --del md[x] - пример: md1", - "Получение списка MD: zraid-config --list", - "Параметр ограничения использования памяти: zraid-config --limit-mem [x] - пример: 90% or 1024Kb", - "Параметр описание носителя: zraid-config --info-md md[x] - пример: md1", - "Помощь: zraid-config --help", + "Нет параметров для zramraid-config!", + "Создание пустого zramraid.conf: zramraid-config --config-default", + "Добавление устройства MD: zramraid-config --add md[x]:image - пример: md1:/home/zramraid/disk1.img", + "Удаление устройства MD: zramraid-config --del md[x] - пример: md1", + "Получение списка MD: zramraid-config --list", + "Параметр ограничения использования памяти: zramraid-config --limit-mem [x] - пример: 90% or 1024Kb", + "Параметр описание носителя: zramraid-config --info-md md[x] - пример: md1", + "Помощь: zramraid-config --help", "Операция не выполнена", "Выполнено - успешно.", "Не найдено:", "Введите описаниe для устройства MD и нажмите Enter:", "Описание образов в конфигурации не найдено", "Доступно только с привилегиями root!", - "Версия zraid:", + "Версия zramraid:", "Извините, старая версия ядра, рекомендуется 4.2.x и выше для этого параметра!", "- устройство уже работает...", "версия ядра не позволяет выборочное управление носителями, только полная остановка и запуск, рекомендуется 4.2.x и выше.", - "Индивидуальный запуск носителя zraid: zraid-maker --on md[x] - пример:md1", - "Индивидульная остановка носителя zraid: zraid-maker --off md[x] - пример:md1" + "Индивидуальный запуск носителя zramraid: zramraid-maker --on md[x] - пример:md1", + "Индивидульная остановка носителя zramraid: zramraid-maker --off md[x] - пример:md1" ] }, "C.UTF-8":{ "msg":[ - "Not start zraid system!", - "No input parameters for zraid-maker", - "Full start arrays zraid: zraid-maker --on", - "Full stop array zraid: zraid-maker --off", - "State arrays zraid: zraid-maker --status", - "Check config zraid arrays: zraid-maker --test", + "Not start zramraid system!", + "No input parameters for zramraid-maker", + "Full start arrays zramraid: zramraid-maker --on", + "Full stop array zramraid: zramraid-maker --off", + "State arrays zramraid: zramraid-maker --status", + "Check config zramraid arrays: zramraid-maker --test", "Not found in the system package jq!", - "Not found configuration file zraid.conf", + "Not found configuration file zramraid.conf", "Not found in the system package mdadm!", "No specified md devices!", "The parameter is incorrect!", @@ -76,10 +76,10 @@ "Not found file!", "The total images exceeds the limit of available memory!", "This device busy a system!", - "zraid start...", - "zraid stop...", - "zraid - on & enable devices:", - "zraid - off", + "zramraid start...", + "zramraid stop...", + "zramraid - on & enable devices:", + "zramraid - off", "limit mem:", "error: md", "error: image ", @@ -91,29 +91,29 @@ "I'm sorry the old kernel version! recommended 3.14 or higher", "Error value", "Allowed only", - "help: zraid-maker --help", + "help: zramraid-maker --help", "Memory total:", "Memory free:", - "No input parameters for zraid-config!", - "Create empty zraid.conf: zraid-config --config-default", - "Add device MD in config: zraid-config --add md[x]:image - example: md1:/home/zraid/disk1.img", - "Delete device MD in config: zraid-config --del md[x] - example: md1", - "Listing devices MD in config: zraid-config --list", - "The memory limit usage: zraid-config --limit-mem [x] - example: 90% or 1024Kb", - "The set info for md device: zraid-config --info-md md[x] - example: md1", - "Help: zraid-config --help", + "No input parameters for zramraid-config!", + "Create empty zramraid.conf: zramraid-config --config-default", + "Add device MD in config: zramraid-config --add md[x]:image - example: md1:/home/zramraid/disk1.img", + "Delete device MD in config: zramraid-config --del md[x] - example: md1", + "Listing devices MD in config: zramraid-config --list", + "The memory limit usage: zramraid-config --limit-mem [x] - example: 90% or 1024Kb", + "The set info for md device: zramraid-config --info-md md[x] - example: md1", + "Help: zramraid-config --help", "Operation not succeded", "Operation succeded", "Not found:", "Enter the data for device MD description and press Enter:", "description of the images in the configuration are not found", "It is only available with root privileges", - "version zraid:", + "version zramraid:", "I'm sorry the old kernel version! recommended 4.2 or higher for this option", "-device is already working", "kernel version does not allow selective media management, only a complete stop and start, recommended 4.2 or higher for this option", - "Selective startup zraid device: raid-maker --on md[x] - example: md1", - "Selective stop zraid device: raid-maker --off md[x] - example: md1" + "Selective startup zramraid device: zramraid-maker --on md[x] - example: md1", + "Selective stop zramraid device: zramraid-maker --off md[x] - example: md1" ] } } diff --git a/zraid.deb/etc/zraid/zraid-config b/zramraid.deb/etc/zramraid/zramraid-config similarity index 97% rename from zraid.deb/etc/zraid/zraid-config rename to zramraid.deb/etc/zramraid/zramraid-config index 8ee1fa0..055dce1 100755 --- a/zraid.deb/etc/zraid/zraid-config +++ b/zramraid.deb/etc/zramraid/zramraid-config @@ -1,13 +1,14 @@ #!/bin/bash -## zraid-config +## zramraid-config ## (c) author's idea and realization: Kleemov A. & Koshuba V. ## script author: Koshuba V - stvixfree@gmail.com +## License: GPLv3 ## all parameters ##settime=$(date +%s%3N); option=$1; params=$2; -PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/zraid"; -version="10.03.18"; +export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/zramraid"; +version="25.06.18"; ## msg [53] set_msg=( '"0" "0"' '"1" "0"' '"2" "0"' '"3" "0"' '"4" "0"' '"5" "0"' '"6" "1"' '"7" "1"' '"8" "1"' '"9" "1"' '"10" "1"' '"11" "1"' '"12" "1"' '"13" "1"' '"14" "1"' '"15" "1"' '"16" "0"' @@ -26,10 +27,10 @@ free_mem=$(cat /proc/meminfo |awk '/^MemAvailable:/{print $2}'); limit_mem=0; info_limit_mem=0; total_size_images=0; -zpath="/etc/zraid"; -zconfig="zraid.conf"; -zmsg="/etc/zraid/messages.dat"; -log="/var/log/zraid.log"; +zpath="/etc/zramraid"; +zconfig="zramraid.conf"; +zmsg="/etc/zramraid/messages.dat"; +log="/var/log/zramraid.log"; reports=(); id_zmd=(); image_zmd=(); @@ -121,7 +122,7 @@ value_in=""; function writeToLog() { for ((rpt_index=0; rpt_index != ${#reports[@]}; rpt_index++)) do - echo "$rdate zraid message: ${reports[$rpt_index]}">>$log; + echo "$rdate zramraid message: ${reports[$rpt_index]}">>$log; done } @@ -243,7 +244,7 @@ if [[ ! $(cat $zmsg|grep "$lang"|wc -m) == 0 ]] ##--@F step operation function readConf() { -# test enable file zraid.conf +# test enable file zramraid.conf if [ ! -f $zpath/$zconfig ] then reports=(); @@ -500,7 +501,7 @@ if [ ! -f $zpath/$zconfig ] then confNew; else - cp $zpath/$zconfig $zpath/$(date +%H_%M)"-zraid.old">/dev/null; + cp $zpath/$zconfig $zpath/$(date +%H_%M)"-zramraid.old">/dev/null; confNew; fi } @@ -645,7 +646,7 @@ done } -##- Begin ZRAID +##- Begin zramraid case "$option" in ## create default config + diff --git a/zraid.deb/etc/zraid/zraid-maker b/zramraid.deb/etc/zramraid/zramraid-maker similarity index 98% rename from zraid.deb/etc/zraid/zraid-maker rename to zramraid.deb/etc/zramraid/zramraid-maker index 9d0a375..3aaad0e 100755 --- a/zraid.deb/etc/zraid/zraid-maker +++ b/zramraid.deb/etc/zramraid/zramraid-maker @@ -1,11 +1,12 @@ #!/bin/bash -## zraid-maker +## zramraid-maker ## (c) author's idea and realization: Kleemov A. & Koshuba V. ## script author: Koshuba V - stvixfree@gmail.com +## License: GPLv3 ## all parameters option=$1; params=$2; -PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/zraid"; +PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/zramraid"; version="10.03.18"; ## msg [53] set_msg=( '"0" "1"' '"1" "1"' '"2" "1"' '"3" "1"' '"4" "1"' '"5" "1"' '"6" "1"' '"7" "1"' '"8" "1"' @@ -27,10 +28,10 @@ total_mem=$(cat /proc/meminfo |awk '/^MemTotal:/{print $2}'); free_mem=$(cat /proc/meminfo |awk '/^MemAvailable:/{print $2}'); limit_mem=0; info_limit_mem=0; -zpath="/etc/zraid"; -zconfig="/etc/zraid/zraid.conf"; -zmsg="/etc/zraid/messages.dat"; -log="/var/log/zraid.log"; +zpath="/etc/zramraid"; +zconfig="/etc/zramraid/zramraid.conf"; +zmsg="/etc/zramraid/messages.dat"; +log="/var/log/zramraid.log"; ## reports=(); id_zmd=(); @@ -126,7 +127,7 @@ value_in=""; function writeToLog() { for ((rpt_index=0; rpt_index != ${#reports[@]}; rpt_index++)) do - echo "$rdate zraid message: ${reports[$rpt_index]}">>$log; + echo "$rdate zramraid message: ${reports[$rpt_index]}">>$log; done } @@ -317,7 +318,7 @@ eXlogic; ##--@F step operation function confRead() { -# test enable file zraid.conf +# test enable file zramraid.conf if [ ! -f $zconfig ] then reports=(); @@ -870,10 +871,10 @@ done } -##- Begin ZRAID +##- Begin zramraid case "$option" in -## on zraid +## on zramraid "--on" | "--on" ) if [ ! "$params" ] then @@ -886,7 +887,7 @@ fi exit 0; ;; -## off zraid +## off zramraid "--off" | "--off" ) if [ ! "$params" ] then @@ -899,7 +900,7 @@ fi exit 0; ;; -## status zraid +## status zramraid "--status" | "--status" ) test_status=1; execute_func=( ${operation_status[@]} ); diff --git a/zraid.deb/etc/zraid/zraid.conf b/zramraid.deb/etc/zramraid/zramraid.conf similarity index 100% rename from zraid.deb/etc/zraid/zraid.conf rename to zramraid.deb/etc/zramraid/zramraid.conf diff --git a/zramraid.deb/lib/systemd/system/zramraid.service b/zramraid.deb/lib/systemd/system/zramraid.service new file mode 100644 index 0000000..f308b5e --- /dev/null +++ b/zramraid.deb/lib/systemd/system/zramraid.service @@ -0,0 +1,21 @@ +[Unit] +SourcePath=/etc/zramraid/zramraid-maker +Description=zram raid system +Before=libvirt-guests.service libvirtd.service runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target +After=dbus.service iscsid.service apparmor.service local-fs.target +Conflicts=shutdown.target + +[Service] +User=root +Group=root +Type=oneshot +GuessMainPID=no +RemainAfterExit=yes +WorkingDirectory=/etc/zramraid/ +ExecStart=/etc/init.d/zramraid-manager start +ExecStop=/etc/init.d/zramraid-manager stop +ExecReload=/etc/init.d/zramraid-manager restart +TimeoutSec=5min + +[Install] +WantedBy=multi-user.target diff --git a/zraid.deb/zraid-install b/zramraid.deb/zramraid-install similarity index 56% rename from zraid.deb/zraid-install rename to zramraid.deb/zramraid-install index e9a255a..eef5282 100755 --- a/zraid.deb/zraid-install +++ b/zramraid.deb/zramraid-install @@ -1,18 +1,17 @@ #!/bin/bash -## zraid-install (Default for Debian & Ubuntu) +## zramraid-install (Default for Debian & Ubuntu) ## (c) author's idea and realization: Kleemov A. & Koshuba V. ## script author: Koshuba V - stvixfree@gmail.com -## version = 10.03.18 +## version = 26.06.18 +## License: GPLv3 option=$1; rdate=$(date +%c); reports=(); +getpkg=( "jq" "mdadm" "lsb-release" ); test_module=$(find /lib/modules/$kernel_version -name '*.ko'|grep zram|wc -m); -test_jq=$(apt-cache policy jq | grep status); -test_mdadm=$(apt-cache policy mdadm | grep status); -test_lsb_release=$(apt-cache policy lsb-release | grep status); log="/var/log/syslog"; eval kernel_version="(" $(uname -r|sed 's/\./ /g') ")"; -debversion=$(lsb_release -c); +deb_release="" ## functions & operations operation_install=( "clear" "testId" "checkDep" "checkMod" "install" "printInfo" ); operation_uninstall=( "clear" "testId" "checkDep" "checkMod" "uninstall" "printInfo" ); @@ -50,7 +49,7 @@ value_in=""; function writeToLog() { for ((rpt_index=0; rpt_index != ${#reports[@]}; rpt_index++)) do - echo "$rdate zraid install message: ${reports[$rpt_index]}">>$log; + echo "$rdate zramraid install message: ${reports[$rpt_index]}">>$log; done } @@ -68,9 +67,9 @@ function pIhelp() { lEnd=0; clear echo - echo -e "install: zraid-install --install"; - echo -e "uninstall: zraid-install --uninstall"; - echo -e "help: zraid-install --help"; + echo -e "install: zramraid-install --install"; + echo -e "uninstall: zramraid-install --uninstall"; + echo -e "help: zramraid-install --help"; exit 0; } @@ -120,59 +119,53 @@ fi ##--@F Check the program dependency function checkDep() { -# This installation check jq -if [ ! "$test_jq" ] - then - ## lang messages if yes then lang else us... - reports[${#reports[@]}]="Do not set jq package"; - makeErr; -fi -# This installation check mdadm -if [ ! "$test_mdadm" ] - then - reports[${#reports[@]}]="Do not set mdadm package"; - makeErr; +if [[ ! $(apt-cache policy ${getpkg[@]} | grep status|wc -l) = $(echo -e ${#getpkg[@]}) ]]; + then apt-get install $(echo ${getpkg[@]}); fi -# This installation check mdadm -if [ ! "$test_lsb_release" ] +for ((ipkg=0; ipkg != ${#getpkg[@]}; ipkg++)) + do + if [ ! "$(apt-cache policy ${getpkg[$ipkg]} | grep status)" ] then - reports[${#reports[@]}]="Do not set lsb_release package"; + ## lang messages if yes then lang else us... + reports[${#reports[@]}]="Do not set ${getpkg[$ipkg]} package"; makeErr; fi - -## check Debian or Ubuntu... -## +done +local lsbtools=$(whereis -b lsb_release|awk '/^lsb_release:/{print $2}'); +deb_release=$( $lsbtools -r|awk '/^Release:/{print $2}'|sed 's/\./ /g'|awk '{print$1}' ); } function install() { -if [ ! -d "/etc/zraid" ] - then - mkdir -p /etc/zraid; -fi -cp -f $PWD/etc/zraid/messages.dat /etc/zraid/messages.dat; -cp -f $PWD/etc/zraid/zraid-config /etc/zraid/zraid-config; -cp -f $PWD/etc/zraid/zraid-maker /etc/zraid/zraid-maker; -cp -f $PWD/etc/init.d/zraid-manager /etc/init.d/zraid-manager; -cp -f $PWD/etc/default/zraid /etc/default/zraid; -ln -s /etc/zraid/zraid-maker /usr/local/bin/zraid-maker; -ln -s /etc/zraid/zraid-config /usr/local/bin/zraid-config; -## 4 deb 8.x end up -if [ $(echo $debversion|grep jessie|wc -m) != 0 ] +if [ ! -d "/etc/zramraid" ] then -cp -f $PWD/lib/systemd/system/zraid-start.service /lib/systemd/system/zraid-start.service; -cp -f $PWD/lib/systemd/system/zraid-monitor.service /lib/systemd/system/zraid-monitor.service; -/bin/systemctl enable zraid-start.service; -/bin/systemctl enable zraid-monitor.service; + mkdir -p /etc/zramraid; fi -if [ $(echo $debversion|grep wheezy|wc -m) != 0 ] - then - update-rc.d -n zraid-manager defaults; +cp -f $PWD/etc/zramraid/messages.dat /etc/zramraid/messages.dat; +cp -f $PWD/etc/zramraid/zramraid-config /etc/zramraid/zramraid-config; +cp -f $PWD/etc/zramraid/zramraid-maker /etc/zramraid/zramraid-maker; +cp -f $PWD/etc/init.d/zramraid-manager /etc/init.d/zramraid-manager; +cp -f $PWD/etc/default/zramraid /etc/default/zramraid; +ln -s /etc/zramraid/zramraid-maker /usr/local/bin/zramraid-maker; +ln -s /etc/zramraid/zramraid-config /usr/local/bin/zramraid-config; + +if [[ $deb_release < 8 ]]; + then + update-rc.d -n zramraid-manager defaults; + else + cp -f $PWD/lib/systemd/system/zramraid.service /lib/systemd/system/zramraid.service; + /bin/systemctl enable zramraid.service; + if [ -f "/lib/systemd/system/libvirt-guests.service" ]; + then + if [ $(cat /lib/systemd/system/libvirt-guests.service|grep zramraid|wc -m ) = 0 ]; + then + sed -i '/Requires=virt-guest-shutdown.target/a \'"Requires=zramraid.service" /lib/systemd/system/libvirt-guests.service; + fi + fi fi -## update-rc.0 .. -reports[${#reports[@]}]="zraid install susseful"; -reports[${#reports[@]}]="please setup config for autostart from boot: /etc/default/zraid."; +reports[${#reports[@]}]="zramraid install susseful"; +reports[${#reports[@]}]="please setup config for autostart from boot: /etc/default/zramraid."; writeToLog; printInfo; } @@ -180,36 +173,39 @@ printInfo; function uninstall() { function zrDel() { -if [ $(echo $debversion|grep jessie|wc -m) != 0 ] - then -/bin/systemctl stop zraid-manager; -/bin/systemctl disable zraid-start.service; -/bin/systemctl disable zraid-monitor.service; -rm /lib/systemd/system/zraid-start.service; -rm /lib/systemd/system/zraid-monitor.service; -fi -if [ $(echo $debversion|grep wheezy|wc -m) != 0 ] - then - /etc/init.d/zraid-manager stop; - update-rc.d -n zraid-manager remove; +if [[ $deb_release < 8 ]]; + then + /etc/init.d/zramraid-manager stop; + update-rc.d -n zramraid-manager remove; + else + /bin/systemctl stop zramraid.service; + /bin/systemctl disable zramraid.service; + rm /lib/systemd/system/zramraid.service; + if [ -f "/lib/systemd/system/libvirt-guests.service" ]; + then + if [ ! $(cat /lib/systemd/system/libvirt-guests.service|grep zramraid|wc -m ) = 0 ]; + then + sed -i -e '/'"Requires=zramraid.service"'/d' /lib/systemd/system/libvirt-guests.service; + fi + fi fi - rm -f /usr/local/bin/zraid-maker; - rm -f /usr/local/bin/zraid-config; - rm -f /etc/zraid/messages.dat; - rm -f /etc/zraid/zraid-config; - rm -f /etc/zraid/zraid-maker; - rm -f /etc/init.d/zraid-manager; - rm -f /etc/default/zraid; + rm -f /usr/local/bin/zramraid-maker; + rm -f /usr/local/bin/zramraid-config; + rm -f /etc/zramraid/messages.dat; + rm -f /etc/zramraid/zramraid-config; + rm -f /etc/zramraid/zramraid-maker; + rm -f /etc/init.d/zramraid-manager; + rm -f /etc/default/zramraid; } -if [ ! -f "/etc/zraid/zraid.conf" ] +if [ ! -f "/etc/zramraid/zramraid.conf" ] then zrDel; - rm -rf /etc/zraid; + rm -rf /etc/zramraid; else zrDel; fi -reports[${#reports[@]}]="zraid uninstall susseful"; +reports[${#reports[@]}]="zramraid uninstall susseful"; writeToLog; printInfo; @@ -240,17 +236,17 @@ for ((ex_index=0; ex_index != ${#execute_func[@]}; ex_index++)) done } -##- Begin ZRAID +##- Begin zramraid case "$option" in -## install zraid +## install zramraid "--install" | "--install" ) execute_func=( ${operation_install[@]} ); executor; exit 0 ;; -## uninstall zraid +## uninstall zramraid "--uninstall" | "--uninstall" ) execute_func=( ${operation_uninstall[@]} ); executor;