1 #!/bin/sh /etc/rc.common
3 # Copyright (C) 2014-2017 - Eloi Carbo
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Extra Service Function to get the Status of the Service
20 # This complements /etc/rc.common functions
21 # Commands ending with *_quiet are meant to be ran in Luci. These
22 # scripts' return minimal output.
23 EXTRA_COMMANDS
="status start_quiet stop_quiet restart_quiet status_quiet"
24 EXTRA_HELP
=" status Returns service status"
27 BIRD_CONFIG
="/etc/${BIRD}.conf"
28 BIRD_LOG
="/var/log/${BIRD}.log"
29 BIRD_ERR
="/tmp/${BIRD}.err"
36 SERVICE_PID_FILE
="/var/run/${BIRD}.pid"
38 BIRD_BIN
="/usr/sbin/${BIRD}"
39 # Special non-terminal-rich output for Luci calls
42 .
/etc
/${BIRD}/init.d
/${BIRD}-lib.sh
47 get use_UCI_config
'bird'
50 if [ "${LUCI}" == "false" ]; then
51 echo "Starting ${BIRD} Service [ ... ]"
53 if [ -f ${BIRD_ERR} ]; then
59 if [ -z "${use_UCI_config}" -o "${use_UCI_config}" = "0" ]; then
60 # Disable Custom bird-openwrt settings.
61 # Use default behaviour and files
62 ${BIRD_BIN} -d -c ${BIRD_CONFIG} -P ${SERVICE_PID_FILE} -D ${BIRD_LOG} &> ${BIRD_ERR} &
64 #Set Bird6 configuration location:
67 get UCI_config_file
'bird'
69 BIRD_CONFIG
="${UCI_config_file:-$BIRD_CONFIG}"
70 BIRD_LOG
="${log_file:-$BIRD_LOG}"
71 #Backup previous configuration
72 [ -f ${BIRD_CONFIG} ] && cp ${BIRD_CONFIG} ${BIRD_CONFIG}.bak
73 #Setup the basic configuration
74 prepare_global
'global'
76 # Gather and set all Functions
78 # Gather and set all Filters
81 # Setup Main Protocols
82 config_foreach prepare_kernel
'kernel'
83 config_foreach prepare_static
'static'
84 config_foreach prepare_device
'device'
85 config_foreach prepare_direct
'direct'
86 config_foreach prepare_pipe
'pipe'
88 #Setup protocol's configuration: BGP
89 config_foreach prepare_bgp_template
'bgp_template'
90 config_foreach prepare_bgp
'bgp'
92 #Setup protocol's configuration: OSPF
93 #config_foreach prepare_ospf_instance 'ospf'
96 ${BIRD_BIN} -d -c ${BIRD_CONFIG} -P ${SERVICE_PID_FILE} -D ${BIRD_LOG} &>${BIRD_ERR} &
98 while [ ! -s ${SERVICE_PID_FILE} ]; do
100 if [ -s ${BIRD_ERR} ]; then
101 if [ "${LUCI}" == "false" ]; then
102 echo -e "${BIRD} Daemon Start Status: \033[0;31m[ FAILED ]\e[m"
104 cat ${BIRD_ERR} >> ${BIRD_LOG}
106 echo "${BIRD} - Failed: $(cat ${BIRD_ERR})"
107 cat ${BIRD_ERR} >> ${BIRD_LOG}
113 if [ -s ${SERVICE_PID_FILE} ]; then
114 if [ -s ${BIRD_ERR} ]; then
115 if [ "${LUCI}" == "false" ]; then
116 echo -e "${BIRD} Daemon already started. Status \033[0;32m[ RUNNING ]\e[m"
118 echo "${BIRD} already started"
121 if [ "${LUCI}" == "false" ]; then
122 echo -e "${BIRD} Daemon Start Status: \033[0;32m[ STARTED ]\e[m"
124 echo "${BIRD} - Started"
127 # PID File found (service started correctly)
131 # PID File not found (error while starting service)
136 if [ -s ${SERVICE_PID_FILE} ]; then
139 get log_file
'global'
140 BIRD_LOG
="${log_file:-$BIRD_LOG}"
141 start-stop-daemon
-p ${SERVICE_PID_FILE} -K 2>&1 >> ${BIRD_LOG}
142 if [ $?
-eq 0 ]; then
143 if [ "${LUCI}" == "false" ]; then
144 echo -e "${BIRD} Daemon Stop Status: \033[0;32m[ OK ]\e[m"
146 echo "${BIRD} - Stopped"
149 if [ "${LUCI}" == "false" ]; then
150 echo -e "${BIRD} Daemon Stop Status: \033[0;31m[ FAILED ]\e[m"
151 echo "Check ${BIRD_LOG} file for more information."
153 echo "${BIRD} Failed to Stop. See Log file: ${BIRD_LOG}"
157 if [ "${LUCI}" == "false" ]; then
158 echo -e "${BIRD} Daemon Service already stopped. \033[0;31m[ FAILED ]\e[m"
160 echo "${BIRD} already stopped"
169 if [ "${LUCI}" == "true" ]; then
176 service_reload
${BIRD_BIN}
180 if [ -s ${SERVICE_PID_FILE} ]; then
181 if [ "${LUCI}" == "false" ]; then
182 echo -e "${BIRD} start status: \033[0;32m[ RUNNING ]\e[m"
184 echo "${BIRD}: Running"
188 if [ -s ${BIRD_ERR} ]; then
189 if [ "${LUCI}" == "false" ]; then
190 echo -e "${BIRD} service status: \033[0;31m[ STOPPED ]\e[m"
193 echo "${BIRD}: Failed - $(cat ${BIRD_ERR})"
197 if [ "${LUCI}" == "false" ]; then
198 echo -e "${BIRD} service status: \033[0;31m[ STOPPED ]\e[m"
200 echo "${BIRD}: Stopped"
207 # Luci-specific calls (stripped output).
208 # The following scripts are not meant to be ran using Ash Terminal
209 # Used in: LUCI/model/cbi/bird6/status.lua