wok-6.x view linux-zram/stuff/compcache @ rev 24072
Add some current_version
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Jul 07 17:56:16 2021 +0000 (2021-07-07) |
parents | 87b5f192a581 |
children |
line source
1 #!/bin/sh
2 # /etc/init.d/compcache: Start, stop and restart COMPCACHE daemon on SliTaz,
3 # at boot time or with the command line. Daemons options are configured
4 # with /etc/daemons.conf
5 #
6 . /etc/init.d/rc.functions
7 source /etc/compcache.conf
9 NAME="compcache"
10 DESC="$(_ '%s daemon' compcache)"
11 EXIST="$(grep -s zram0 /proc/swaps)"
13 case "$1" in
14 start)
15 if [ "$EXIST" ] ; then
16 _ '%s is already running.' $NAME
17 exit 1
18 fi
19 if [ -z "$SIZE" -o "$SIZE" = "0%" ]; then
20 _ '%s disabled in %s.' $NAME '/etc/compcache.conf'
21 exit 1
22 fi
23 action 'Loading module...'
24 devices=$(awk '/cpu cores/{c=$4} /processor/{p++} /siblings/{s=$3}
25 END { if (c*s>0) p/=s/c; if (p==0) p++; print p}' /proc/cpuinfo)
26 modprobe zram num_devices=$devices &&
27 for i in $(seq 0 $(($devices-1))); do
28 awk "/MemTotal/ { printf(\"%uk\\n\", \$2 * ${SIZE%\%} / 100 / $devices) }" \
29 < /proc/meminfo > /sys/block/zram$i/disksize
30 done
31 status
33 action 'Starting %s: %s...' "$DESC" $NAME
34 for i in $(seq 0 $(($devices-1))); do
35 mkswap /dev/zram$i && swapon /dev/zram$i -p 100
36 done
37 status
38 ;;
39 stop)
40 if [ -z "$EXIST" ] ; then
41 _ '%s is not running.' $NAME
42 exit 1
43 fi
44 action 'Stopping %s: %s...' "$DESC" $NAME
45 for i in $(cd /sys/block/; ls -d zram*); do
46 swapoff /dev/$i && echo 1 > /sys/block/$i/reset
47 done
48 status
49 action 'Unloading module...'
50 rmmod zram
51 status
52 ;;
53 *)
54 emsg "<n><b>$(_ 'Usage:')</b> $0 [start|stop]"
55 newline
56 exit 1
57 ;;
58 esac
60 exit 0