Create stand-alone system services in Ruby - ruby

I want to build application which servers as a stand-alone system service, always run on the backend and servers a front-end with a web interface.
Like we do in Linux /etc/init.d/apache2 start , Same as I want to server my application /etc/init.d/myapp start.
My major target is to deliver on Linux specially Ubuntu, whole app would be in plain Ruby and front-end would be in Sinatra.
I want to make it install with simple, gem install my_app and command line features get available to start the service. The application would be doing heavily processing and database insertion. And I want that its configurations must be set as in pure linux fashion, like /etc/apache2/apache2.conf
Can any one guide me in it? Also if possible, i want to secure the code, is there any possibilities for it?

I am using the Daemon-Kit gem for the same requirements. Works very well in production. The only thing it does not include is the configuration with a .conf file, but it's easy to do it yourself with Ruby code. You can deploy with Capistrano, no need to install.

Related

Automatically set up new Digital Ocean server for Laravel app

I know that https://forge.laravel.com/auth/register is available for $12/month*, but I'd like to understand how to accomplish the same thing myself.
What I assume is possible (and what I'm looking for): I create a server that has only Ubuntu 18.04.3 installed and nothing else, and I upload a script that installs all the appropriate software and sets up MySQL with the correct passwords, etc (without manual intervention).
I've tried Laradock and had tons of problems with Docker and don't want to do that anymore.
I see that https://cloud.digitalocean.com/droplets/new lets me create a LEMP droplet (Ubuntu, Nginx, MySQL, PHP-FPM) with one click. But it lacks Redis, and its versions are outdated (e.g. PHP 7.2).
I've heard people mention Chef (maybe this?), but that seems to be more complicated than what I'm imagining.
Unfortunately I'm not even sure how to search for what I'm trying to do (or how to tag this question); is this called "server provisioning"? I've been searching phrases like "automatic install script redis mysql server for laravel".
Thanks in advance for pointing me in the right direction.
* I also just found https://getcleaver.com/ and https://runcloud.io/server-management, which each look like Forge + Envoyer (and RunCloud offers a free plan).
It is called server provisioning and Chef would be a good fit for this, check out Ansible too - another thing you could do is setup the server yourself and create an image from that server and then base your new servers out of that image, that way you'll have all your services installed from the start.
This sounds like a job or something like Puppet (or Chef/Ansible), however Laravel Envoy may be another tool to look at if you haven't already for the second part of your problem.
I highly recommend Heroku (or similar service), as this is all done out of the box, and has a ton of other great features that make developing a pipeline a breeze.

Web application in Golang for offline/browser use

I'd like to create a simple web application to manage some data. The application will use PostgreSQL but I have no idea how to package everything in order to make it run on windows, linux, and mac. I can cross-compile a go binary which will include everything (web server, etc..) but the postgresql database will be left out because that's running as a separate server locally. I heard about docker but I don't know if that's the right solution.
Should I create a docker container and include PostgreSQL in it so I can start that web app on any platform?
You don't need Docker to do this.
It complicates things since your users will have to install the Docker engine first. Go is perfectly capable for cross platform applications, batteries included.
Decide if you want your app to run in a browser tab or should it have it's own window?
For a browser tab compile your app for the target architecture and think about a URL scheme that will make sense to your users, for example
localhost:8080/app => the user interface. This route is the web app, it serves HTML, JS and CSS. Tell your users to run the executable (or install it as a service, see this or use a platform specific tool like this one). Then open the link in a browser
localhost:8080/api => backend routes. Serves data to requests made by the user interface. For talking to the Postgres server running locally
If you want your app to run in it's own window have a look at Electron. See gotron: Go Api for Electron
If you want to use Docker for this, you have to create a platform-specific docker image containing the platform-specific binary in it. Once you have these images, you can use docker-compose to run your app with an instance of postgres running in its own container.

Combining travis and ec2

I have a github project that uses travis for continuous integration. I would like to deploy my project on amazon ec2. In order to simplify deployment, I would like the deployed system to have the same configuration as the test system. Is this possible?
AFAICT, this requires two things: First, an ec2 preconfigured instance that matches the settings used by travis. Does one exist? And second, a way to execute travis.yml scripts from the command line. How can I do that?
As for executing .travis.yml scripts from the command line, if I were you I would instead take it the other way around and replace your .travis.yml script with something like this:
language: bleh
etc etc...
install:
- ./travis-scripts/install.sh
before_script:
- ./travis-scripts/before_script.sh
script:
- ./travis-scripts/script.sh
Of course, you will still have to write a script for installing whatever language versions, Travis plugins etc you need on your Amazon EC2 instance.
As for an Amazon EC2 instance that matches Travis VMs, I don't know about that because I'm not so familiar with Amazon AWS, but I can tell you that Travis VMs are based on Ubuntu 12.04, and there is a lot more specific information in the page about The Build Environment.
So you want something on a EC2 instance that can read your .travis.yml file and configure it in the same way that travis does when it tests?
I think that's a pretty long shot for a relatively simple problem like this. Travis is an integration and testing platform that uses a lot of other systems (like chef and docker) to do what it does with the .yml files. To use this system to run a single app sounds a bit overkill.
I would recommend using chef (or similar like puppet) to configure your production environment and deploy your app.
You could have one chef recipe that configures the production environment (DB's, configuration files, install stuff, etc...) and another that deploys, configures and starts your app. When you want to make changes to the production environment, you make changes to these files. They can easily be bundled with the project.

Integrating Ruby on Windows WAMP server so I can run Ruby and PHP at same time?

I've been searching on this but haven't found anything decisive so far.. I already have a windows WAMP server up and running and am using it for my PHP apps, I want to be able to run some small ruby scripts (to interact with a library that is not available in PHP), I don't even need Rails at this point, I just want to run ruby scripts and be able to run them from within a web browser type environment (like PHP) but I can't figure out how to do this since the "instant rails" takes the same resources of php and apache so it can't run at the same time unless I change the port but I'd rather just make it so it runs off the same apache as my PHP apps ( I don't even need a database at this point as thats all handled in my php apps).. any advice is appreciated
Seeing that you have accepted the answer from your other question: you won't be able to run a ruby TCP server on port X and Apache on the same port.
On the other hand if you decide to use Rails: Install InstantRails but don't start it. Copy the portion of Apache config (in InstantRails directory) that binds rails to Apache and edit it to handle everything under (for eample) /rails then paste it into your Apache config that runs PHP. You may have to fiddle with paths (PATH variable). This way you'll have Apache running on port X, all *.php will go to your PHP interpreter and everything under (for example) /rails will go to Rails/Ruby

Running gem server in passenger

I'm running a few rails/rake apps in Apache/passenger and I want to add the documentation app served by gem server to these apps, so I can easily give it a special (sub)domain, like docs.example.org, so it's easily available for all members of our team and nobody has to start the server himself or remember port numbers (like 8808, the default gem server port).
I would recommend looking into bdoc instead of gem server, it allows the user to access all their gem docs without a server running at all. It would also be trivial to modify bdoc to output to a specific directory then you could easily add a step to regenerate the docs.
The nice thing about having them in static files would be the apache config is dead simple.
If you do want to make bdoc output to a specific dir look at this line.
Edit:
I actually went ahead and branched this on github and made the change. Now you can supply the output directory on the command line and it will generate the static rdoc pages for you.
I'm running http://gems.local on my machine in case I want to do some Ruby cracking offline. (Plain journey, trains, etc).
This is really easy, you can actually run passenger with all the Ruby gems' documentation locally without having to access the net.
I was following Jason's tips and got everything working. See the following article and you should be ready to go:
http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs
Attila
I wrote a blog post on how I have my gems, ruby, rails and jquery docs locally using the yard server and nginx for proxing in mac os x. Steps for linux are almost the same, only thing that changes is the way to configure the daemons.
https://makarius.posterous.com/offline-rails-ruby-jquery-and-gems-docs-with

Resources