freeswitch-stable: cleanup init script
- clean up variable names - add options to uci config to enable/disable logging - remove option change_perm as it's hacky - change check before mkdir and friends to prevent overwriting/chown/chmod of existing files/directories (important) Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
This commit is contained in:
parent
92bdfa634d
commit
84bf41e139
2 changed files with 53 additions and 53 deletions
|
@ -3,8 +3,9 @@ config freeswitch 'general'
|
||||||
option enabled '0'
|
option enabled '0'
|
||||||
option user 'freeswitch'
|
option user 'freeswitch'
|
||||||
option group 'freeswitch'
|
option group 'freeswitch'
|
||||||
|
option log_stderr '1'
|
||||||
|
option log_stdout '1'
|
||||||
option options '-nonat -np'
|
option options '-nonat -np'
|
||||||
option change_perm '0'
|
|
||||||
|
|
||||||
config freeswitch 'directories'
|
config freeswitch 'directories'
|
||||||
option cache '/tmp/freeswitch/cache'
|
option cache '/tmp/freeswitch/cache'
|
||||||
|
|
|
@ -7,89 +7,88 @@ USE_PROCD=1
|
||||||
|
|
||||||
#PROCD_DEBUG=1
|
#PROCD_DEBUG=1
|
||||||
|
|
||||||
FS=freeswitch
|
NAME=freeswitch
|
||||||
LOGGER="/usr/bin/logger -p user.err -s -t $FS"
|
COMMAND=/usr/bin/$NAME
|
||||||
|
|
||||||
# used in both start_service() and stop_service()
|
LOGGER="/usr/bin/logger -p user.err -s -t $NAME"
|
||||||
fs_dir_run=/var/run/$FS
|
|
||||||
|
|
||||||
start_service() {
|
start_service() {
|
||||||
local change_perm
|
|
||||||
local dir
|
local dir
|
||||||
local enabled
|
local enabled
|
||||||
|
|
||||||
local fs_user
|
local user
|
||||||
local fs_group
|
local group
|
||||||
|
|
||||||
local fs_dir_cache
|
local log_stderr
|
||||||
local fs_dir_db
|
local log_stdout
|
||||||
local fs_dir_etc=/etc/$FS
|
|
||||||
local fs_dir_localstate=/var/lib/$FS
|
|
||||||
local fs_dir_log
|
|
||||||
local fs_dir_recordings
|
|
||||||
local fs_dir_storage
|
|
||||||
local fs_dir_temp
|
|
||||||
|
|
||||||
local OPTIONS
|
local dir_cache
|
||||||
|
local dir_db
|
||||||
|
local dir_etc=/etc/$NAME
|
||||||
|
local dir_localstate=/var/lib/$NAME
|
||||||
|
local dir_log
|
||||||
|
local dir_recordings
|
||||||
|
local dir_run=/var/run/$NAME
|
||||||
|
local dir_storage
|
||||||
|
local dir_temp
|
||||||
|
|
||||||
local PROG=/usr/bin/$FS
|
local options
|
||||||
|
|
||||||
config_load $FS
|
config_load $NAME
|
||||||
|
|
||||||
config_get_bool enabled general enabled 0
|
config_get_bool enabled general enabled 0
|
||||||
if [ $enabled -eq 0 ]; then
|
if [ $enabled -eq 0 ]; then
|
||||||
$LOGGER service not enabled in /etc/config/$FS
|
$LOGGER service not enabled in /etc/config/$NAME
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
config_get fs_user general user $FS
|
config_get user general user $NAME
|
||||||
config_get fs_group general group $FS
|
config_get group general group $NAME
|
||||||
|
|
||||||
config_get fs_dir_cache directories cache /tmp/$FS/cache
|
config_get_bool log_stderr general log_stderr 1
|
||||||
config_get fs_dir_db directories db /tmp/$FS/db
|
config_get_bool log_stdout general log_stdout 1
|
||||||
config_get fs_dir_log directories log /tmp/$FS/log
|
|
||||||
config_get fs_dir_recordings directories recordings /tmp/$FS/recordings
|
|
||||||
config_get fs_dir_storage directories storage /tmp/$FS/storage
|
|
||||||
config_get fs_dir_temp directories temp /tmp/$FS/temp
|
|
||||||
|
|
||||||
for dir in "$fs_dir_cache" "$fs_dir_db" "$fs_dir_localstate" \
|
config_get dir_cache directories cache /tmp/$NAME/cache
|
||||||
"$fs_dir_log" "$fs_dir_recordings" "$fs_dir_run" "$fs_dir_storage" \
|
config_get dir_db directories db /tmp/$NAME/db
|
||||||
"$fs_dir_temp"
|
config_get dir_log directories log /tmp/$NAME/log
|
||||||
|
config_get dir_recordings directories recordings /tmp/$NAME/recordings
|
||||||
|
config_get dir_storage directories storage /tmp/$NAME/storage
|
||||||
|
config_get dir_temp directories temp /tmp/$NAME/temp
|
||||||
|
|
||||||
|
for dir in "$dir_cache" "$dir_db" "$dir_localstate" \
|
||||||
|
"$dir_log" "$dir_recordings" "$dir_run" "$dir_storage" \
|
||||||
|
"$dir_temp"
|
||||||
do
|
do
|
||||||
[ -n "$dir" ] && {
|
[ ! -e "$dir" ] && {
|
||||||
mkdir -p "$dir"
|
mkdir -p "$dir"
|
||||||
chown "$fs_user":"$fs_group" "$dir"
|
chown "$user":"$group" "$dir"
|
||||||
chmod 750 "$dir"
|
chmod 750 "$dir"
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
|
||||||
config_get_bool change_perm general change_perm 0
|
config_get options general options
|
||||||
[ $change_perm -eq 1 ] && [ -d "$fs_dir_etc" ] && {
|
|
||||||
find "$fs_dir_etc" -type f -exec chown root:"$fs_group" {} \;
|
|
||||||
find "$fs_dir_etc" -type f -exec chmod 640 {} \;
|
|
||||||
}
|
|
||||||
|
|
||||||
config_get OPTIONS general options
|
|
||||||
|
|
||||||
procd_open_instance
|
procd_open_instance
|
||||||
# starting with full path seems cleaner judging by 'ps' output
|
# starting with full path seems cleaner judging by 'ps' output
|
||||||
procd_set_param command $PROG
|
procd_set_param command $COMMAND
|
||||||
# need to specify all or none of -conf, -log, and -db
|
# need to specify all or none of -conf, -log, and -db
|
||||||
procd_append_param command \
|
procd_append_param command \
|
||||||
-cache "$fs_dir_cache" \
|
-cache "$dir_cache" \
|
||||||
-conf "$fs_dir_etc" \
|
-conf "$dir_etc" \
|
||||||
-db "$fs_dir_db" \
|
-db "$dir_db" \
|
||||||
-g "$fs_group" \
|
-g "$group" \
|
||||||
-log "$fs_dir_log" \
|
-log "$dir_log" \
|
||||||
-recordings "$fs_dir_recordings" \
|
-recordings "$dir_recordings" \
|
||||||
-run "$fs_dir_run" \
|
-run "$dir_run" \
|
||||||
-storage "$fs_dir_storage" \
|
-storage "$dir_storage" \
|
||||||
-temp "$fs_dir_temp" \
|
-temp "$dir_temp" \
|
||||||
-u "$fs_user" \
|
-u "$user" \
|
||||||
$OPTIONS \
|
$options \
|
||||||
-c
|
-c
|
||||||
# forward stderr to logd
|
# forward stderr to logd
|
||||||
procd_set_param stderr 1
|
procd_set_param stderr $log_stderr
|
||||||
|
# same for stdout
|
||||||
|
procd_set_param stdout $log_stdout
|
||||||
procd_close_instance
|
procd_close_instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue