Add 'etc-init.d-swapfile'
This commit is contained in:
parent
c25e02d599
commit
2d2a6e3835
83
etc-init.d-swapfile
Normal file
83
etc-init.d-swapfile
Normal file
@ -0,0 +1,83 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# (C) 2016 - 2023 Fernao Vellozo
|
||||
# This is free software under the terms of GPLv3
|
||||
|
||||
START=90
|
||||
|
||||
EXTRA_COMMANDS="status create"
|
||||
EXTRA_HELP=" status Check service status
|
||||
create Create a swapfile"
|
||||
|
||||
SWPATH="/mnt/routerdata/swapfile"
|
||||
|
||||
boot() {
|
||||
if [ -f $SWPATH ]; then
|
||||
swapon $SWPATH
|
||||
logger "swapfile started on boot"
|
||||
else
|
||||
logger "ERROR: swapfile not found"
|
||||
fi
|
||||
}
|
||||
|
||||
start() {
|
||||
if [ -f $SWPATH ]; then
|
||||
swapon $SWPATH
|
||||
logger "swapfile started"
|
||||
echo "SwapFile started"
|
||||
else
|
||||
logger "ERROR: swapfile not found"
|
||||
echo "ERROR: SwapFile not found at "$SWPATH
|
||||
fi
|
||||
}
|
||||
|
||||
restart() {
|
||||
if [ -f $SWPATH ]; then
|
||||
swapoff $SWPATH
|
||||
swapon $SWPATH
|
||||
logger "swapfile stopped, reloading..."
|
||||
echo "SwapFile Reloaded"
|
||||
else
|
||||
logger "ERROR: swapfile not found"
|
||||
echo "ERROR: SwapFile not found at "$SWPATH
|
||||
fi
|
||||
}
|
||||
|
||||
stop() {
|
||||
if [ -f $SWPATH ]; then
|
||||
swapoff $SWPATH
|
||||
logger "swapfile stopped"
|
||||
echo "SwapFile stopped "$SWPATH
|
||||
else
|
||||
logger "ERROR: swapfile not found"
|
||||
echo "ERROR: SwapFile not found at "$SWPATH
|
||||
fi
|
||||
}
|
||||
|
||||
create() {
|
||||
RAMTOTAL=`fgrep MemTotal /proc/meminfo | awk '{print $2}'`
|
||||
SWAPTOTAL=`fgrep SwapTotal /proc/meminfo | awk '{print $2}'`
|
||||
if [ $SWAPTOTAL != 0 ]; then
|
||||
echo "ERROR: Swap already in use, quitting..."
|
||||
else
|
||||
dd if=/dev/zero of=$SWFILE bs=1024 count=$RAMTOTAL
|
||||
mkswap -L SWAPFILE $SWFILE
|
||||
chmod 600 $SWFILE
|
||||
/etc/init.d/swapfile enable
|
||||
logger "SwapFile created"
|
||||
echo "SwapFile successfully created, enabled to run after the next reboot"
|
||||
fi
|
||||
}
|
||||
|
||||
status() {
|
||||
SWAPTOTAL=`fgrep SwapTotal /proc/meminfo | awk '{print $2}'`
|
||||
if [ $SWAPTOTAL == 0 ]; then
|
||||
echo "No swap memory available"
|
||||
else
|
||||
echo $SWAPTOTAL "KB of swap are available"
|
||||
if [ -f $SWPATH ]; then
|
||||
echo "Swapfile is located at "$SWPATH
|
||||
else
|
||||
echo "Swap memory has been loaded, but not from here"
|
||||
fi
|
||||
fi
|
||||
}
|
Loading…
Reference in New Issue
Block a user