File: nbdswapd

package info (click to toggle)
ltsp 5.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,932 kB
  • ctags: 271
  • sloc: sh: 5,267; ansic: 1,048; perl: 225; python: 211; lex: 152; makefile: 112; yacc: 59
file content (69 lines) | stat: -rwxr-xr-x 2,057 bytes parent folder | download
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
#
#  Copyright (c) 2006 Vagrant Cascadian <vagrant@freegeek.org>
#
#  2006, Oliver Grawert <ogra@canonical.com>
#  2008, Warren Togami <wtogami@redhat.com>
#        Vagrant Cascadian <vagrant@freegeek.org>
#        Eric Harrison <eharrison@k12linux.mesd.k12.or.us>
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation; either version 2 of the
#  License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, you can find it on the World Wide
#  Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
#  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#


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

# default to running mkswap 
RUN_MKSWAP=true

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

# Abort if liveimg
cat /proc/cmdline |/bin/grep -q "liveimg"
[ $? -eq 0 ] && exit 0

# swapfile size (in MB)
SIZE=${SIZE:-"64"}

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

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

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

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

# start the swap server
PATH=/usr/bin:/bin:$PATH nbd-server 0 $SWAP $NBD_SERVER_OPTS -C /dev/null > /dev/null 2>&1

# clean up the swap file
rm -f $SWAP