Skip to content

Commit 7a3976b

Browse files
committed
added nc-zram
1 parent 1c23fa7 commit 7a3976b

File tree

4 files changed

+107
-4
lines changed

4 files changed

+107
-4
lines changed

changelog.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

2-
[v0.46.40](https://github.com/nextcloud/nextcloudpi/commit/e88aa04) (2018-03-04) nc-backup-auto: change to using cron
2+
[v0.47.0](https://github.com/nextcloud/nextcloudpi/commit/4dd3979) (2018-03-05) added nc-zram
33

4-
[v0.46.39](https://github.com/nextcloud/nextcloudpi/commit/2371806) (2018-03-04) nc-ramlogs: change implementation to use log2ram
4+
[v0.46.40](https://github.com/nextcloud/nextcloudpi/commit/a251f64) (2018-03-04) nc-backup-auto: change to using cron
5+
6+
[v0.46.39](https://github.com/nextcloud/nextcloudpi/commit/5ed50c9) (2018-03-04) nc-ramlogs: change implementation to use log2ram
57

68
[v0.46.38](https://github.com/nextcloud/nextcloudpi/commit/63513bc) (2018-03-04) disable ncp user login
79

etc/nextcloudpi-config.d/nc-swapfile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ configure()
3333
[[ -d "$DSTDIR" ]] || { echo "$DSTDIR Doesn't exist. Abort"; return 1; }
3434

3535
[[ "$( stat -fc%T "$DSTDIR" )" == "btrfs" ]] && {
36-
echo "BTRFS doesn't support swapfiles"
36+
echo "BTRFS doesn't support swapfiles. You can still use nc-zram"
3737
return 1
3838
}
3939

etc/nextcloudpi-config.d/nc-zram.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
3+
# NextCloudPi ZRAM settings
4+
#
5+
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
6+
# GPL licensed (see end of file) * Use at your own risk!
7+
#
8+
# Usage:
9+
#
10+
# ./installer.sh nc-zram.sh <IP> (<img>)
11+
#
12+
# See installer.sh instructions for details
13+
#
14+
# More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/
15+
#
16+
17+
ACTIVE_=no
18+
DESCRIPTION="Enable compressed RAM to improve swap performance"
19+
20+
install()
21+
{
22+
cat > /etc/systemd/system/zram.service <<EOF
23+
[Unit]
24+
Description=Set up ZRAM
25+
26+
[Service]
27+
Type=oneshot
28+
ExecStart=/usr/local/bin/ncp-zram start
29+
ExecStop=/usr/local/bin/ncp-zram stop
30+
RemainAfterExit=yes
31+
32+
[Install]
33+
WantedBy=sysinit.target
34+
EOF
35+
36+
cat > /usr/local/bin/ncp-zram <<'EOF'
37+
#!/bin/bash
38+
# inspired by https://github.com/novaspirit/rpi_zram/blob/master/zram.sh
39+
40+
case "$1" in
41+
start)
42+
CORES=$(nproc --all)
43+
modprobe zram num_devices=$CORES || exit 1
44+
45+
swapoff -a
46+
47+
TOTALMEM=`free | grep -e "^Mem:" | awk '{print $2}'`
48+
MEM=$(( ($TOTALMEM / $CORES)* 1024 ))
49+
50+
core=0
51+
while [ $core -lt $CORES ]; do
52+
echo $MEM > /sys/block/zram$core/disksize
53+
mkswap /dev/zram$core
54+
swapon -p 5 /dev/zram$core
55+
let core=core+1
56+
done
57+
;;
58+
59+
stop)
60+
swapoff -a
61+
rmmod zram
62+
;;
63+
*)
64+
echo "Usage: $0 {start|stop}" >&2
65+
exit 1
66+
;;
67+
esac
68+
EOF
69+
chmod +x /usr/local/bin/ncp-zram
70+
}
71+
72+
configure()
73+
{
74+
[[ $ACTIVE_ != "yes" ]] && {
75+
systemctl stop zram
76+
systemctl disable zram
77+
echo "ZRAM disabled"
78+
return 0
79+
}
80+
systemctl start zram
81+
systemctl enable zram
82+
echo "ZRAM enabled"
83+
}
84+
85+
# License
86+
#
87+
# This script is free software; you can redistribute it and/or modify it
88+
# under the terms of the GNU General Public License as published by
89+
# the Free Software Foundation; either version 2 of the License, or
90+
# (at your option) any later version.
91+
#
92+
# This script is distributed in the hope that it will be useful,
93+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
94+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95+
# GNU General Public License for more details.
96+
#
97+
# You should have received a copy of the GNU General Public License
98+
# along with this script; if not, write to the
99+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
100+
# Boston, MA 02111-1307 USA
101+

update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ done
124124

125125
# update ncp-backup
126126
cd "$CONFDIR" &>/dev/null
127-
install_script nc-backup.sh
127+
install_script nc-backup.sh &>/dev/null
128128
cd - &>/dev/null
129129

130130
# add ncp-config link

0 commit comments

Comments
 (0)