Last active
January 1, 2018 08:10
-
-
Save NovapaX/6207082 to your computer and use it in GitHub Desktop.
Files needed to run a rails app in Mac OS X server. (and be able to control it in server.app)
I might write a blog post someday. I generate all these files with some capistrano 'wizard'-style tasks. This is tested for an app running under the root (/) of a virtualhost. Running under a subdirectory should work, but needs some more testing. Server…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo dscl . create "/Groups/org.example.webapp.appname" | |
# find a free group id and use it. (something in the 300 range will hide it from normal user management) | |
sudo dscl . create "/Groups/org.example.webapp.appname" PrimaryGroupID 303 | |
sudo dscl . create "/Groups/org.example.webapp.appname" RealName org.example.webapp.appname | |
sudo dscl . create "/Users/org.example.webapp.appname" | |
# find a free userid | |
sudo dscl . create "/Users/org.example.webapp.appname" UniqueID 303 | |
# use the groupid of the group you just created | |
sudo dscl . create "/Users/org.example.webapp.appname" PrimaryGroupID 303 | |
sudo dscl . create "/Users/org.example.webapp.appname" RealName org.example.webapp.appname | |
sudo dscl . delete "/Users/org.example.webapp.appname" AuthenticationAuthority | |
sudo dscl . create "/Users/org.example.webapp.appname" Password '*' | |
sudo dscl . create "/Users/org.example.webapp.appname" UserShell /bin/bash | |
sudo dscl . create "/Users/org.example.webapp.appname" NFSHomeDirectory /Volumes/Data/Library/Server/Web/Data/Webapps/org.example.webapp.appname/Data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 'Install' the webapp on the server | |
cd /Library/Server/Web/Config/apache2/webapps/ | |
link /Volumes/Data/Library/Server/Web/Data/Webapps/org.example.webapp.appname/Config/org.example.webapp.appname.plist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: /Volumes/Data/Library/Server/Web/Data/Webapps/org.example.webapp.appname/Config/org.example.webapp.appname.conf | |
# This is the httpd configuration that gets included under the virtualhost | |
# directive for which the webapp is enabled in Server.app | |
# modify the [/ or /subdir] part to your needs. When you set it to '/' the entire domain gets proxied to the rails app. | |
Alias [/ or /subdir] /Volumes/Data/Library/Server/Web/Data/Webapps/balancer-group-org.example.webapp.appname/Data/current/public/ | |
BalancerMember balancer://balancer-group-org.example.webapp.appname-/ http://localhost:7303/ | |
XSendFile on | |
XSendFilePath /Volumes/Data/Library/Server/Web/Data/Webapps/balancer-group-org.example.webapp.appname/Data/shared/storage | |
XSendFilePath /Volumes/Data/Library/Server/Web/Data/Webapps/balancer-group-org.example.webapp.appname/Data/shared/public/ | |
#RewriteLog "/var/log/apache2/rewrite.log" | |
#RewriteLogLevel 5 | |
<Directory /Volumes/Data/Library/Server/Web/Data/Webapps/org.example.webapp.appname/Data/current/public > | |
AllowOverride all | |
Allow from all | |
Options -MultiViews -Indexes +FollowSymLinks | |
RewriteEngine On | |
RewriteBase / | |
# Rewrite filename to gzip version if browser accepts it and the file exists. | |
# Gzipped versions are created by the Rails asset pipeline on deploy with asset:precompile | |
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b | |
RewriteCond %{REQUEST_FILENAME}.gz -s | |
RewriteRule (.*\.(js|css))$ $1.gz | |
# Proxy all requests for non-files to the rails application | |
# static files under /public are served by Apache | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^(.*)$ balancer://balancer-group-org.example.webapp.appname-/$1 [P,QSA,L] | |
# Force Type and Content-encoding. Without this it would be application/x-gzip | |
<Files *.css.gz> | |
ForceType text/css | |
Header set Content-Encoding gzip | |
</Files> | |
<Files *.js.gz> | |
ForceType text/javascript | |
Header set Content-Encoding gzip | |
</Files> | |
</Directory> | |
# Set expiration headers for precompiled assets to 'very long' | |
<Location /assets > | |
Header unset ETag | |
FileETag None | |
ExpiresActive On | |
ExpiresDefault "access plus 1 year" | |
</Locatio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: /Volumes/Data/Library/Server/Web/Data/Webapps/org.example.webapp.appname/Config/org.example.webapp.appname.plist | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>displayName</key> | |
<string>ApplicationName, org.example.webapp.appname at /</string> | |
<key>includeFiles</key> | |
<array> | |
<string>/Volumes/Data/Library/Server/Web/Data/Webapps/org.example.webapp.appname/Config/org.example.webapp.appname.conf</string> | |
</array> | |
<key>installationIndicatorFilePath</key> | |
<string>/Volumes/Data/Library/Server/Web/Data/Webapps/org.example.webapp.appname/Config/org.example.webapp.appname.conf</string> | |
<key>launchKeys</key> | |
<array> | |
<string>org.example.webapp.appname</string> | |
</array> | |
<key>name</key> | |
<string>org.example.webapp.appname</string> | |
<key>sslPolicy</key> | |
<integer>0</integer> | |
<key>startCommand</key> | |
<string>launchctl load /Library/LaunchDaemons/org.example.webapp.appname.plist</string> | |
<key>stopCommand</key> | |
<string>launchctl unload /Library/LaunchDaemons/org.example.webapp.appname.plist</string> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: /Library/LaunchDaemons/org.example.webapp.appname.plist | |
# If the app runs under a subdirectory of the website (www.example.org/subdir for example) | |
# the following keys needs to be added do the ProgramArguments array | |
# | |
# <string>--path</string> | |
# <string>/subdir</string> | |
# | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>KeepAlive</key> | |
<true/> | |
<key>Label</key> | |
<string>org.example.webapp.appname</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/rvm/bin/rvm-exec</string> | |
<string>1.9.3-p194</string> | |
<string>bundle</string> | |
<string>exec</string> | |
<string>unicorn_rails</string> | |
<string>-c</string> | |
<string>config/unicorn.rb</string> | |
<string>--env</string> | |
<string>production</string> | |
<string>--listen</string> | |
<string>7303</string> | |
</array> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>UserName</key> | |
<string>org.example.webapp.appname</string> | |
<key>WorkingDirectory</key> | |
<string>/Volumes/Data/Library/Server/Web/Data/Webapps/org.example.webapp.appname/Data/current</string> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment