Class: Utopia::Command::Server::Update

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/utopia/command/server.rb

Overview

Update a server.

Instance Method Summary collapse

Instance Method Details

#invoke(parent) ⇒ Object



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
# File 'lib/utopia/command/server.rb', line 58

def invoke(parent)
	destination_root = parent.root
	
	Dir.chdir(destination_root) do
		# It's okay to call this on an existing repo, it will only update config as required to enable --shared.
		# --shared allows multiple users to access the site with the same group.
		system("git", "init", "--shared") or fail "could not initialize repository"
		
		system("git", "config", "receive.denyCurrentBranch", "ignore") or fail "could not set configuration"
		system("git", "config", "core.worktree", destination_root) or fail "could not set configuration"
		
		# In theory, to convert from non-shared to shared:
		# chgrp -R <group-name> .                   # Change files and directories' group
		# chmod -R g+w .                            # Change permissions
		# chmod g-w .git/objects/pack/*             # Git pack files should be immutable
		# chmod g+s `find . -type d`                # New files get group id of directory
	end
	
	# Set some useful defaults for the environment.
	environment = Environment[]
	environment.update_environment(destination_root) do |store|
		store['RACK_ENV'] ||= 'production'
		store['DATABASE_ENV'] ||= 'production'
		store['UTOPIA_SESSION_SECRET'] ||= SecureRandom.hex(40)
	end
	
	# Copy git hooks:
	system("cp", "-r", File.join(template_root, 'git', 'hooks'), File.join(destination_root, '.git')) or fail "could not copy git hooks"
	# finally set everything in the .git directory to be group writable
	# This failed for me and I had to do sudo chown http:http .git -R first.
	system("chmod", "-Rf", "g+w", File.join(destination_root, '.git')) or fail "could not update permissions of .git directory"
end

#template_rootObject



53
54
55
56
# File 'lib/utopia/command/server.rb', line 53

def template_root
	# The root directory of the template server deployment:
	File.join(SETUP_ROOT, 'server')
end