wok-6.x annotate linux-zram/stuff/compcache @ rev 23660
updated spacefm (0.9.4 -> 1.0.6)
author | Hans-G?nter Theisgen |
---|---|
date | Fri Apr 24 06:18:34 2020 +0100 (2020-04-24) |
parents | f1020832b94b |
children | 1bb3a050ea16 |
rev | line source |
---|---|
pascal@13390 | 1 #!/bin/sh |
pascal@13390 | 2 # /etc/init.d/compcache: Start, stop and restart COMPCACHE daemon on SliTaz, |
pascal@13390 | 3 # at boot time or with the command line. Daemons options are configured |
pascal@13390 | 4 # with /etc/daemons.conf |
pascal@13390 | 5 # |
pascal@13390 | 6 . /etc/init.d/rc.functions |
pascal@13390 | 7 source /etc/compcache.conf |
pascal@13390 | 8 |
pascal@13390 | 9 NAME="compcache" |
al@19159 | 10 DESC="$(_ '%s daemon' compcache)" |
pascal@22023 | 11 EXIST="$(grep -s zram0 /proc/swaps)" |
pascal@13390 | 12 |
pascal@13390 | 13 case "$1" in |
pascal@13390 | 14 start) |
pascal@22023 | 15 if [ "$EXIST" ] ; then |
al@19159 | 16 _ '%s is already running.' $NAME |
pascal@13390 | 17 exit 1 |
pascal@13390 | 18 fi |
pascal@23440 | 19 if [ -z "$SIZE" -o "$SIZE" = "0%" ]; then |
pascal@23440 | 20 _ '%s disabled in %s.' $NAME '/etc/compcache.conf' |
pascal@23440 | 21 exit 1 |
pascal@23440 | 22 fi |
al@19159 | 23 action 'Loading module...' |
pascal@23634 | 24 devices=$(awk '/cpu cores/{c=$4} /processor/{p++} /siblings/{s=$3} |
pascal@23634 | 25 END { if (c*s>0) p/=s/c; if (p==0) p++; print p}' /proc/cpuinfo) |
Hans-G?nter@22377 | 26 modprobe zram num_devices=$devices && |
pascal@23440 | 27 for i in $(seq 0 $(($devices-1))); do |
pascal@23469 | 28 awk "/MemTotal/ { print \$2 * 1024 * ${SIZE%\%} / 100 / $devices }" \ |
pascal@23440 | 29 < /proc/meminfo > /sys/block/zram$i/disksize |
pascal@21917 | 30 done |
pascal@13390 | 31 status |
pascal@13390 | 32 |
al@19159 | 33 action 'Starting %s: %s...' "$DESC" $NAME |
pascal@21917 | 34 for i in $(seq 0 $(($devices-1))); do |
pascal@21917 | 35 mkswap /dev/zram$i && swapon /dev/zram$i -p 100 |
pascal@21917 | 36 done |
pascal@13390 | 37 status |
pascal@13390 | 38 ;; |
pascal@13390 | 39 stop) |
al@19159 | 40 if [ -z "$EXIST" ] ; then |
al@19159 | 41 _ '%s is not running.' $NAME |
pascal@13390 | 42 exit 1 |
pascal@13390 | 43 fi |
al@19159 | 44 action 'Stopping %s: %s...' "$DESC" $NAME |
pascal@21917 | 45 for i in $(cd /sys/block/; ls -d zram*); do |
pascal@21917 | 46 swapoff /dev/$i && echo 1 > /sys/block/$i/reset |
pascal@21917 | 47 done |
pascal@13390 | 48 status |
al@19159 | 49 action 'Unloading module...' |
pascal@13390 | 50 rmmod zram |
pascal@13390 | 51 status |
pascal@13390 | 52 ;; |
pascal@13390 | 53 *) |
al@19159 | 54 emsg "<n><b>$(_ 'Usage:')</b> $0 [start|stop]" |
al@19159 | 55 newline |
pascal@13390 | 56 exit 1 |
pascal@13390 | 57 ;; |
pascal@13390 | 58 esac |
pascal@13390 | 59 |
pascal@13390 | 60 exit 0 |