Skip to content

Commit

Permalink
fix service status
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberAndi committed Dec 14, 2023
1 parent a043742 commit 625b176
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions openWRT_install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,135 @@ iptables_inst=$(opkg list-installed | grep iptable)

function service_State() {

if [ ! -z $2 ]
then
#echo $1' ' $2': '
if [ ! -z $1 ]
then
serviceInst=$(opkg list-installed | grep $1)
if [ "$serviceInst" != "" ]
then
if [ -z $(echo $(/etc/init.d/"$1" status) | grep 'not found') ]
then
echo $(/etc/init.d/"$1" status) 2>/dev/null
if [ $(/etc/init.d/"$1" status) != "inactive" ] ; then

case $2 in
"restart")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" restart)
wait $erg 2>/dev/null
fi;;
"start")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" start)
wait $erg 2>/dev/null
fi;;
"stop")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" stop)
wait $erg 2>/dev/null
fi;;
"enable")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" enable)
wait $erg 2>/dev/null
fi;;
"disable")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" disable)
wait $erg 2>/dev/null
fi;;
"inactive")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" stop)
wait $erg 2>/dev/null
erg=""
erg=$(/etc/init.d/"$1" disable)
wait $erg 2>/dev/null
fi;;
*)
echo "false state!"
esac

else
case $2 in
"restart")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" restart)
wait $erg 2>/dev/null
fi;;
"start")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" start)
wait $erg 2>/dev/null
fi;;
"enable")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" enable)
wait $erg 2>/dev/null
fi;;
"disable")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" disable)
wait $erg 2>/dev/null
fi;;
"inactive")
if [ $2 != $(/etc/init.d/"$1" status) ]
then
erg=""
erg=$(/etc/init.d/"$1" stop)
wait $erg 2>/dev/null
erg=""
erg=$(/etc/init.d/"$1" disable)
wait $erg 2>/dev/null
fi;;
*)
echo "false state!"
esac
fi

fi

fi
fi
elif [ ! -z $1 ]
then
serviceInst=$(opkg list-installed | grep $1 )
if [ "$serviceInst" != "" ]
then
if [ -z $(echo $(/etc/init.d/"$1" status) | grep 'not found') ]
then
echo $(/etc/init.d/"$1" status) 2>/dev/null

fi
fi
fi
}


function service_State_old() {

if [ ! -z $2 ]
then
#echo $1' ' $2': '
Expand Down

0 comments on commit 625b176

Please sign in to comment.