author | Danek Duvall <danek.duvall@oracle.com> |
Tue, 13 May 2014 15:55:28 -0600 | |
changeset 1896 | f83e6dde6c3b |
child 1944 | 56ac2df1785b |
permissions | -rw-r--r-- |
1896
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.6 |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
2 |
|
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
3 |
# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
4 |
# |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
6 |
# not use this file except in compliance with the License. You may obtain |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
7 |
# a copy of the License at |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
8 |
# |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
10 |
# |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
13 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
14 |
# License for the specific language governing permissions and limitations |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
15 |
# under the License. |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
16 |
|
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
17 |
import errno |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
18 |
import os |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
19 |
import sys |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
20 |
|
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
21 |
import smf_include |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
22 |
|
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
23 |
rings = { |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
24 |
"account-reaper": ["account", "container", "object"], |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
25 |
"account-replicator": ["account"], |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
26 |
"container-replicator": ["container"], |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
27 |
"container-sync": ["container", "object"], |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
28 |
"container-updater": ["account"], |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
29 |
"object-expirer": ["object"], |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
30 |
"object-replicator": ["object"], |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
31 |
"object-updater": ["container"], |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
32 |
"proxy-server": ["account", "container", "object"] |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
33 |
} |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
34 |
|
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
35 |
def start(): |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
36 |
# All the Swift services do essentially the same thing, so there's no need |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
37 |
# to have different method executables. Just look at the FMRI and run the |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
38 |
# appropriate executable from /usr/lib/swift. |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
39 |
fmri = os.environ["SMF_FMRI"] |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
40 |
exefile = os.path.basename(fmri.split(":")[1]) |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
41 |
exepath = os.path.join("/usr/lib/swift", exefile) |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
42 |
|
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
43 |
# Try to find a config file that matches the executable name (minus the |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
44 |
# leading "swift-". If that fails, try using the -server config file. |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
45 |
cfgfile = "/etc/swift/%s.conf" % exepath.split("-", 1)[1] |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
46 |
if not os.path.isfile(cfgfile): |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
47 |
cfgfile = "/etc/swift/%s-server.conf" % exepath.split("-")[1] |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
48 |
if not os.path.isfile(cfgfile): |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
49 |
print >> sys.stderr, "Missing configuration file" |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
50 |
smf_include.smf_method_exit(smf_include.SMF_EXIT_ERR_CONFIG, |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
51 |
"missing_config", "Missing configuration file") |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
52 |
|
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
53 |
missing_rings = [] |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
54 |
for ring in rings.get(exepath.split("-", 1)[1], ()): |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
55 |
ringfile = "/etc/swift/%s.ring.gz" % ring |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
56 |
if not os.path.isfile(ringfile): |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
57 |
missing_rings.append(ringfile) |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
58 |
if missing_rings: |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
59 |
print >> sys.stderr, "Missing ring(s): " + ", ".join(missing_rings) |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
60 |
smf_include.smf_method_exit(smf_include.SMF_EXIT_ERR_CONFIG, |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
61 |
"missing_ring", |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
62 |
"Missing ring(s): " + ", ".join(missing_rings)) |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
63 |
|
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
64 |
# This is the default recon_cache_path (from the config files) as well as |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
65 |
# the default run_dir (from the code). |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
66 |
try: |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
67 |
os.mkdir("/var/run/swift") |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
68 |
except OSError as e: |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
69 |
if e.errno != errno.EEXIST: |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
70 |
raise |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
71 |
|
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
72 |
smf_include.smf_subprocess("%s %s" % (exepath, cfgfile)) |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
73 |
|
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
74 |
if __name__ == "__main__": |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
75 |
os.putenv("LC_ALL", "C") |
f83e6dde6c3b
18551677 Request to integrate Swift into userland
Danek Duvall <danek.duvall@oracle.com>
parents:
diff
changeset
|
76 |
smf_include.smf_main() |