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

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

Archive Download this file



interactive