diff --git a/rootfs/etc/init.d/ftp b/rootfs/etc/init.d/ftp index b88c7bf..5cb4f37 100755 --- a/rootfs/etc/init.d/ftp +++ b/rootfs/etc/init.d/ftp @@ -12,7 +12,7 @@ case "$1" in stop) notify "Stopping ftpd " kill $(cat /var/run/ftpd.pid) - killall ftpd + killall ftpd &> /dev/null rm /var/run/ftpd.pid check $? ;; diff --git a/rootfs/etc/init.d/hostapd b/rootfs/etc/init.d/hostapd index 520a38e..282c884 100755 --- a/rootfs/etc/init.d/hostapd +++ b/rootfs/etc/init.d/hostapd @@ -7,9 +7,11 @@ case "$1" in notify "Starting hostapd " if [[ "$2" == "" ]]; then /usr/bin/hostapd -P /var/run/hostapd.pid /etc/hostapd/hostapd + # echo $! > /var/run/hostapd.pid check $? else /usr/bin/hostapd -P /var/run/hostapd.pid $2 + # echo $! > /var/run/hostapd.pid check $? fi ;; diff --git a/rootfs/etc/init.d/http_d b/rootfs/etc/init.d/http_d index dffa684..9ec1d59 100755 --- a/rootfs/etc/init.d/http_d +++ b/rootfs/etc/init.d/http_d @@ -6,13 +6,13 @@ case "$1" in start) notify "Starting httpd " httpd -h /srv/www &> /dev/null + echo $! > /var/run/httpd.pid check $? ;; stop) notify "Stopping httpd " killall httpd - #kill $(cat /var/run/httpd.pid) - #rm /var/run/httpd.pid + rm /var/run/httpd.pid check $? ;; restart|reload) diff --git a/rootfs/etc/init.d/nginx b/rootfs/etc/init.d/nginx index 48bed93..2ae31cc 100755 --- a/rootfs/etc/init.d/nginx +++ b/rootfs/etc/init.d/nginx @@ -6,11 +6,13 @@ case "$1" in start) notify "Starting nginx " nginx + echo $! > /var/run/nginx.pid check $? ;; stop) notify "Stopping nginx " nginx -s stop + rm /var/run/nginx.pid check $? ;; restart|reload) diff --git a/rootfs/etc/init.d/openrouterinit b/rootfs/etc/init.d/openrouterinit index e8f0c32..3990a86 100755 --- a/rootfs/etc/init.d/openrouterinit +++ b/rootfs/etc/init.d/openrouterinit @@ -7,12 +7,14 @@ case "$1" in notify "Starting openrouter software " cd /srv/ftpd/auth_service_router/bin && ./auth_service &> /dev/null & cd /srv/ftpd/openrouter_adminpanel/bin && ./openrouter &> /dev/null & + echo $! > /var/run/openrouterinit.pid check $? ;; stop) notify "Stopping openrouter software " killall openrouter killall auth_service + rm /var/run/openrouterinit.pid check $? ;; restart|reload) diff --git a/rootfs/etc/init.d/ssh b/rootfs/etc/init.d/ssh index 56fc2f4..144c0b2 100755 --- a/rootfs/etc/init.d/ssh +++ b/rootfs/etc/init.d/ssh @@ -6,11 +6,13 @@ case "$1" in start) notify "Starting sshd " /usr/bin/sshd -D & + echo $! > /var/run/ssh.pid check $? ;; stop) notify "Stopping sshd " killall sshd + rm /var/run/ssh.pid check $? ;; restart|reload) diff --git a/rootfs/etc/init.d/telnet b/rootfs/etc/init.d/telnet index fa36120..e638023 100755 --- a/rootfs/etc/init.d/telnet +++ b/rootfs/etc/init.d/telnet @@ -6,11 +6,13 @@ case "$1" in start) notify "Starting telnet " telnetd -S -p $(cat /etc/openrouter/telnet/port) + echo $! > /var/run/telnet.pid check $? ;; stop) notify "Stopping telnet " killall telnetd + rm /var/run/telnet.pid check $? ;; restart|reload) diff --git a/rootfs/usr/bin/rc b/rootfs/usr/bin/rc index 2051df7..37e6bb6 100755 --- a/rootfs/usr/bin/rc +++ b/rootfs/usr/bin/rc @@ -11,7 +11,17 @@ ## ########## ## ########## -rootdir=/Users/anatolijmironcenko/Documents/cpp/openrouter/rootfs +#----- colors ------- +Green='\033[0;32m' +Color_off='\033[0m' +Red='\033[0;31m' +Bred='\033[1;31m' +Yellow='\033[1;33m' +White='\033[0;37m' +Bwhite='\033[1;37m' +#-------------------- + +rootdir=/ #------------------------ add to boot function -------------- add() { @@ -80,6 +90,32 @@ bootlist() { } #------------------------------------------------------------ +#------------------ service status -------------------------- +status() { + if [[ "$1" == "" ]]; then + help + exit 0 + fi + if [[ "$(ls /etc/init.d | grep $1)" == "" ]]; then + printf "$Yellow**$Bred error:$Color_off can't find service /etc/init.d/$1\n" + exit 1 + fi + printf "$Yellow**$Green $1$Color_off\n" + rcdservice=$(ls $rootdir/etc/rc.d | grep $1 2> /dev/null) + if [[ "$rcdservice" == "" ]]; then + printf "Loaded:$Yellow unloaded$Color_off (/etc/rc.d)\n" + else + printf "Loaded:$Green loaded$Color_off (/etc/rc.d/$rcdservice)\n" + fi + servicepid=$(ls $rootdir/var/run | grep $1) + if [[ "$servicepid" == "" ]]; then + printf "Active: deactive (${Yellow}deactive$Color_off)\n" + else + printf "Active: active (${Green}running$Color_off); pid (/var/run/$servicepid)\n" + fi +} +#------------------------------------------------------------ + #-------------- print help function ------------------------- help() { echo " @@ -91,6 +127,7 @@ help() { rc restart [init.d script name] - restart service rc list - list all services rc bootlist - list enabled services + rc status [init.d script name] - check service status examples: rc add httpd @@ -128,6 +165,9 @@ case ${command} in bootlist) bootlist ;; + status) + status $2 + ;; *) help ;;