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
54 echo -n "" > ${BIRD_ERR}
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 Bird4 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 # PID & ERROR contents are read from their files to avoid an issue
114 # where if [ -s ${SERVICE_PID_FILE} ] and if [ -s ${BIRD_ERR} ]
115 # fails unless a previous command reads its contents making its
116 # behaviour unreliable.
117 SVC_PID
="$(cat ${SERVICE_PID_FILE})"
118 BRDERR_TXT
="$(cat ${BIRD_ERR})"
119 if [ -n "${SVC_PID}" ]; then
120 if [ -n "${BRDERR_TXT}" ]; then
121 if [ "${LUCI}" == "false" ]; then
122 echo -e "${BIRD} Daemon already started. Status \033[0;32m[ RUNNING ]\e[m"
124 echo "${BIRD} already started"
127 if [ "${LUCI}" == "false" ]; then
128 echo -e "${BIRD} Daemon Start Status: \033[0;32m[ STARTED ]\e[m"
130 echo "${BIRD} - Started"
133 # PID File found (service started correctly)
137 # PID File not found (error while starting service)
142 if [ -s ${SERVICE_PID_FILE} ]; then
145 get log_file
'global'
146 BIRD_LOG
="${log_file:-$BIRD_LOG}"
147 start-stop-daemon
-p ${SERVICE_PID_FILE} -K 2>&1 >> ${BIRD_LOG}
148 if [ $?
-eq 0 ]; then
149 if [ "${LUCI}" == "false" ]; then
150 echo -e "${BIRD} Daemon Stop Status: \033[0;32m[ OK ]\e[m"
152 echo "${BIRD} - Stopped"
154 echo -n "" > ${BIRD_ERR}
156 if [ "${LUCI}" == "false" ]; then
157 echo -e "${BIRD} Daemon Stop Status: \033[0;31m[ FAILED ]\e[m"
158 echo "Check ${BIRD_LOG} file for more information."
160 echo "${BIRD} Failed to Stop. See Log file: ${BIRD_LOG}"
164 if [ "${LUCI}" == "false" ]; then
165 echo -e "${BIRD} Daemon Service already stopped. \033[0;31m[ FAILED ]\e[m"
167 echo "${BIRD} already stopped"
176 if [ "${LUCI}" == "true" ]; then
183 service_reload
${BIRD_BIN}
187 if [ -s ${SERVICE_PID_FILE} ]; then
188 if [ "${LUCI}" == "false" ]; then
189 echo -e "${BIRD} start status: \033[0;32m[ RUNNING ]\e[m"
191 echo "${BIRD}: Running"
195 if [ -s ${BIRD_ERR} ]; then
196 if [ "${LUCI}" == "false" ]; then
197 echo -e "${BIRD} service status: \033[0;31m[ STOPPED ]\e[m"
200 echo "${BIRD}: Failed - $(cat ${BIRD_ERR})"
204 if [ "${LUCI}" == "false" ]; then
205 echo -e "${BIRD} service status: \033[0;31m[ STOPPED ]\e[m"
207 echo "${BIRD}: Stopped"
215 # Luci-specific calls (stripped output).
216 # The following scripts are not meant to be ran using Ash Terminal
217 # Used in: LUCI/model/cbi/bird4/status.lua