Deploying Sinatra app .rb - sinatra

I know this is probably a stupid question. But I created a .rb file with Sinatra framework and I am not sure how to "deploy" it. When I posted the file on the server I just get a simple text file that reads back my code. It works great when I run it with Sinatra.
Thanks in advance!

It looks like your web server (Apache?) is just serving you with your Ruby script (that is a text, ASCII file) instead of running it (that is: instead of passing it through the Ruby interpreter).
Hence:
Is the Ruby interpreter installed on your server?
Is your web server configured to run Ruby scripts (files terminating with ".rb")
through the Ruby interpreter?
And, is Sinatra itself installed on your web server?
Anyway, Ruby applications (Rails, Sinatra, Padrino) are usually deployed to a server using GIT. Have a look at Heroku and Engine Yard.
Also, there are tools specifically designed to help the developer in deploying Ruby applications. Have a look at Capistrano or Vlad and/or Google for "how to deploy a sinatra application".

For Sinatra/Rails/etc, most people use a Webserver (ie Apache, Nginx, etc) AND an Application Server (Thin, Passenger, Unicorn). For a simple app these can live on the same host. The webserver manages the incoming traffic and the application server executes the ruby code and passes results to the webserver.
When you execute ruby app.rb to run your Sinatra application, you're actually loading up WEBrick which is an application server. Since your development machine is local, you can access it directly at localhost:3000 or some similar address.
Look into tutorial on setting up your webserver with Thin, it's one of the easier ones to work with. When/if you outgrow it, then look into Unicorn.

Related

What directory to publish Asp.NET Core application on desktop to?

I come from the desktop application world (WPF, WinForms), where the convention is to deploy your exe to \Program Files[ (x86)]\CompanyName\AppName\ directory, and store all the data in \Program Data\CompanyName\AppName\ directory.
What's the corresponding convention for deploying Asp.NET Core web services on a desktop (not a server) PC? Program Files directory doesn't seem like a good idea, because it requires admin credentials for writing, a problem you hit the moment you try to publish the app. On the other hand, while Program Data doesn't have the permission problem, it just doesn't feel right, given there is no corresponding Program Files location.
I've also seen C:\intepub\wwwroot\web-service-name used, when IIS was involved. Is that the way to go? I'm guessing it makes sense when running Asp.Net Core app in Kestrel behind IIS as reverse proxy, but what if I were to host my app inside a Windows Service instead?
There is a lot of enduser as well as enterprise apps deployed as windows services with embedded web applications (using Apache, tomcat..etc) Under Program Files, Ex: HPE server admin/config tools.
So for Kestrel APP, I would deploy bin in Program Files and write logs,DB,etc under Program Data. it will works without permission issues since dotnet binary has the needed perms.

difference between perl dancer framework and apache2 http server

I am new to the programming world and started with Perl couple of days back. I tried developing a web application using Perl. Initially followed some tutorial and learned how to write simple CGI scripts using Perl and deployed it using Apache2 httpd server. After getting to know about the Perl Dancer it was much easier to develop a web application using the framework.As both serve the same purpose I want to know weather Dancer is a replacement to the Apache httpd server or dancer internally uses apache to start a server. As dancer is just a web application framework how internally it is managing to handle the server request and responses.
Can anybody post a link where I can read and get to know about how the webserver works?
Dancer has a PSGI interface.
PSGI is similar to CGI in that it allows a web server to communicate with the Perl application, but it is more efficient (it keeps the application running all the time so it doesn't need to load everything from scratch for each request) and has more features (e.g. the ability to use Plack middleware).
Dancer comes with a script to run a simple web server (which is not Apache) for development purposes.
It is expected that you'll use a more powerful web server (such as Apache HTTPD) in production.

How do you choose your HTTP server in Sinatra?

I am running a Sinatra application locally.
Ever since I installed Thin, my Sinatra app always uses it as the web server. However, I have been having performance issues with Thin serving the large amount of static files required by my application, and I would like to switch to either Mongrel or WEBrick.
I cannot seem to figure out how to switch my application over to Mongrel or WEBrick. Even when I put require 'mongrel' or require 'webrick' at the top of my app.rb, upon a ruby app.rb, Sinatra still starts with Thin.
So, my question is: how do you specify the web server for Sinatra to use in development mode? Also, how could I do so in production mode?
You can set the server Sinatra uses with the :server configuration setting:
set :server, 'webrick' # or thin, mongrel
In production, it is much better to use a more sophisticated server like Phusion Passenger or Unicorn, since they have better performance than Thin, Mongrel, or WEBrick. If you choose Passenger or Unicorn, you would not configure the server within your Sinatra application file itself, but instead typically configure it separately using a Rackup config.ru file.
"Ruby on Rails Server options" is aimed at Rails applications, but is still very relevant for Sinatra apps.

Web framework with user-friendly desktop deployment?

I'm building a web app with Backbone.js (I'm not tied to Backbone yet though). I need a back-end framework only for persistence to a database via a RESTful API. However, I also need to able to deploy it as a 'desktop' app for off-line use, i.e. running a local server and launching a browser window, but I don't want users to have to start a server from the command line to run the application.
I can use SQLite as a database since it's only a single user application, it's just the framework that I'm stuck on. I have looked at the following:
Rails and Django: Default web servers are too flimsy, requires Ruby/Python and runs from the command line. I'm aware of the Bitnami stacks but at 99mb it's too big of a dependency and not exactly hidden from the user.
Sproutcore: Run from command line, also too bulky.
Pyjamas Desktop - Depends on MSHTML which I suspect limits my ability to use HTML5 features.
I'm leaning towards creating a Java app that starts a Scala/Lift server instance and opens a web browser, then sits in the system tray (kind of like WAMP). Is anyone familiar with a tool or framework built for user-friendly deployment as a standalone desktop app?
I do not know if PHP is an option for you? Then I would recommend phpdock.
web2py has a standalone deploy-to-desktop feature with no dependency on Python: http://web2py.com/books/default/chapter/29/14#How-to-distribute-your-applications-as-binaries
As Eydun said, phpdock is an option but it's commercially licensed .
I settled on using Java/Spring/H2/Hibernate/Jetty. I find that Jetty serves requests VERY quickly so the application looks real-time when launched in a browser. There is a tutorial on embedding the Jetty server here. I imagine it's quite trivial to build a GUI that launches the server and a browser.
Another Java option is to use the Play Framework, which may be more at home to those coming from a Django/Rails background. However, the documentation for "creating a standalone version of your application" for Play 2.0+ indicates that they have ditched using Java EE containers (Tomcat/Jetty) and WAR files in favor of running the JARs with the bundled copy of JBoss Netty, so it may take a bit of work to get it running the way you want it.
I would recommend the Play Framework approach if you're OK with using/learning Scala.

Heroku-like services for Scala?

I love Heroku but I would prefer to develop in Scala rather than Ruby on Rails.
Does anyone know of any services like Heroku that work with Scala?
UPDATE: Heroku now officially supports Scala - see answers below for links
As of October 3rd 2011, Heroku officially supports Scala, Akka and sbt.
http://blog.heroku.com/archives/2011/10/3/scala/
Update
Heroku has just announced support for Java.
Update 2
Heroku has just announced support for Scala
Also
Check out Amazon Elastic Beanstalk.
To deploy Java applications using
Elastic Beanstalk, you simply:
Create your application as you
normally would using any editor or IDE
(e.g. Eclipse).
Package your
deployable code into a standard Java
Web Application Archive (WAR file).
Upload your WAR file to Elastic
Beanstalk using the AWS Management
Console, the AWS Toolkit for Eclipse,
the web service APIs, or the Command
Line Tools.
Deploy your application.
Behind the scenes, Elastic Beanstalk
handles the provisioning of a load
balancer and the deployment of your
WAR file to one or more EC2 instances
running the Apache Tomcat application
server.
Within a few minutes you will
be able to access your application at
a customized URL (e.g.
http://myapp.elasticbeanstalk.com/).
Once an application is running,
Elastic Beanstalk provides several
management features such as:
Easily deploy new application versions
to running environments (or rollback
to a previous version).
Access
built-in CloudWatch monitoring metrics
such as average CPU utilization,
request count, and average latency.
Receive e-mail notifications through
Amazon Simple Notification Service
when application health changes or
application servers are added or
removed.
Access Tomcat server log
files without needing to login to the
application servers.
Quickly restart
the application servers on all EC2
instances with a single command.
Another strong contender is Cloud Foundry. One of the nice features of Cloud Foundry is the ability to have a local version of "the cloud" running on your laptop so you can deploy and test offline.
I started working on the exact same thing as what you said a few weeks ago. I use Lift, which is a great framework and has a lot of potential, on top of Linux chroot environment.
I'm done with a demo version, but Linux chroot is not that stable (nor secure), so I'm now switching to FreeBSD jail on Amazon EC2, and hopefully it'll be done soon.
http://lifthub.net/
There are also other Java hosting environment including VMForce mentioned above.
If you are looking for a custom setup which also has the ease of deployment that heroku offers: http://dotcloud.com. They are invite only right now but I was given access in under three days. I am working on a Lift/MongoDB project there and it works well.
Off the top of my head, only VMForce comes to mind, but its not available yet. This will be a Java-oriented service, so that probably means you'll have to spend a wee bit of time figuring out how to package the app.
For more discussion, there was a debate about this in 2008.
I'm not entirely sure if it's really suitable or not, but people have deployed Scala applications to Google App Engine, for example http://mawson.wordpress.com/2009/04/10/first-steps-with-scala-on-google-app-engine/
Actually you can run scala on heroku right now. You don't believe it?
https://github.com/lstoll/heroku-playframework-scala
I'm not sure the tricks lstoll has used are legit but using the
new cedar platform where you can run custom processes and some
ingenious Gemfile hacking he has managed to bootstrap the Java
play platform into a process. Seems to work as he has a live
site running a test page.
Stax cloud service offers preconfigured lift project skeleton. Also, there is a tutorial on how to deploy lift project to appengine.