~ubuntu-branches/ubuntu/raring/lsb/raring-proposed

« back to all changes in this revision

Viewing changes to install_initd

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lawrence
  • Date: 2002-04-15 02:25:51 UTC
  • Revision ID: james.westby@ubuntu.com-20020415022551-don2tfe0tawo0g44
Tags: 1.1.0-11
Note that Debian's run-parts ignores certain lsb cron.* scripts, in
violation of the LSB specification.  See #118646.
(If necessary, run-parts may be diverted by this package to conform.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import sys, re, os, initdutils
 
4
 
 
5
if len(sys.argv) > 1:
 
6
    initfile = sys.argv[1]
 
7
else:
 
8
    print >> sys.stderr, 'Usage: %s /etc/init.d/<init-script>' % sys.argv[0]
 
9
    sys.exit(1)
 
10
 
 
11
# Default priorities
 
12
startpri = stoppri = 20
 
13
defstart = [2, 3, 4, 5]
 
14
defstop = [0, 1, 6]
 
15
 
 
16
# Priorities of these facilities in Debian
 
17
os_facilities = {
 
18
    "$local_fs" : {'lsb' : (0, 100)},
 
19
    "$network" : {'lsb' : (10, 50)},
 
20
    "$remote_fs" : {'lsb ': (19, 20)},
 
21
    "$named" : {'lsb': (19, 19)},
 
22
    "$syslog" : {'lsb' : (10, 89)},
 
23
    "$netdaemons" : {'lsb': (80, 19)},
 
24
    }
 
25
 
 
26
facilities = initdutils.load_facilities()
 
27
facilities.update(os_facilities)
 
28
 
 
29
headers = initdutils.scan_initfile(initfile)
 
30
 
 
31
reqstart = headers.get('Required-Start', [])
 
32
if reqstart:
 
33
    startpri = 5
 
34
    for facility in reqstart:
 
35
        if not facilities.has_key(facility):
 
36
            print >> sys.stderr, 'Missing expected start facility', facility
 
37
        else:
 
38
            for script, pri in facilities[facility].items():
 
39
                if script != initfile:
 
40
                    start, stop = pri
 
41
                    startpri = max(startpri, start+1)
 
42
    startpri = min(max(startpri, 1), 99)
 
43
 
 
44
reqstop = headers.get('Required-Stop', [])
 
45
if reqstop:
 
46
    stoppri = 95
 
47
    for facility in reqstop:
 
48
        if not facilities.has_key(facility):
 
49
            print >> sys.stderr, 'Missing expected stop facility', facility
 
50
        else:
 
51
            for script, pri in facilities[facility].items():
 
52
                if script != initfile:
 
53
                    start, stop = pri
 
54
                    stoppri = min(stoppri, stop-1)
 
55
    stoppri = min(max(stoppri, 1), 99)
 
56
 
 
57
provides = headers.get('Provides', [])
 
58
if provides:
 
59
    for facility in provides:
 
60
        if facility[0] == '$':
 
61
            print >> sys.stderr, 'Ignoring system-provided facility', facility
 
62
            continue
 
63
        if not facilities.has_key(facility):
 
64
            facilities[facility] = {}
 
65
 
 
66
        facilities[facility][initfile] = (startpri, stoppri)
 
67
    initdutils.save_facilities(facilities)
 
68
 
 
69
defstart = headers.get('Default-Start', defstart)
 
70
defstop = headers.get('Default-Stop', defstop)
 
71
 
 
72
# A set type would be nice... [range(2,6) = 2..5]
 
73
for level in range(2,6):
 
74
    if level in defstart:
 
75
        for i in range(2,6):
 
76
            if i not in defstart:
 
77
                defstart.append(i)
 
78
    if level in defstop:
 
79
        for i in range(2,6):
 
80
            if i not in defstop:
 
81
                defstop.append(i)
 
82
 
 
83
defstart.sort()
 
84
defstop.sort()
 
85
 
 
86
start_runlevels = " ".join(map(str, defstart))
 
87
stop_runlevels = " ".join(map(str, defstop))
 
88
 
 
89
initfile = initfile.replace('/etc/init.d/', '')
 
90
 
 
91
os.system("/usr/sbin/update-rc.d %(initfile)s start %(startpri)d %(start_runlevels)s . stop %(stoppri)d %(stop_runlevels)s ." % locals())