add support for sysctl.conf.d
Former-commit-id: 5bf692c236e8cd9d3dbbb4b56da9394384199b59 Former-commit-id: 141eff08cf61243c5e0ffddf99b61ab5a61da338
This commit is contained in:
parent
011635023e
commit
37618793de
44
genswap.sh
44
genswap.sh
@ -4,7 +4,8 @@ SWAPPATH=/
|
|||||||
SWAPNAME="swapfile"
|
SWAPNAME="swapfile"
|
||||||
TOTALRAM=$(free -m | gawk '/Mem:/{print $2}')
|
TOTALRAM=$(free -m | gawk '/Mem:/{print $2}')
|
||||||
SWAPPINESS="10"
|
SWAPPINESS="10"
|
||||||
SYSCTLCONF="/etc/sysctl.conf"
|
SYSCTLCONF="sysctl.conf"
|
||||||
|
SYSCTLDIR="sysctl.conf.d"
|
||||||
VERSION="0.1.0"
|
VERSION="0.1.0"
|
||||||
BUILDDATE="2018-06-05"
|
BUILDDATE="2018-06-05"
|
||||||
|
|
||||||
@ -98,12 +99,24 @@ function autoSwap(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function swappiness(){
|
function swappiness(){
|
||||||
|
|
||||||
|
|
||||||
echo -e -n "\n${YELLOW}Enter a number for swappiness (0-100)[default=10]: ${NC}"
|
echo -e -n "\n${YELLOW}Enter a number for swappiness (0-100)[default=10]: ${NC}"
|
||||||
read setSwappiness
|
read setSwappiness
|
||||||
|
|
||||||
if [ -z "${setSwappiness}" ];then
|
if [ -z "${setSwappiness}" ];then
|
||||||
echo -e "\n${LCYAN}Setting default (10)\n${NC}"
|
echo -e "\n${LCYAN}Setting default (10)\n${NC}"
|
||||||
echo "vm.swappiness=${SWAPPINESS}" | sudo tee -a /etc/sysctl.conf
|
|
||||||
|
if [ -d "/etc/${SYSCTLDIR}" ];then
|
||||||
|
|
||||||
|
SYSCTLCONF="swappiness.conf"
|
||||||
|
touch /etc/${SYSCTLDIR}/${SYSCTLCONF}
|
||||||
|
echo "vm.swappiness=${SWAPPINESS}" | sudo tee -a /etc/${SYSCTLDIR}/${SYSCTLCONF}
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
echo "vm.swappiness=${SWAPPINESS}" | sudo tee -a /etc/${SYSCTLCONF}
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
elif [[ ! "${setSwappiness}" =~ ^-?[0-9]+$ ]];then
|
elif [[ ! "${setSwappiness}" =~ ^-?[0-9]+$ ]];then
|
||||||
@ -119,9 +132,30 @@ function swappiness(){
|
|||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "vm.swappiness=${setSwappiness}" | sudo tee -a ${SYSCTLCONF}
|
if [ -d "/etc/${SYSCTLDIR}" ];then
|
||||||
SWAPPINESSSET=$(cat ${SYSCTLCONF} | grep vm.swappiness=${setSwappiness})
|
|
||||||
if [ ${SWAPPINESSSET} = "vm.swappiness=${setSwappiness}" ] ;then
|
SYSCTLCONF="swappiness.conf"
|
||||||
|
USINGSYSCTLDIR="true"
|
||||||
|
touch /etc/${SYSCTLDIR}/${SYSCTLCONF}
|
||||||
|
echo "vm.swappiness=${setSwappiness}" > /etc/${SYSCTLDIR}/${SYSCTLCONF}
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
echo "vm.swappiness=${setSwappiness}" >> /etc/${SYSCTLCONF}
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [ "${USINGSYSCTLDIR}" = "true" ];then
|
||||||
|
|
||||||
|
SWAPPINESSSET=$(cat /etc/${SYSCTLDIR}/${SYSCTLCONF} | grep vm.swappiness=${setSwappiness})
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
SWAPPINESSSET=$(cat /etc/${SYSCTLCONF} | grep vm.swappiness=${setSwappiness})
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ${SWAPPINESSSET} = "vm.swappiness=${setSwappiness}" ]] ;then
|
||||||
echo -e "${LGREEN}Swappiness value set successfully!\n${NC}"
|
echo -e "${LGREEN}Swappiness value set successfully!\n${NC}"
|
||||||
else
|
else
|
||||||
echo -e "${LRED}Swappiness not set sucessfully...\n${NC}"
|
echo -e "${LRED}Swappiness not set sucessfully...\n${NC}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user