wok view linux64-zram/stuff/compcache @ rev 23440
linux-zram: autostart
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Apr 02 12:22:43 2020 +0200 (2020-04-02) |
parents | 804a303f31dc |
children | f1020832b94b |
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++}
25 END { if (c>0) p=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/ { print \$2 * 1024 * ${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