Skip to content

Commit 5f2ffc8

Browse files
authored
Remove zramsync service (#7)
Signed-off-by: Ethan Dye <[email protected]>
1 parent 2f51a14 commit 5f2ffc8

8 files changed

+185
-267
lines changed

README.md

+92-76
Large diffs are not rendered by default.

install.sh

+23-27
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
3+
if [[ "$(id -u)" -ne 0 ]]; then
4+
echo "ERROR: You need to be ROOT (sudo can be used)."
5+
exit 1
6+
fi
7+
if [[ $(systemctl is-active zram-config.service) == "active" ]]; then
8+
echo "ERROR: zram-config service is still running. Please run \"sudo systemctl stop zram-config.service\" to stop it and then uninstall before running this."
9+
exit 1
10+
fi
11+
if [[ -f /usr/local/sbin/zram-config ]]; then
12+
echo "ERROR: zram-config is already installed, uninstall first."
13+
exit 1
14+
fi
15+
16+
if ! dpkg -s 'make' 'libattr1-dev' &> /dev/null; then
17+
apt-get install --yes make libattr1-dev || exit 1
18+
fi
219

3-
source /etc/openhabian.conf
4-
5-
6-
systemctl -q is-active zram-config && { echo "ERROR: zram-config service is still running. Please run \"sudo service zram-config stop\" to stop it and uninstall"; exit 1; }
7-
[ "$(id -u)" -eq 0 ] || { echo "You need to be ROOT (sudo can be used)"; exit 1; }
8-
[ -d /usr/local/bin/zram-config ] && { echo "zram-config is already installed, uninstall first"; exit 1; }
9-
10-
apt-get -y install libattr1-dev
11-
12-
#if grep -q "buster" /etc/os-release
13-
#then
14-
# git clone https://github.com/StuartIanNaylor/overlayfs-tools -b Arch
15-
#else
16-
# git clone https://github.com/StuartIanNaylor/overlayfs-tools
17-
#fi
18-
19-
# buster compile fixed in origin
2020
git clone https://github.com/kmxz/overlayfs-tools
21-
cd overlayfs-tools
21+
cd overlayfs-tools || exit 1
2222
make
2323
cd ..
2424

25-
sed -i "s|%STORAGE|${storagedir:-/storage}|g" zram-config.service
26-
# zram-config install
2725
install -m 755 zram-config /usr/local/sbin/
28-
install -m 755 zramsync /usr/local/sbin/
2926
install -m 644 zram-config.service /etc/systemd/system/zram-config.service
3027
install -m 644 ztab /etc/ztab
31-
mkdir -p /usr/local/share/zram-config
3228
mkdir -p /usr/local/share/zram-config/log
3329
install -m 644 uninstall.sh /usr/local/share/zram-config/uninstall.sh
3430
install -m 644 ro-root.sh /usr/local/share/zram-config/ro-root.sh
3531
install -m 644 zram-config.logrotate /etc/logrotate.d/zram-config
3632
mkdir -p /usr/local/lib/zram-config/
37-
3833
install -m 755 overlayfs-tools/overlay /usr/local/lib/zram-config/overlay
39-
systemctl enable zram-config
34+
systemctl daemon-reload
35+
systemctl enable zram-config.service
4036

41-
#echo "##### Reboot to activate zram-config #####"
42-
#echo "##### edit /etc/ztab to configure options #####"
37+
echo "##### Reboot to activate zram-config #####"
38+
echo "##### edit /etc/ztab to configure options #####"

uninstall.sh

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
if [ "$(id -u)" -eq 0 ]
4-
then
5-
service zram-config stop
6-
systemctl disable zram-config
7-
rm /etc/systemd/system/zram-config.service
8-
rm /usr/local/bin/zram-config
9-
rm /etc/ztab
10-
rm /etc/logrotate.d/zram-config
11-
12-
echo "zram-config is uninstalled, removing the uninstaller in progress"
13-
rm -rf /usr/local/share/zram-config
14-
rm -rf /usr/local/lib/zram-config
15-
echo "##### Reboot isn't needed #####"
16-
else
17-
echo "You need to be ROOT (sudo can be used)"
3+
if [[ "$(id -u)" -ne 0 ]]; then
4+
echo "ERROR: You need to be ROOT (sudo can be used)."
5+
exit 1
186
fi
7+
8+
systemctl disable --now zram-config.service
9+
rm -f /etc/systemd/system/zram-config.service
10+
rm -f /usr/local/bin/zram-config
11+
rm -f /etc/logrotate.d/zram-config
12+
rm -f /etc/ztab
13+
rm -rf /usr/local/lib/zram-config
14+
rm -rf /usr/local/share/zram-config
15+
16+
echo "##### Reboot isn't needed #####"

zram-config

+15-46
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ createZdir() {
108108
}
109109

110110
createZlog() {
111-
if [[ $(dpkg -s 'nginx') ]] && [[ $(systemctl is-active nginx.service) ]]; then
111+
if dpkg -s 'nginx' &> /dev/null && [[ $(systemctl is-active nginx.service) == "active" ]]; then
112112
systemctl stop nginx.service >> "$ZLOG" 2>&1 || return 1
113113
fi
114-
if [[ $(systemctl is-active rsyslog.service) ]]; then
114+
if [[ $(systemctl is-active rsyslog.service) == "active" ]]; then
115115
systemctl stop rsyslog.service >> "$ZLOG" 2>&1 || return 1
116116
fi
117117

118118
createZdir
119119

120120
systemctl restart rsyslog.service >> "$ZLOG" 2>&1 || return 1
121-
if [[ $(dpkg -s 'nginx') ]]; then
121+
if dpkg -s 'nginx' &> /dev/null; then
122122
systemctl restart nginx.service >> "$ZLOG" 2>&1 || return 1
123123
fi
124124

@@ -146,13 +146,14 @@ removeZlog() {
146146
fi
147147

148148
echo "$ZRAM_DEV" >> "$ZLOG"
149-
local DEV_NUM="$(echo "$ZRAM_DEV" | tr -dc '0-9')"
149+
local DEV_NUM
150+
DEV_NUM="$(echo "$ZRAM_DEV" | tr -dc '0-9')"
150151

151152
if [[ -n $TARGET_DIR ]]; then
152-
if [[ $(dpkg -s 'nginx') ]] && [[ $(systemctl is-active nginx.service) ]]; then
153+
if dpkg -s 'nginx' &> /dev/null && [[ $(systemctl is-active nginx.service) == "active" ]]; then
153154
systemctl stop nginx.service >> "$ZLOG" 2>&1 || return 1
154155
fi
155-
if [[ $(systemctl is-active rsyslog.service) ]]; then
156+
if [[ $(systemctl is-active rsyslog.service) == "active" ]]; then
156157
systemctl stop rsyslog.service >> "$ZLOG" 2>&1 || return 1
157158
fi
158159

@@ -180,18 +181,18 @@ removeZlog() {
180181
return 1
181182
fi
182183

183-
if [[ $(dpkg -s 'nginx') ]] && [[ $(systemctl is-active nginx.service) ]]; then
184+
if dpkg -s 'nginx' &> /dev/null && [[ $(systemctl is-active nginx.service) == "active" ]]; then
184185
systemctl stop nginx.service >> "$ZLOG" 2>&1 || return 1
185186
fi
186-
if [[ $(systemctl is-active rsyslog.service) ]]; then
187+
if [[ $(systemctl is-active rsyslog.service) == "active" ]]; then
187188
systemctl stop rsyslog.service >> "$ZLOG" 2>&1 || return 1
188189
fi
189190

190191
echo "$DEV_NUM" > /sys/class/zram-control/hot_remove
191192
zramctl -r "/dev${ZRAM_DEV}" >> "$ZLOG" 2>&1 || return 1
192193

193194
systemctl restart rsyslog.service >> "$ZLOG" 2>&1 || return 1
194-
if [[ $(dpkg -s 'nginx') ]]; then
195+
if dpkg -s 'nginx' &> /dev/null; then
195196
systemctl restart nginx.service >> "$ZLOG" 2>&1 || return 1
196197
fi
197198

@@ -201,7 +202,8 @@ removeZlog() {
201202

202203
removeZdir() {
203204
echo "$ZRAM_DEV" >> "$ZLOG"
204-
local DEV_NUM="$(echo "$ZRAM_DEV" | tr -dc '0-9')"
205+
local DEV_NUM
206+
DEV_NUM="$(echo "$ZRAM_DEV" | tr -dc '0-9')"
205207

206208
if [[ -n "$TARGET_DIR" ]]; then
207209
if ! (umount --verbose "${TARGET_DIR}/" >> "$ZLOG" 2>&1); then
@@ -234,7 +236,8 @@ removeZdir() {
234236
}
235237

236238
removeZswap() {
237-
local DEV_NUM="$(echo "$ZRAM_DEV" | tr -dc '0-9')"
239+
local DEV_NUM
240+
DEV_NUM="$(echo "$ZRAM_DEV" | tr -dc '0-9')"
238241

239242
swapoff "/dev${ZRAM_DEV}" >> "$ZLOG" 2>&1 || return 1
240243
echo "$DEV_NUM" > /sys/class/zram-control/hot_remove
@@ -415,42 +418,8 @@ case "$1" in
415418
disableZephemeral
416419
;;
417420

418-
sync)
419-
echo "zram-config sync $(date +%Y-%m-%d-%H:%M:%S)" >> "$ZLOG"
420-
tac "${TMPDIR}"/zram-device-list > "${TMPDIR}"/zram-device-list.rev
421-
file="${TMPDIR}/zram-device-list.rev"
422-
while read -r line; do
423-
case "$line" in
424-
"#"*)
425-
# Skip comment line
426-
continue
427-
;;
428-
429-
"")
430-
# Skip empty line
431-
continue
432-
;;
433-
434-
*)
435-
set -- $line
436-
echo "ztab sync ${1} ${2} ${3} ${4}" >> "$ZLOG"
437-
case "$1" in
438-
dir|log)
439-
ZTYPE="$1"
440-
ZRAM_DEV="$2"
441-
TARGET_DIR="$3"
442-
BIND_DIR="$4"
443-
mergeOverlay
444-
;;
445-
esac
446-
;;
447-
esac
448-
done < "$file"
449-
rm -fv "${TMPDIR}"/zram-device-list.rev >> "$ZLOG"
450-
;;
451-
452421
*)
453-
echo "Usage: zram-config {start|stop|sync|enable-ephemeral|disable-ephemeral}" > 2
422+
echo "Usage: zram-config {start|stop|enable-ephemeral|disable-ephemeral}" > 2
454423
exit 1
455424
;;
456425
esac

zram-config.service

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[Unit]
22
Description=zram-config
33
After=local-fs.target
4-
Before=openhab2.service smbd.service
4+
Before=reboot.target halt.target shutdown.target poweroff.target openhab2.service smbd.service
55

66
[Service]
77
Type=oneshot
88
TimeoutSec=300
99
RemainAfterExit=yes
10-
ExecStartPre=-/usr/local/sbin/zramsync "recover" "%STORAGE/zram"
1110
ExecStart=/usr/local/sbin/zram-config "start"
11+
ExecStart=/usr/local/sbin/zram-config "stop"
1212

1313
[Install]
1414
WantedBy=basic.target

zramsync

-68
This file was deleted.

zramsync.service

-17
This file was deleted.

ztab

+39-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
1-
# To comment out any line Add new drives with the first collumn providing the drive type and then drive details seperated by tab
2-
# All algorithm in /proc/crypto are supported but only lzo/lz4 have zramctl text strings.
3-
# lz4 is the fastest whilst deflate(zlib) has much better text compression.
4-
# mem_limit is compressed memory limit and will set a hard memory limit for sys admin.
5-
# disk_size is virtual uncompressed size approx 220-450% of mem allocated depending on algorithm and input file.
6-
# Much higher than the compression alg is capable will waste mem as there is an approx 0.1% mem overhead even when empty.
7-
# swap_priority set zram over alternative swap devices.
8-
# page-cluster 0 means tuning to singular pages rather than default 3 which caches 8 for HDD tuning, which can lower latency.
9-
# swappiness 80 due to improved performance of zram allows more usage without effect of raising from default 60.
10-
# Can be up to 100 but will increase process queue on intense load such as boot.
11-
# zram_dir is the directory you wish to hold in zram, the original is moved to a bind mount bind_dir and is synchronised on start/stop and write commands.
12-
# bind_dir is a directory where the original dir will be mounted for sync purposes. Usually in /opt or /var, name optional.
13-
# oldlog_dir will enable logrotation to an off device directory whilst retaining only live logs in zram. Usually in /opt or /var, name optional.
14-
# If you need multiple zram swaps or zram dirs just create another entry in /ect/ztab.
15-
# Stop the service sudo service zram-config stop edit /etc/ztab sudo nano /etc/ztab start the service sudo service zram-config start
1+
# Use '#' to comment out any line, add new drives with the first column
2+
# providing the drive type and then drive details separated by tab characters.
3+
#
4+
# All algorithms in '/proc/crypto' are supported but only lzo and lz4 have
5+
# zramctl text strings; lz4 is the fastest with deflate(zlib) having much better
6+
# text compression.
7+
#
8+
# mem_limit is the compressed memory limit and will set a hard memory limit for
9+
# the system admin.
10+
#
11+
# disk_size is the virtual uncompressed size approx. 220-450% of memory
12+
# allocated depending on the algorithm and input file. Don't make it much higher
13+
# than the compression algorithm is capable of as it will waste memory because
14+
# there is a ~0.1% memory overhead when empty
15+
#
16+
# swap_priority will set ZRAM over alternative swap devices.
17+
#
18+
# page-cluster 0 means tuning to singular pages rather than the default 3 which
19+
# caches 8 for HDD tuning, which can lower latency.
20+
#
21+
# swappiness 80 because the improved performance of ZRAM allows more usage
22+
# without any adverse affects from the default of 60. It can be raised up to 100
23+
# but that will increase process queue on intense loads such as boot time.
24+
#
25+
# target_dir is the directory you wish to hold in ZRAM, and the original will be
26+
# moved to a bind mount 'bind_dir' and is synchronized on start, stop, and write
27+
# commands.
28+
#
29+
# bind_dir is the directory where the original directory will be mounted for
30+
# sync purposes. Usually in '/opt' or '/var', name optional.
31+
#
32+
# oldlog_dir will enable log-rotation to an off device directory while retaining
33+
# only live logs in ZRAM. Usually in '/opt' or '/var', name optional.
34+
#
35+
# If you need multiple ZRAM swaps or ZRAM directories, just create another entry
36+
# in this file.
37+
# To do this safely, first stop ZRAM using 'systemctl stop zram-config.service',
38+
# then edit this file.
39+
# Once finished, restart ZRAM using 'systemctl restart zram-config.service'.
1640

1741
# swap alg mem_limit disk_size swap_priority page-cluster swappiness
1842
swap lz4 250M 750M 75 0 80

0 commit comments

Comments
 (0)