diff --git a/usr/lib/init/init-funcs.sh b/usr/lib/init/init-funcs.sh index 003a326..e4b7512 100644 --- a/usr/lib/init/init-funcs.sh +++ b/usr/lib/init/init-funcs.sh @@ -35,13 +35,19 @@ rc() { #--- restart function --- restart() { $0 stop + sleep 1 $0 start } + +reload() { + restart +} #------------------------ #--- help function --- help() { - echo "$0 init script usage: $0 {start|stop|restart|reload}" + echo "$0 init script usage: $0 {start|stop|restart|reload|help}" + exit 1 } #--------------------- @@ -54,3 +60,9 @@ check() { printf "$BBLUE**$BGREEN SUCCESS: $2\n$RESET" } #----------------------------------------------- + +#--- notify func --- +notify() { + printf "$BBLUE**$BYELLOW $1\n$RESET" +} +#------------------- diff --git a/usr/lib/init/services/dnsd.service b/usr/lib/init/services/dnsd.service index fc10bdb..6544bf4 100755 --- a/usr/lib/init/services/dnsd.service +++ b/usr/lib/init/services/dnsd.service @@ -5,21 +5,25 @@ . /usr/lib/init/init-funcs.sh #------------------------------------ +start() { + notify "Starting dnsd" + /usr/bin/dnsd -d -c /etc/dnsd.conf + check $? "start dnsd" + echo $(pgrep dnsd) > /var/run/dnsd.pid + return $? +} + +stop() { + notify "Stopping dnsd" + kill $(cat /var/run/dnsd.pid) + check $? "stop dnsd" + rm /var/run/dnsd.pid &> /dev/null + return $? +} + case "$1" in - start) - printf "$BBLUE**$BYELLOW Starting dnsd\n$RESET" - /usr/bin/dnsd -d -c /etc/dnsd.conf - check $? "start dnsd" - echo $(pgrep dnsd) > /var/run/dnsd.pid - ;; - stop) - printf "$BBLUE**$BYELLOW Stopping dnsd\n$RESET" - kill $(cat /var/run/dnsd.pid) - check $? "stop dnsd" - rm /var/run/dnsd.pid - ;; - restart|reload) - restart + start|stop|restart|reload|help) + "$1" ;; *) help diff --git a/usr/lib/init/services/dnsmasq.service b/usr/lib/init/services/dnsmasq.service index 730c54d..15f64b4 100755 --- a/usr/lib/init/services/dnsmasq.service +++ b/usr/lib/init/services/dnsmasq.service @@ -5,20 +5,24 @@ . /usr/lib/init/init-funcs.sh #------------------------------------ +start() { + notify "Starting dnsmasq" + /usr/bin/dnsmasq --user=dnsmasq --pid-file=/var/run/dnsmasq.pid + check $? "start dnsmasq" + return $? +} + +stop() { + notify "Stopping dnsmasq" + kill $(cat /var/run/dnsmasq.pid) + check $? "stop dnsmasq" + rm /var/run/dnsmasq.pid &> /dev/null + return $? +} + case "$1" in - start) - printf "$BBLUE**$BYELLOW Starting dnsmasq\n$RESET" - /usr/bin/dnsmasq --user=dnsmasq --pid-file=/var/run/dnsmasq.pid - check $? "start dnsmasq" - ;; - stop) - printf "$BBLUE**$BYELLOW Stopping dnsmasq\n$RESET" - kill $(cat /var/run/dnsmasq.pid) - check $? "stop dnsmasq" - rm /var/run/dnsmasq.pid &> /dev/null - ;; - restart|reload) - restart + start|stop|restart|reload|help) + "$1" ;; *) help diff --git a/usr/lib/init/services/ftpd.service b/usr/lib/init/services/ftpd.service index 6f06be7..58341cf 100755 --- a/usr/lib/init/services/ftpd.service +++ b/usr/lib/init/services/ftpd.service @@ -5,21 +5,25 @@ . /usr/lib/init/init-funcs.sh #------------------------------------ +start() { + notify "Starting ftpd" + tcpsvd -vE 0.0.0.0 21 ftpd -w -S -A /srv/ftpd &>/dev/null & + check $? "start ftpd" + echo $(pgrep tcpsvd) > /ar/run/ftpd.pid + return $? +} + +stop() { + notify "Stopping ftpd" + kill $(cat /var/run/ftpd.pid) + check $? "stop ftpd" + rm /var/run/ftpd.pid &> /dev/null + return $? +} + case "$1" in - start) - printf "$BBLUE**$BYELLOW Starting ftpd\n$RESET" - tcpsvd -vE 0.0.0.0 21 ftpd -w -S -A /srv/ftpd &>/dev/null & - check $? "start ftpd" - echo $(pgrep tcpsvd) > /ar/run/ftpd.pid - ;; - stop) - printf "$BBLUE**$BYELLOW Stopping ftpd\n$RESET" - kill $(cat /var/run/ftpd.pid) - check $? "stop ftpd" - rm /var/run/ftpd.pid - ;; - restart|reload) - restart + start|stop|restart|reload|help) + "$1" ;; *) help diff --git a/usr/lib/init/services/hostapd.service b/usr/lib/init/services/hostapd.service new file mode 100755 index 0000000..5bedfc0 --- /dev/null +++ b/usr/lib/init/services/hostapd.service @@ -0,0 +1,40 @@ +#!/bin/sh + +#--- import colors and init-funcs --- +. /usr/lib/init/colors.sh +. /usr/lib/init/init-funcs.sh +#------------------------------------ + +start() { + notify "Starting hostapd" + if [ "$2" = "" ]; then + /usr/bin/hostapd -P /var/run/hostapd.pid /etc/hostapd/hostapd + check $? "start hostapd" + else + /usr/bin/hostapd -P /var/run/hostapd.pid $2 + check $? "start hostapd" + fi + return $? +} + +stop() { + notify "Stopping hostapd" + if [ ! -f /var/run/hostapd.pid ]; then + notify "$RESET[$RED Dnsmasq is not running $RESET]" + exit 1 + fi + kill $(cat /var/run/hostapd.pid) + check $? "stop hostapd" + rm /var/run/hostapd.pid &> /dev/null + return $? +} + +case "$1" in + start|stop|restart|reload|help) + "$1" + ;; + *) + help + ;; +esac +return $? diff --git a/usr/lib/init/services/hostname.service b/usr/lib/init/services/hostname.service index 588fd2d..ad9df44 100755 --- a/usr/lib/init/services/hostname.service +++ b/usr/lib/init/services/hostname.service @@ -5,15 +5,20 @@ . /usr/lib/init/init-funcs.sh #------------------------------------ +start() { + notify "Settin up hostname" + /usr/bin/hosname -F /etc/hostname + check $? "Set up hostname" + return $? +} + +stop() { + return +} + case "$1" in - start) - printf "$BBLUE**$BYELLOW Setting up hostname\n$RESET" - /usr/bin/hosname -F /etc/hostname - check $? "Set up hostname" - ;; - stop) - ;; - restart|reload) + start|stop|restart|reload|help) + "$1" ;; *) help diff --git a/usr/lib/init/services/httpd.service b/usr/lib/init/services/httpd.service index 4e7e539..49e5386 100755 --- a/usr/lib/init/services/httpd.service +++ b/usr/lib/init/services/httpd.service @@ -5,21 +5,25 @@ . /usr/lib/init/init-funcs.sh #------------------------------------ +start() { + otify "Starting httpd" + /usr/bin/httpd -h /srv/www + check $? "start httpd" + echo $(pgrep httpd) > /var/run/httpd.pid + return $? +} + +stop() { + notify "Stopping httpd" + kill $(cat /var/run/httpd.pid) + check $? "stop httpd" + rm /var/run/httpd.pid &> /dev/null + return $? +} + case "$1" in - start) - printf "$BBLUE**$BYELLOW Starting httpd\n$RESET" - /usr/bin/httpd -h /srv/www - check $? "start httpd" - echo $(pgrep httpd) > /var/run/httpd.pid - ;; - stop) - printf "$BBLUE**$BYELLOW Stopping httpd\n$RESET" - kill $(cat /var/run/httpd.pid) - check $? "stop httpd" - rm /var/run/httpd.pid - ;; - restart|reload) - restart + start|stop|restart|reload|help) + "$1" ;; *) help diff --git a/usr/lib/init/services/iptables.service b/usr/lib/init/services/iptables.service new file mode 100755 index 0000000..3e73b43 --- /dev/null +++ b/usr/lib/init/services/iptables.service @@ -0,0 +1,40 @@ +#!/bin/sh + +#--- import colors and init-funcs --- +. /usr/lib/init/colors.sh +. /usr/lib/init/init-funcs.sh +#------------------------------------ + +DAEMON="iptables" +IPTABLES_ARGS="" + +start() { + notify "Starting $DAEMON" + iptables-restore /etc/iptables.conf + check $? "start $DAEMON" + return $? +} + +stop () { + notify "Stopping $DAEMON" + iptables -F + check $? "stop $DAEMON" + return $? +} + +save() { + notify "Saving %s: $DAEMON" + iptables-save -f /etc/iptables.conf + check $? "saving %s: $DAEMON" + return $? +} + +case "$1" in + start|stop|restart|reload|save|help) + "$1" + ;; + *) + help + ;; +esac +return $? diff --git a/usr/lib/init/services/klogd.service b/usr/lib/init/services/klogd.service index 151bb88..0beb098 100755 --- a/usr/lib/init/services/klogd.service +++ b/usr/lib/init/services/klogd.service @@ -5,20 +5,24 @@ . /usr/lib/init/init-funcs.sh #------------------------------------ +start() { + notify "Starting klogd" + /usr/bin/klogd + check $? "start klogd" + return $? +} + +stop() { + notify "Stopping klogd" + kill $(cat /var/run/klogd.pid) + check $? "stop klogd" + rm /var/run/klogd.pid &> /dev/null + return $? +} + case "$1" in - start) - printf "$BBLUE**$BYELLOW Starting klogd\n$RESET" - /usr/bin/klogd - check $? "start klogd" - ;; - stop) - printf "$BBLUE**$BYELLOW Stopping klogd\n$RESET" - kill $(cat /var/run/klogd.pid) - check $? "stop klogd" - rm /var/run/klogd.pid &> /dev/null - ;; - restart|reload) - restart + start|stop|restart|reload|help) + "$1" ;; *) help diff --git a/usr/lib/init/services/networking.service b/usr/lib/init/services/networking.service index e2b39bc..d394f5c 100755 --- a/usr/lib/init/services/networking.service +++ b/usr/lib/init/services/networking.service @@ -5,23 +5,25 @@ . /usr/lib/init/init-funcs.sh #------------------------------------ +start() { + notify "Starting networking" + /usr/bin/ifup -a + check $? "networking" + echo $! > /var/run/networking.pid + return $? +} + +stop() { + notify "Stopping networking" + /usr/bin/ifdown -a + check $? "Stop networking" + rm /var/run/networking.pid &> /dev/null + return $? +} + case "$1" in - start) - printf "$BBLUE**$BYELLOW Starting networking\n$RESET" - /usr/bin/ifup -a - check $? "networking" - echo $! > /var/run/networking.pid - ;; - stop) - printf "$BBLUE**$BYELLOW Stopping netowrking\n$RESET" - /usr/bin/ifdown -a - check $? "Stop networking" - if [ -f /var/run/neworking.pid ]; then - rm /var/run/networking.pid - fi - ;; - restart|reload) - restart + start|stop|restart|reload|help) + "$1" ;; *) help diff --git a/usr/lib/init/services/nginx.service b/usr/lib/init/services/nginx.service new file mode 100755 index 0000000..9c267cd --- /dev/null +++ b/usr/lib/init/services/nginx.service @@ -0,0 +1,32 @@ +#!/bin/sh + +#--- import colors and init-funcs --- +. /usr/lib/init/colors.sh +. /usr/lib/init/init-funcs.sh +#------------------------------------ + +start() { + notify "Starting nginx" + nginx + check $? "start nginx" + echo $(pgrep nginx) > /var/run/nginx.pid + return $? +} + +stop() { + notify "Stopping nginx" + nginx -s stop + check $? "stop nginx" + rm /var/run/nginx.pid &> /dev/null + return $? +} + +case "$1" in + start|stop|restart|reload) + "$1" + ;; + *) + help + ;; +esac +return $? diff --git a/usr/lib/init/services/openrouterinit.service b/usr/lib/init/services/openrouterinit.service new file mode 100644 index 0000000..e453cb2 --- /dev/null +++ b/usr/lib/init/services/openrouterinit.service @@ -0,0 +1,37 @@ +#!/bin/sh + +#--- import colors and init-funcs --- +. /usr/lib/init/colors.sh +. /usr/lib/init/init-funcs.sh +#------------------------------------ + +start() { + notify "Starting openrouter software" + /usr/bin/auth_service &>/dev/null + check $? "start auth_service" + echo $(pgrep auth_service) > /var/run/auth_service.pid + /usr/bin/openrouter &> /dev/null + check $? "start openrouter" + echo $(pgrep openrouter) > /var/run/openrouter.pid + return $? +} + +stop() { + notify "Stopping openrouter software" + kill $(cat /var/run/auth_service.pid) + check $? "stop auth_service" + kill $(cat /var/run/openrouter.pid) + check $? "stop openrouter" + rm /var/run/{auth_service.pid,openrouter.pid} &> /dev/null + return $? +} + +case "$1" in + start|stop|restart|reload|help) + "$1" + ;; + *) + help + ;; +esac +return $? diff --git a/usr/lib/init/services/sshd.service b/usr/lib/init/services/sshd.service new file mode 100755 index 0000000..4698f67 --- /dev/null +++ b/usr/lib/init/services/sshd.service @@ -0,0 +1,32 @@ +#!/bin/sh + +#--- import colors and init-funcs --- +. /usr/lib/init/colors.sh +. /usr/lib/init/init-funcs.sh +#------------------------------------ + +start() { + notify "Starting sshd" + /usr/bin/sshd -D & + check $? "start sshd" + echo $(pgrep sshd) > /var/run/sshd.pid + return $? +} + +stop() { + notify "Stopping sshd" + kill $(cat /var/run/sshd.pid) + check $? "stop sshd" + rm /var/run/sshd.pid &> /dev/null + return $? +} + +case "$1" in + start|stop|restart|reload|help) + "$1" + ;; + *) + help + ;; +esac +return $? diff --git a/usr/lib/init/services/sysctl.service b/usr/lib/init/services/sysctl.service new file mode 100755 index 0000000..596e8b4 --- /dev/null +++ b/usr/lib/init/services/sysctl.service @@ -0,0 +1,27 @@ +#!/bin/sh + +#--- import colors and init-funcs --- +. /usr/lib/init/colors.sh +. /usr/lib/init/init-funcs.sh +#------------------------------------ + +start() { + notify "Setting up sysctl" + sysctl -p & /dev/null + check $? "setting up sysctl" + return $? +} + +stop() { + return +} + +case "$1" in + start|stop|restart|reload|help) + "$1" + ;; + *) + help + ;; +esac +return $? diff --git a/usr/lib/init/services/syslogd.service b/usr/lib/init/services/syslogd.service index 372f0a8..c6c1ddc 100755 --- a/usr/lib/init/services/syslogd.service +++ b/usr/lib/init/services/syslogd.service @@ -5,20 +5,24 @@ . /usr/lib/init/init-funcs.sh #------------------------------------ +start() { + notify "Starting syslogd" + /usr/bin/syslogd + check $? "start syslogd" + return $? +} + +stop() { + notify "Stopping syslogd" + kill $(cat /var/run/syslogd.pid) + check $? "stop syslogd" + rm /var/run/syslogd.pid &> /dev/null + return $? +} + case "$1" in - start) - printf "$BBLUE**$BYELLOW Starting syslogd\n$RESET" - /usr/bin/syslogd - check $? "start syslogd" - ;; - stop) - printf "$BBLUE**$BYELLOW Stopping syslogd\n$RESET" - kill $(cat /var/run/syslogd.pid) - check $? "stop syslogd" - rm /var/run/syslogd.pid &> /dev/null - ;; - restart|reload) - restart + start|stop|restart|reload|help) + "$1" ;; *) help diff --git a/usr/lib/init/services/telnetd.service b/usr/lib/init/services/telnetd.service index bce40f7..cacbd9e 100755 --- a/usr/lib/init/services/telnetd.service +++ b/usr/lib/init/services/telnetd.service @@ -5,21 +5,25 @@ . /usr/lib/init/init-funcs.sh #------------------------------------ +start() { + notify "Starting telnetd" + /usr/bin/telnetd -p 23 + check $? "start telnetd" + echo $(gprep telnetd) > /var/run/telnetd.pid + return $? +} + +stop() { + notify "Stopping telnetd" + kill $(cat /var/run/telnetd.pid) + check $? "stop telnetd" + rm /var/run/telnetd.pid &> /dev/null + return $? +} + case "$1" in - start) - printf "$BBLUE**$BYELLOW Starting telnetd\n$RESET" - /usr/bin/telnetd -p 23 - check $? "start telnetd" - echo $(gprep telnetd) > /var/run/telnetd.pid - ;; - stop) - printf "$BBLUE**$BYELLOW Stopping telnetd\n$RESET" - kill $(cat /var/run/telnetd.pid) - check $? "stop telnetd" - rm /var/run/telnetd.pid &> /dev/null - ;; - restart|reload) - restart + start|stop|restart|reload|help) + "$1" ;; *) help diff --git a/usr/share/rc/orders b/usr/share/rc/orders index 5ae1d73..4076dcd 100644 --- a/usr/share/rc/orders +++ b/usr/share/rc/orders @@ -7,10 +7,10 @@ 07dnsmasq 08dnsd 09telnetd -10ssh +10sshd 11iptables -12openrouterinit -13ftpd -14hostapd -15httpd -16nginx \ No newline at end of file +12ftpd +13hostapd +14httpd +15nginx +16openrouterinit \ No newline at end of file