File: nbdswapd

package info (click to toggle)
ltsp 0.99debian11
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 976 kB
  • ctags: 103
  • sloc: sh: 1,320; python: 485; ansic: 436; lex: 152; makefile: 129; yacc: 58
file content (43 lines) | stat: -rwxr-xr-x 1,003 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh

# copyright 2006 Vagrant Cascadian <vagrant@freegeek.org>, distributed under
# the terms of the GNU General Public License version 2 or any later version.

# generates a swap file and configures nbd-server to export it
# to stdout. should usually be run from an inetd.

# default swapfile size (in MB)
SIZE=32

# default to running mkswap 
RUN_MKSWAP=true

if [ -f /etc/ltsp/nbdswapd.conf ]; then
    . /etc/ltsp/nbdswapd.conf
fi

if [ -n "$SWAPDIR" ]; then
    if [ -d "$SWAPDIR" ] && [ -w "$SWAPDIR" ]; then
        TEMPFILE_OPTS="-d $SWAPDIR"
    else
        echo "ERROR: not a directory or not writeable: $SWAPDIR" > /dev/stderr
        exit 1
    fi
fi

if [ -z "$SWAP" ]; then
    SWAP=$(tempfile $TEMPFILE_OPTS)
fi

# generate the swap file
dd if=/dev/zero of=$SWAP bs=1024k count=$SIZE 2> /dev/null

if [ "$RUN_MKSWAP" = "true" ]; then
    /sbin/mkswap $SWAP > /dev/null 2>&1
fi

# start the swap server
/bin/nbd-server 0 $SWAP $NBD_SERVER_OPTS

# clean up the swap file
rm -f $SWAP