1#!/bin/sh 2# 3# $FreeBSD: src/etc/rc.d/localdaemons,v 1.2 2003/05/05 15:38:41 mtm Exp $ 4# 5 6# PROVIDE: localdaemons 7# BEFORE: securelevel 8# KEYWORD: shutdown 9 10. /etc/rc.subr 11 12name="localdaemons" 13start_cmd="locald_start" 14stop_cmd="locald_stop" 15 16# Returns true (0) if the passed argument is a valid name 17# for a script, false (1) otherwise. 18# 19valid_scriptname() 20{ 21 case ${1##*.} in 22 orig) 23 return 1 24 ;; 25 sample) 26 return 1 27 ;; 28 dist) 29 return 1 30 ;; 31 esac 32 return 0 33} 34 35locald_start() 36{ 37 # For each dir in $local_startup, search for init scripts matching * 38 # 39 case ${local_startup} in 40 [Nn][Oo] | '') 41 ;; 42 *) 43 echo -n 'Local package initialization:' 44 slist="" 45 if [ -z "${script_name_sep}" ]; then 46 script_name_sep=" " 47 fi 48 for dir in ${local_startup}; do 49 if [ -d "${dir}" ]; then 50 for script in ${dir}/*; do 51 if valid_scriptname ${script}; then 52 slist="${slist}${script_name_sep}${script}" 53 fi 54 done 55 fi 56 done 57 script_save_sep="$IFS" 58 IFS="${script_name_sep}" 59 sortedslist=`rcorder -s nostart /etc/rc.d/* ${slist} 2>/dev/null | grep -v "^/etc/rc.d/" | tr '\n' "$IFS"`; 60 for script in ${sortedslist}; do 61 if [ -x "${script}" ]; then 62 (set -T 63 trap 'exit 1' 2 64 ${script} start) 65 elif [ -f "${script}" -o -L "${script}" ]; then 66 echo -n " (skipping ${script##*/}, not executable)" 67 fi 68 done 69 IFS="${script_save_sep}" 70 echo '.' 71 ;; 72 esac 73} 74 75locald_stop() 76{ 77 echo -n 'Shutting down daemon processes:' 78 79 # For each dir in $local_startup, search for init scripts matching * 80 case ${local_startup} in 81 [Nn][Oo] | '') 82 ;; 83 *) 84 slist="" 85 if [ -z "${script_name_sep}" ]; then 86 script_name_sep=" " 87 fi 88 for dir in ${local_startup}; do 89 if [ -d "${dir}" ]; then 90 for script in ${dir}/*; do 91 if valid_scriptname ${script}; then 92 slist="${slist}${script_name_sep}${script}" 93 fi 94 done 95 fi 96 done 97 script_save_sep="$IFS" 98 IFS="${script_name_sep}" 99 sortedslist=`rcorder -s nostart /etc/rc.d/* ${slist} 2>/dev/null | grep -v "^/etc/rc.d/" | tr '\n' "$IFS"`; 100 for script in `reverse_list ${sortedslist}`; do 101 if [ -x "${script}" ]; then 102 (set -T 103 trap 'exit 1' 2 104 ${script} stop) 105 fi 106 done 107 IFS="${script_save_sep}" 108 echo '.' 109 ;; 110 esac 111} 112 113load_rc_config $name 114run_rc_command "$1" 115