Root/package/base-files/files/etc/rc.common

1#!/bin/sh
2# Copyright (C) 2006-2011 OpenWrt.org
3
4. $IPKG_INSTROOT/etc/functions.sh
5
6initscript=$1
7action=${2:-help}
8shift 2
9
10start() {
11    return 0
12}
13
14stop() {
15    return 0
16}
17
18reload() {
19    return 1
20}
21
22restart() {
23    trap '' TERM
24    stop "$@"
25    start "$@"
26}
27
28boot() {
29    start "$@"
30}
31
32shutdown() {
33    stop
34}
35
36disable() {
37    name="$(basename "${initscript}")"
38    rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
39    rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
40}
41
42enable() {
43    name="$(basename "${initscript}")"
44    disable
45    [ -n "$START" -o -n "$STOP" ] || {
46        echo "/etc/init.d/$name does not have a START or STOP value"
47        return 1
48    }
49    [ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
50    [ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
51}
52
53enabled() {
54    name="$(basename "${initscript}")"
55    [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
56}
57
58depends() {
59    return 0
60}
61
62help() {
63    cat <<EOF
64Syntax: $initscript [command]
65
66Available commands:
67    start Start the service
68    stop Stop the service
69    restart Restart the service
70    reload Reload configuration files (or restart if that fails)
71    enable Enable service autostart
72    disable Disable service autostart
73$EXTRA_HELP
74EOF
75}
76
77. "$initscript"
78
79ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
80list_contains ALL_COMMANDS "$action" || action=help
81[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
82$action "$@"
83

Archive Download this file



interactive