1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2017 OpenWrt.org
11 DEFAULT
=/etc
/default
/$FS
12 LOGGER
="/usr/bin/logger -p user.err -s -t $FS"
16 [ -f $DEFAULT ] && .
$DEFAULT
18 fs_user
="${FS_USER:-$FS}"
19 fs_group
="${FS_GROUP:-$FS}"
22 fs_dir_localstate
="/var/lib/$FS"
23 fs_dir_run
="/var/run/$FS"
25 fs_dir_cache
="${FS_DIR_CACHE:-/tmp/$FS/cache}"
26 fs_dir_db
="${FS_DIR_DB:-/tmp/$FS/db}"
27 fs_dir_log
="${FS_DIR_LOG:-/tmp/$FS/log}"
28 fs_dir_recordings
="${FS_DIR_RECORDINGS:-/tmp/$FS/recordings}"
29 fs_dir_storage
="${FS_DIR_STORAGE:-/tmp/$FS/storage}"
30 fs_dir_temp
="${FS_DIR_TEMP:-/tmp/$FS/temp}"
35 if [ -f "/etc/${FS}_disabled" ]; then
36 $LOGGER File
\"/etc
/${FS}_disabled
\" exists
37 $LOGGER Remove it once your configuration is
set up
41 for dir
in "$fs_dir_cache" "$fs_dir_db" "$fs_dir_localstate" \
42 "$fs_dir_log" "$fs_dir_recordings" "$fs_dir_run" "$fs_dir_storage" \
47 chown
"$fs_user":"$fs_group" "$dir"
52 #[ -d "$fs_dir_etc" ] && {
53 # find "$fs_dir_etc" -type f -exec chown root:"$fs_group" {} \;
54 # find "$fs_dir_etc" -type f -exec chmod 640 {} \;
58 # starting with full path seems cleaner judging by 'ps' output
59 procd_set_param
command /usr
/bin
/$FS
60 # need to specify all or none of -conf, -log, and -db
61 procd_append_param
command -cache "$fs_dir_cache" -conf \
62 "$fs_dir_etc" -db "$fs_dir_db" -log "$fs_dir_log" -recordings \
63 "$fs_dir_recordings" -run "$fs_dir_run" -storage "$fs_dir_storage" \
65 procd_append_param
command -c
66 # -nc -nf: workaround for interop issue (which causes high load)
67 #procd_append_param command -nc -nf
68 procd_append_param
command $OPTIONS
69 procd_set_param user
"$fs_user"
70 # forward stdout of the command to logd
71 #procd_set_param stdout 1
73 procd_set_param stderr
1
80 local timeout
=$TIMEOUT
82 pgrep
$FS &> /dev
/null
83 [ $?
-ne 0 ] && exit 0
85 [ -f "$fs_dir_run"/${FS}.pid
]
88 # init script could find itself in a scenario where FS was started
89 # very recently, so make it wait a while for a pid file to appear
90 while [ $retval -ne 0 -a $timeout -gt 0 ]; do
92 [ -f "$fs_dir_run"/${FS}.pid
]
94 timeout
=$
(($timeout-1))
97 [ $retval -eq 0 ] ||
{
98 $LOGGER PID
file does not exist
102 mypid
=$
(cat "$fs_dir_run"/${FS}.pid
)
104 [ "$mypid" -gt 1 ] 2> /dev
/null ||
{
105 $LOGGER PID
file contains garbage
111 pgrep
$FS |
grep -w $mypid &>/dev
/null
114 while [ $retval -eq 0 -a $timeout -gt 0 ]; do
116 pgrep
$FS |
grep -w $mypid &>/dev
/null
118 [ $retval -eq 0 ] && kill $mypid 2>/dev
/null
119 timeout
=$
(($timeout-10))
122 [ $retval -ne 1 ] && {
123 $LOGGER Failed to stop
$FS