source: package_branches/invirt-base/hvirt/files/lib/init/config-init.sh @ 2754

Last change on this file since 2754 was 1929, checked in by price, 16 years ago

document config-init.sh better

File size: 1.2 KB
Line 
1# For a package which only configures another, "parent" package.
2#
3# Usage:
4#   PACKAGE=short-name
5#   GEN_FILES=(files to generate)
6#   PARENTPACKAGE=(parent-package another-parent-package)
7#   . /lib/init/config-init.sh
8#   config_init "$1"
9#
10# PACKAGE       - name to appear in log message
11# GEN_FILES     - files to be generated with gen-files.sh
12# PARENTPACKAGE - packages to receive start, etc, commands passed through
13#
14# Global variables GEN_FILES, PARENTPACKAGE may be unset for zero
15# values, or scalars for one.  If run under sh, they cannot be arrays.
16
17. /lib/init/vars.sh
18. /lib/lsb/init-functions
19. /lib/init/gen-files.sh
20
21if [ $BASH_VERSION ]; then
22  handle_parents () {
23    for p in "${PARENTPACKAGE[@]}"; do
24      invoke-rc.d "$p" "$1"
25    done
26  }
27else
28  handle_parents () {
29    if [ -n "$PARENTPACKAGE" ]; then
30      invoke-rc.d "$PARENTPACKAGE" "$1"
31    fi
32  }
33fi
34
35config_init () {
36  case "$1" in
37    start|reload|force-reload|restart)
38      log_begin_msg "Reloading config for $PACKAGE"
39      gen_files
40      log_end_msg $?
41      handle_parents "$1"
42      ;;
43    stop)
44      handle_parents "$1"
45      ;;
46    *)
47      log_success_msg "Usage: /etc/init.d/$PACKAGE {start|reload|force-reload|restart|stop}"
48      ;;
49  esac
50}
Note: See TracBrowser for help on using the repository browser.