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"
17 [ -f $DEFAULT ] && .
$DEFAULT
19 fs_user
="${FS_USER:-$FS}"
20 fs_group
="${FS_GROUP:-$FS}"
23 fs_dir_localstate
="/var/lib/$FS"
24 fs_dir_run
="/var/run/$FS"
26 fs_dir_cache
="${FS_DIR_CACHE:-/tmp/$FS/cache}"
27 fs_dir_db
="${FS_DIR_DB:-/tmp/$FS/db}"
28 fs_dir_log
="${FS_DIR_LOG:-/tmp/$FS/log}"
29 fs_dir_recordings
="${FS_DIR_RECORDINGS:-/tmp/$FS/recordings}"
30 fs_dir_storage
="${FS_DIR_STORAGE:-/tmp/$FS/storage}"
31 fs_dir_temp
="${FS_DIR_TEMP:-/tmp/$FS/temp}"
36 if [ -f "/etc/${FS}_disabled" ]; then
37 $LOGGER File
\"/etc
/${FS}_disabled
\" exists
38 $LOGGER Remove it once your configuration is
set up
42 for dir
in "$fs_dir_cache" "$fs_dir_db" "$fs_dir_localstate" \
43 "$fs_dir_log" "$fs_dir_recordings" "$fs_dir_run" "$fs_dir_storage" \
48 chown
"$fs_user":"$fs_group" "$dir"
53 #[ -d "$fs_dir_etc" ] && {
54 # find "$fs_dir_etc" -type f -exec chown root:"$fs_group" {} \;
55 # find "$fs_dir_etc" -type f -exec chmod 640 {} \;
59 # starting with full path seems cleaner judging by 'ps' output
60 procd_set_param
command $PROG
61 # need to specify all or none of -conf, -log, and -db
62 procd_append_param
command \
63 -cache "$fs_dir_cache" \
68 -recordings "$fs_dir_recordings" \
70 -storage "$fs_dir_storage" \
71 -temp "$fs_dir_temp" \
76 # forward stderr to logd
77 procd_set_param stderr
1
84 local timeout
=$TIMEOUT
86 pgrep
$FS &> /dev
/null
87 [ $?
-ne 0 ] && exit 0
89 [ -f "$fs_dir_run"/${FS}.pid
]
92 # init script could find itself in a scenario where FS was started
93 # very recently, so make it wait a while for a pid file to appear
94 while [ $retval -ne 0 -a $timeout -gt 0 ]; do
96 [ -f "$fs_dir_run"/${FS}.pid
]
98 timeout
=$
(($timeout-1))
101 [ $retval -eq 0 ] ||
{
102 $LOGGER PID
file does not exist
106 mypid
=$
(cat "$fs_dir_run"/${FS}.pid
)
108 [ "$mypid" -gt 1 ] 2> /dev
/null ||
{
109 $LOGGER PID
file contains garbage
114 kill $mypid 2>/dev
/null
115 pgrep
$FS |
grep -w $mypid &>/dev
/null
118 while [ $retval -eq 0 -a $timeout -gt 0 ]; do
120 pgrep
$FS |
grep -w $mypid &>/dev
/null
122 [ $retval -eq 0 ] && kill $mypid 2>/dev
/null
123 timeout
=$
(($timeout-10))
126 [ $retval -ne 1 ] && {
127 $LOGGER Failed to stop
$FS