sysadmin

Running a docker registry in my homelab

Home labs are a great place to learn and tinker with systems. I love it because I get to wear my systems administrator hat. I’ve been doing a lot of application development lately as well as tinkering with various build & deployment tools for those applications. The best way, in my opinion, is docker. It’s just so good, you can package up all of the tools and configurations into a distributable unit, using an open standard.

Continue reading →

Running Ruby on Rails on Docker

I have been developing Ruby on Rails apps in Docker for several years now. I couldn't imagine not using Docker at this point! An Introduction to DockerDocker an open-source project for automating the deployment of applications as portable self sufficient containers that run in cloud or on premises. Docker is also a company that owns this technology. The underlying technology that powers Docker has been part of Linux for many years.

Continue reading →

Multi-Platform Git Diff and Merge Tools

Maintain a single .gitconfig between different operating systems by using proxy scripts for git diff and git merge tools. We first need to know which operating system we are using. I do this by by extracting the value from uname and then setting the value to an environtment variable. On MacOS this will return darwin, on most Linux distributions it should return linux. export DOTFILES_OS=`uname | awk '{print tolower($0)}'` In your .

Continue reading →

Deploying a Simple Rails App with Ansible

Ruby on Rails is quickly becoming my framework of choice for my personal websites and projects. It's a pleasure to work with and has been easy to learn. But no framework is without its challenges. One of those challenges is of course deploying the app to a server. There are a lot of options for hosting and deploying a Rails app. But, I like to run my own servers which means I have to also take care of deploying to those servers.

Continue reading →

How to Run Rails App Server with Systemd and Ansible

Create a systemd service to run your rails app server. Ansible tasks to create the service: --- …snip… vars: rails_root: “/myapp” rails_user: “webuser” tasks: - name: Setup Rails Web Service template: dest: /usr/lib/systemd/system/rails-web.service src: templates/rails-web.systemd.j2 - name: Enable Rails Web Service systemd: name: rails-web daemon_reload: yes enabled: yes masked: no The ansible template "rails-web.systemd.j2": [Unit] Description=Rails Web [Service] Type=simple SyslogIdentifier=rails-web User={{ rails_user }} PIDFile={{ rails_root }}/tmp/pids/web.pid WorkingDirectory={{ rails_root }} ExecStart=/bin/bash -l -c “{{ rails_root }}/bin/rails s -b 0.

Continue reading →

WP Transients must be used responsibly

We ran into an interesting issue with WooCommerce at work. First, here is the subject of the support request we got from our hosting provider: The site is generating ~150MB/sec of transaction logs, filling 500GB of diskspace Holy. Shit. A WordPress site should not be generating that much data. 150MB per second? Wow. How? Why? The simple explanation is that there is a bottleneck in WooCommerce with the filtered layer nav query objects using single transient record.

Continue reading →

Whitelist IPs in Nginx

I want to whitelist my clients IP addresses (and my office IPs) to allow them to view a site, while the rest of the world will be redirected to another site, using Nginx. My Nginx server is behind a load balancer. Using the geo module I am able to do this rather easily. By default, geo will use $remote_addr for the IP address. However, because our server is behind a load balancer this will not work, as it would always be the IP of the load balancer.

Continue reading →

Capistrano tasks for Magento

Custom tasks for Capistrano that I am using to help manage a Magento website. set :linked_files, %w{app/etc/local.xml .htaccess robots.txt} set :linked_dirs, %w{sitemap var media} namespace :mage do task :restart do on roles(:app) do execute "cd #{current_path} && rm -f maintenance.flag" end end task :disable do on roles(:app) do execute "cd #{current_path} && touch maintenance.flag" end end task :enable do on roles(:app) do execute "cd #{current_path} && rm -f maintenance.flag" end end task :clear_cache do on roles(:app) do execute "

Continue reading →

Setting up Git HTTP Backend for local collaboration

You want to share a topic branch with a colleague but do not want to push that branch upstream to Github/BitBucket/GitLab, etc. How do you do this? You could create a patch and email it. Or you could do it in the most crazy way possible and use Apache and allow your colleague to pull from your repo directly. This does take a bit more time to setup, but it would also be absolutely crazy dumb for everyone involved.

Continue reading →

Enable status for php-fpm

Accessing the PHP-FPM Status screen is easy enough. First, enable pm.status in your php pool: pm.status_path = /status Then add the following block to your Nginx vhost conf: location ~ ^/(status|ping)$ { access_log off; allow 127.0.0.1; allow 192.168.1.0/24; ##### YOU WILL WANT TO CHANGE THIS TO YOUR IP ADDR ##### deny all; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/var/run/php-fpm-www.sock; } Restart php-fpm and nginx and then browse to http:///status. You will be presented with some useful information on the current status of your PHP-FPM pool.

Continue reading →

Trying to Troubleshoot extremely high MySQL CPU Usage

MySQL CPU usage was spiking upwards of 1000%. Load average was around 50-60. I could not SSH into the machine though, not immediately. Since I could not actually get into the machine I had it restarted. Just as soon as the machine came back up MySQL CPU usage jumped right back up to 1000%. Once I was able to finally shut MySQL down I had to discover _why_ the load was so ridiculously high.

Continue reading →

Securing Git repository from accidental exposure using Chef

It was brought to my attention at the office that a few of our recently launched websites had publicly exposed .git repository information. Unscrupulous users could use the exposed data to pull down the entire commit history, giving them unfiltered access to what is basically the blueprint for the website. What if someone accidentally uploaded a config file to the repository with sensitive information in it? Or what if the user was able to discover a major security vulnerability in the code that would have otherwise remained "

Continue reading →