Method: Promotion::Enforcer#start
- Defined in:
- lib/promotion/enforcer.rb
#start ⇒ Object
Enforces the conditions needed for the selected app to function properly, as specified in the deployment descriptor:
-
ensure that certain groups exist
-
ensure that certain users exist (belonging to certain groups)
-
ensure that certain folders exist, if not create them; set permissions correctly; if desired, make sure they are empty
-
move specified files into place, set ownerships and permissions; create empty, or make empty, or preserve contents as desired.
-
ensure symbolic link exists, create if missing
-
create a zip archive of certain files if desired.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/promotion/enforcer.rb', line 56 def start() @spec.elements.each("/Specification/Groups/Group") { |group| gid = group.attributes["Gid"].to_i name = group.attributes["Name"] create_group(gid, name) unless group_exist?(gid, name) } @spec.elements.each("/Specification/Users/User") { |user| uid = user.attributes["Uid"].to_i name = user.attributes["Name"] gid = user.attributes["Gid"].to_i uclass = user.attributes["Class"] || "default" gecos = user.attributes["Gecos"] || "" home = user.attributes["Home"] || "/home/#{name}" shell = user.attributes["Shell"] || "/bin/ksh" groups = user.attributes["Groups"] || "" groups = groups.gsub(/\s+/, ",") # adduser needs comma-separated groups create_user(uid, name, gid, uclass, gecos, home, shell, groups) unless user_exist?(uid, name) } @spec.elements.each("/Specification/Folders/Folder[@Clear='true']") { |folder| path = folder.text().strip() clear_folder(path) } @spec.elements.each("/Specification/Folders/Folder") { |folder| path = folder.text().strip() owner = folder.attributes["Owner"] || folder.parent.attributes["Owner"] || DEFAULT_FOLDER_OWNER group = folder.attributes["Group"] || folder.parent.attributes["Group"] || DEFAULT_FOLDER_GROUP mode = folder.attributes["Mode"] || folder.parent.attributes["Mode"] || DEFAULT_FOLDER_MODE clear = folder.attributes["Clear"] || folder.parent.attributes["Clear"] || DEFAULT_FOLDER_MODE mode = mode.oct() clear = (clear == "true") ensure_folder(path, owner, group, mode, clear) } @spec.elements.each("/Specification/Files/File") { |file| path = file.text().strip() owner = file.attributes["Owner"] || file.parent.attributes["Owner"] || DEFAULT_FILE_OWNER group = file.attributes["Group"] || file.parent.attributes["Group"] || DEFAULT_FILE_GROUP mode = file.attributes["Mode"] || file.parent.attributes["Mode"] || DEFAULT_FILE_MODE mode = mode.oct() source = file.attributes["Source"] || file.parent.attributes["Source"] || DEFAULT_FILE_SOURCE empty = file.attributes["Empty"] == "true" overwrite = !(file.attributes["Overwrite"] == "false") backup = file.attributes["Backup"] == "true" ensure_file(path, owner, group, mode, source, empty, overwrite, backup) } @spec.elements.each("/Specification/Files/Link") { |link| path = link.text().strip() owner = link.attributes["Owner"] || link.parent.attributes["Owner"] || DEFAULT_FILE_OWNER group = link.attributes["Group"] || link.parent.attributes["Group"] || DEFAULT_FILE_GROUP mode = link.attributes["Mode"] || link.parent.attributes["Mode"] || DEFAULT_FILE_MODE mode = mode.oct() target = link.attributes["Target"] || link.parent.attributes["Source"] || DEFAULT_FILE_SOURCE ensure_link(path, owner, group, mode, target) } @spec.elements.each("/Specification/Allfiles") { |file| path = file.text().strip() owner = file.attributes["Owner"] || file.parent.attributes["Owner"] || DEFAULT_FILE_OWNER group = file.attributes["Group"] || file.parent.attributes["Group"] || DEFAULT_FILE_GROUP mode = file.attributes["Mode"] || file.parent.attributes["Mode"] || DEFAULT_FILE_MODE mode = mode.oct() source = file.attributes["Source"] || file.parent.attributes["Source"] || DEFAULT_FILE_SOURCE ensure_allfiles(path, owner, group, mode, source) } @spec.elements.each("/Specification/Subversion") { |svn| folder = svn.elements["Folder"].text url = svn.elements["Url"].text svn_check_out(url, folder) } @spec.elements.each("/Specification/Zipfile") { |zipfile| build_zip_file(zipfile) } end |