util-linux: port swapfile init scripts to systemd

Signed-off-by: Stephan Raue <stephan@openelec.tv>
This commit is contained in:
Stephan Raue 2013-08-16 15:21:59 +02:00
parent 97cc8cbd7b
commit 4fd5d8afc5
4 changed files with 51 additions and 26 deletions

View File

@ -113,10 +113,16 @@ post_makeinstall_target() {
cp .libs/swapon $INSTALL/usr/sbin cp .libs/swapon $INSTALL/usr/sbin
cp .libs/swapoff $INSTALL/usr/sbin cp .libs/swapoff $INSTALL/usr/sbin
mkdir -p $INSTALL/etc/init.d mkdir -p $INSTALL/usr/lib/openelec
cp $PKG_DIR/scripts/32_swapfile $INSTALL/etc/init.d cp -PR $PKG_DIR/scripts/mount-swap $INSTALL/usr/lib/openelec
mkdir -p $INSTALL/etc mkdir -p $INSTALL/etc
cat $PKG_DIR/config/swap.conf | sed -e "s,@SWAPFILESIZE@,$SWAPFILESIZE,g" > $INSTALL/etc/swap.conf cat $PKG_DIR/config/swap.conf | sed -e "s,@SWAPFILESIZE@,$SWAPFILESIZE,g" > $INSTALL/etc/swap.conf
fi fi
} }
post_install () {
if [ "$SWAP_SUPPORT" = "yes" ]; then
enable_service swap.service
fi
}

View File

@ -1,3 +1,4 @@
#!/bin/sh
################################################################################ ################################################################################
# This file is part of OpenELEC - http://www.openelec.tv # This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv) # Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
@ -18,35 +19,30 @@
# http://www.gnu.org/copyleft/gpl.html # http://www.gnu.org/copyleft/gpl.html
################################################################################ ################################################################################
#
# create and enable swapfile
#
# runlevels: openelec, textmode
. /etc/swap.conf . /etc/swap.conf
if [ -f $HOME/.config/swap.conf ]; then if [ -f /storage/.config/swap.conf ]; then
. $HOME/.config/swap.conf . /storage/.config/swap.conf
fi fi
(
if [ -e /proc/swaps ]; then
SWAP=`blkid -t TYPE="swap" -o device` SWAP=`blkid -t TYPE="swap" -o device`
case $1 in
create)
if [ -z "$SWAP" -a ! -f "$SWAPFILE" ]; then if [ -z "$SWAP" -a ! -f "$SWAPFILE" ]; then
progress "creating swapfile"
echo "creating Swapfile ..."
mkdir -p `dirname $SWAPFILE` mkdir -p `dirname $SWAPFILE`
dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAPFILESIZE 2>&1 > /dev/null dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAPFILESIZE
chmod 0600 $SWAPFILE 2>&1 > /dev/null chmod 0600 $SWAPFILE
mkswap $SWAPFILE 2>&1 > /dev/null mkswap $SWAPFILE
fi fi
;;
progress "enable swap" mount)
[ -z "$SWAP" -a -f "$SWAPFILE" ] && SWAP=$SWAPFILE [ -z "$SWAP" -a -f "$SWAPFILE" ] && SWAP=$SWAPFILE
for i in $SWAP; do for i in $SWAP; do
swapon -p 10000 $SWAP 2>&1 > /dev/null swapon -p 10000 $SWAP
done done
sysctl -w vm.swappiness=10 2>&1 > /dev/null ;;
fi unmount)
)& swapoff -a
;;
esac

View File

@ -0,0 +1 @@
vm.swappiness=10

View File

@ -0,0 +1,22 @@
[Unit]
Description=Mounting swapfile
DefaultDependencies=false
Before=swap.target shutdown.target
Conflicts=shutdown.target
Wants=swap.target
ConditionPathExists=/proc/swaps
ConditionKernelCommandLine=!noswap
ConditionKernelCommandLine=!installer
[Service]
Environment=HOME=/storage
Type=oneshot
ExecStartPre=/usr/lib/openelec/mount-swap create
ExecStart=/usr/lib/openelec/mount-swap mount
ExecStop=/usr/lib/openelec/mount-swap unmount
RemainAfterExit=yes
[Install]
WantedBy=basic.target