From 4fd5d8afc59905ca737f8ff1afc2384e4153e27a Mon Sep 17 00:00:00 2001 From: Stephan Raue Date: Fri, 16 Aug 2013 15:21:59 +0200 Subject: [PATCH] util-linux: port swapfile init scripts to systemd Signed-off-by: Stephan Raue --- packages/sysutils/util-linux/package.mk | 10 ++++- .../scripts/{32_swapfile => mount-swap} | 44 +++++++++---------- .../util-linux/sysctl.d/swappiness.conf | 1 + .../sysutils/util-linux/system.d/swap.service | 22 ++++++++++ 4 files changed, 51 insertions(+), 26 deletions(-) rename packages/sysutils/util-linux/scripts/{32_swapfile => mount-swap} (63%) mode change 100644 => 100755 create mode 100644 packages/sysutils/util-linux/sysctl.d/swappiness.conf create mode 100644 packages/sysutils/util-linux/system.d/swap.service diff --git a/packages/sysutils/util-linux/package.mk b/packages/sysutils/util-linux/package.mk index dc2c2cce47..280d4b5bf9 100644 --- a/packages/sysutils/util-linux/package.mk +++ b/packages/sysutils/util-linux/package.mk @@ -113,10 +113,16 @@ post_makeinstall_target() { cp .libs/swapon $INSTALL/usr/sbin cp .libs/swapoff $INSTALL/usr/sbin - mkdir -p $INSTALL/etc/init.d - cp $PKG_DIR/scripts/32_swapfile $INSTALL/etc/init.d + mkdir -p $INSTALL/usr/lib/openelec + cp -PR $PKG_DIR/scripts/mount-swap $INSTALL/usr/lib/openelec mkdir -p $INSTALL/etc cat $PKG_DIR/config/swap.conf | sed -e "s,@SWAPFILESIZE@,$SWAPFILESIZE,g" > $INSTALL/etc/swap.conf fi } + +post_install () { + if [ "$SWAP_SUPPORT" = "yes" ]; then + enable_service swap.service + fi +} diff --git a/packages/sysutils/util-linux/scripts/32_swapfile b/packages/sysutils/util-linux/scripts/mount-swap old mode 100644 new mode 100755 similarity index 63% rename from packages/sysutils/util-linux/scripts/32_swapfile rename to packages/sysutils/util-linux/scripts/mount-swap index f5ac377db2..16c2996553 --- a/packages/sysutils/util-linux/scripts/32_swapfile +++ b/packages/sysutils/util-linux/scripts/mount-swap @@ -1,3 +1,4 @@ +#!/bin/sh ################################################################################ # This file is part of OpenELEC - http://www.openelec.tv # Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv) @@ -18,35 +19,30 @@ # http://www.gnu.org/copyleft/gpl.html ################################################################################ -# -# create and enable swapfile -# -# runlevels: openelec, textmode - . /etc/swap.conf -if [ -f $HOME/.config/swap.conf ]; then - . $HOME/.config/swap.conf +if [ -f /storage/.config/swap.conf ]; then + . /storage/.config/swap.conf 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 - progress "creating swapfile" - echo "creating Swapfile ..." mkdir -p `dirname $SWAPFILE` - dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAPFILESIZE 2>&1 > /dev/null - chmod 0600 $SWAPFILE 2>&1 > /dev/null - mkswap $SWAPFILE 2>&1 > /dev/null + dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAPFILESIZE + chmod 0600 $SWAPFILE + mkswap $SWAPFILE fi - - progress "enable swap" - [ -z "$SWAP" -a -f "$SWAPFILE" ] && SWAP=$SWAPFILE - for i in $SWAP; do - swapon -p 10000 $SWAP 2>&1 > /dev/null - done - sysctl -w vm.swappiness=10 2>&1 > /dev/null - fi -)& + ;; + mount) + [ -z "$SWAP" -a -f "$SWAPFILE" ] && SWAP=$SWAPFILE + for i in $SWAP; do + swapon -p 10000 $SWAP + done + ;; + unmount) + swapoff -a + ;; +esac diff --git a/packages/sysutils/util-linux/sysctl.d/swappiness.conf b/packages/sysutils/util-linux/sysctl.d/swappiness.conf new file mode 100644 index 0000000000..b700b4d79f --- /dev/null +++ b/packages/sysutils/util-linux/sysctl.d/swappiness.conf @@ -0,0 +1 @@ +vm.swappiness=10 \ No newline at end of file diff --git a/packages/sysutils/util-linux/system.d/swap.service b/packages/sysutils/util-linux/system.d/swap.service new file mode 100644 index 0000000000..509b5e5415 --- /dev/null +++ b/packages/sysutils/util-linux/system.d/swap.service @@ -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