Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/boto/pyami/installers/ubuntu/installer.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 # Copyright (c) 2006,2007,2008 Mitch Garnaat http://garnaat.org/ | |
2 # | |
3 # Permission is hereby granted, free of charge, to any person obtaining a | |
4 # copy of this software and associated documentation files (the | |
5 # "Software"), to deal in the Software without restriction, including | |
6 # without limitation the rights to use, copy, modify, merge, publish, dis- | |
7 # tribute, sublicense, and/or sell copies of the Software, and to permit | |
8 # persons to whom the Software is furnished to do so, subject to the fol- | |
9 # lowing conditions: | |
10 # | |
11 # The above copyright notice and this permission notice shall be included | |
12 # in all copies or substantial portions of the Software. | |
13 # | |
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | |
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
20 # IN THE SOFTWARE. | |
21 # | |
22 import boto.pyami.installers | |
23 import os | |
24 import os.path | |
25 import stat | |
26 import boto | |
27 import random | |
28 from pwd import getpwnam | |
29 | |
30 class Installer(boto.pyami.installers.Installer): | |
31 """ | |
32 Base Installer class for Ubuntu-based AMI's | |
33 """ | |
34 def add_cron(self, name, command, minute="*", hour="*", mday="*", month="*", wday="*", who="root", env=None): | |
35 """ | |
36 Write a file to /etc/cron.d to schedule a command | |
37 env is a dict containing environment variables you want to set in the file | |
38 name will be used as the name of the file | |
39 """ | |
40 if minute == 'random': | |
41 minute = str(random.randrange(60)) | |
42 if hour == 'random': | |
43 hour = str(random.randrange(24)) | |
44 fp = open('/etc/cron.d/%s' % name, "w") | |
45 if env: | |
46 for key, value in env.items(): | |
47 fp.write('%s=%s\n' % (key, value)) | |
48 fp.write('%s %s %s %s %s %s %s\n' % (minute, hour, mday, month, wday, who, command)) | |
49 fp.close() | |
50 | |
51 def add_init_script(self, file, name): | |
52 """ | |
53 Add this file to the init.d directory | |
54 """ | |
55 f_path = os.path.join("/etc/init.d", name) | |
56 f = open(f_path, "w") | |
57 f.write(file) | |
58 f.close() | |
59 os.chmod(f_path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC) | |
60 self.run("/usr/sbin/update-rc.d %s defaults" % name) | |
61 | |
62 def add_env(self, key, value): | |
63 """ | |
64 Add an environemnt variable | |
65 For Ubuntu, the best place is /etc/environment. Values placed here do | |
66 not need to be exported. | |
67 """ | |
68 boto.log.info('Adding env variable: %s=%s' % (key, value)) | |
69 if not os.path.exists("/etc/environment.orig"): | |
70 self.run('cp /etc/environment /etc/environment.orig', notify=False, exit_on_error=False) | |
71 fp = open('/etc/environment', 'a') | |
72 fp.write('\n%s="%s"' % (key, value)) | |
73 fp.close() | |
74 os.environ[key] = value | |
75 | |
76 def stop(self, service_name): | |
77 self.run('/etc/init.d/%s stop' % service_name) | |
78 | |
79 def start(self, service_name): | |
80 self.run('/etc/init.d/%s start' % service_name) | |
81 | |
82 def create_user(self, user): | |
83 """ | |
84 Create a user on the local system | |
85 """ | |
86 self.run("useradd -m %s" % user) | |
87 usr = getpwnam(user) | |
88 return usr | |
89 | |
90 def install(self): | |
91 """ | |
92 This is the only method you need to override | |
93 """ | |
94 raise NotImplementedError |