Bash script to play a sound file every X seconds

February 2, 2019

As part of my continued efforts to improve awareness of my physical body while I’m hacking away at a keyboard, I got the idea that it would be nice if a pleasant sound played every X seconds to remind me stop slouching, relax, etc.

I wanted it to be simple, easy to start and stop, and easy to configure both the time interval between plays and the file being played.

Finding nothing of that ilk in some quick Google searches, I present the below for your usage and hopefully increased awareness :)

Run without arguments for the help.

Debian start a ramdisk on boot

March 13, 2017

I run some servers that use a ramdisk to increase performance for recording audio files. Since ramdisks evaporate on a reboot, and I have services that depend on the ramdisk to operate properly, I needed a way to:

  • Automatically create the ramdisk on boot
  • Ensure it’s set up prior to the services that depend on it
  • Perform cleanup on the ramdisk when the server is shut down

The set of scripts below accomplish this nicely by leveraging systemd. Here’s a quick rundown of what each does:

  • ramdisk: The script is written as a System V init script, and would be placed at /etc/init/ramdisk. Does the work of:
    • Creating the ramdisk
    • Calling an optionally configured script to perform cleanup prior to tearing down the ramdisk
  • customize: This is an optional file to override the default settings of the first script. Place it at /etc/default/ramdisk with any customizations you like.
  • ramdisk.service: systemd service file that calls the start/stop functions of ramdisk. Place this anywhere systemd recognizes service scripts, and run systemctl daemon-reload.

The nice thing about this setup through systemd is that any other systemd services that depend on the ramdisk being set up can simply include this in their service description:

Requires=ramdisk.service
After=ramdisk.service

ICE/CBP regulations summary for domestic travelers

February 28, 2017

The election of Donald Trump has roused me from my political slumber, to be sure…

I’m trying to stay informed, and also signed up for the excellent Daily Action alerts, which keeps me plugged in to things I can do every day to make my voice heard.

Today’s alert was in reference to ICE/CBP’s request to see the ID of all passengers on a US domestic flight.

According to the expert cited in that article, it’s highly unlikely that these authorities have a legal right to demand you produce ID under these circumstances.

So today my little action of resistance was to print up a convenient half-page summary of the regulations the expert referred to in that article. Two copies per page, should be small enough to fold up and fit in a wallet, purse, or back pocket.

I’ll be carrying mine around, at least for awhile, to remind myself that I don’t want to live in a police state.

HUGE DISCLAIMER:

What I’m sharing is for informational purposes only. I’m not an attorney, and did not deeply vet this information, but simply looked up the US codes referenced in the article and made them a bit easier to carry around.

FreeSWITCH Kickstart, an automated server configuration tool

April 6, 2016

Project background

Several years ago I began the journey to better systematize my server management workflow. At the time I was managing over 20 server instances, almost entirely ‘by hand’, meaning I did things like keeping checklists for the steps to rebuild critical servers, running software updates on each individually, etc. Then, I finally took the time to research server configuration management software, selected Salt as my tool, and completely re-oriented my relationship to dealing with software updates, new server builds, etc.

Managing a server this way means that you don’t change anything about the server directly, but instead write code that makes the changes for you. While this does involve a learning curve (it’s almost always faster to just run a command straight from the command line than write code to run the command for you), the benefits of this approach far outweigh the costs in the long run:

  • Automatically rebuild any server from scratch: As long as you have data backups, it’s no longer a big deal if your server tanks. Rebuilding becomes a glorified version of rebooting your computer when it’s acting weird
  • Consistency in dev -> staging -> production environments: You can be much more sure that the server you’re doing development on is consistent with the server that will run in production. With tools like Vagrant, combined with server configuration management, you can run virtually the identical server on your laptop that you do for your customers.
  • Clear documentation: This cannot be underestimated. The exact steps to re-create your mission critical infrastructure is written in code, which means both certainty about how it works, and ease of transfer of this knowledge to other maintainers.

Even though this approach is well known by hard core sysadmins, I suspect many people who could profit from it still have not taken the leap, either through ignorance or the barrier of the learning curve.

Fast forward to last year, and I’m working on CircleAnywhere, an online group meditation platform, using FreeSWITCH for some of the video conferencing portions. Naturally the server, being mission-critical to the project, was built using a Salt configuration for all the reasons mentioned above. It was a fair amount of work to hammer out the deployment, and it occurred to me that a lot of the heavy lifting I had done was the same heavy lifting that anyone rolling out a new FreeSWITCH server (whether for local development or in production) had to do. So I decided to do just a little bit more work, and repackage my efforts for the good of others. :)

FreeSWITCH Kickstart

Thus was born FreeSWITCH Kickstart, a Vagrant/Salt configuration for automatically deploying a FreeSWITCH server for either development or production. Installation locally via Vagrant or remotely involves only a few simple steps (the most difficult of which is acquiring valid SSL certificates for production builds).

The project strives to provide these three things:

  1. An easy way to get up and running with a local FreeSWITCH development environment
  2. A sane/convenient starting point for rolling a production server.
  3. A nice starter template for admins who want their FreeSWITCH server under Salt server configuration management.

A ton of stuff is done automagically for you – even if you don’t like/need it all, it’s still an awesome way to get going!

I’ve written up a fairly comprehensive features list, so you know what you’re getting.

I hope the community will benefit from this work, and doubly hope that others will offer refinements on this first effort. My intention is to maintain this project for the FreeSWITCH community, keeping it up to date with the installation procedure for the latest code and recommended operating system. If anyone would like to join me in maintainership of the project, I would certainly welcome it. :)

Jester, FreeSWITCH, Lua, and my quest for an awesome scripting toolkit

January 20, 2016

Back in 2010, in collaboration with Star2Star Communications, I wrote a Lua scripting library for FreeSWITCH called Jester. Its most marketable highlight was a profile that offered a complete drop-in replacement for Asterisk’s Comedian Mail.

My deeper motivation for writing it was to try and bring some sanity and consistency to the process of implementing more advanced voice workflows. This motiviation arose from my own experience of the mishmash of dialplan XML and one-off Lua scripts that still to this day forms the foundation of my first major VoIP system. I began to believe that there must be a better way – if the goal was to do any number of fairly common things, like grab data from a database, send an email, talk to a webservice – can’t we basically standardize those into reusable units? So, Jester…

Fast forward to 2016, and my toolkit, through almost complete lack of maintenance, had become legacy code. In addition, the years had revealed both the strengths and weaknesses of my original efforts, and I wanted to do something about it.

In the last few weeks, I took the first big steps to revive and reshape Jester for a new and improved release. A lot of the hard work is now done:

  • Updated the entire codebase to be compatible with all 5.x versions of Lua, which means it will now run on anything from the terrifically old FreeSWITCH 1.0.7 to the very latest code.

  • Complete refactoring/update of the user documentation, now available online and nicely formatted.

  • Preserved the original Asterisk Comedian Mail replica, so it can still be used as a drop in replacement for those moving from Asterisk to FreeSWITCH

  • Good progress on handling some of the original architectural issues

Going forward, I’d love to get some other people on board with the project, particularly those interested in helping to turn Jester into a solid, well-used library for the land beyond the dialplan. I think the biggest reason for the initial flaws was that I didn’t have any other eyes on my designs.

Please do contact me if you’re interested in teaming up.

New release of Luchia, Lua API for CouchDB

December 31, 2015

Many years ago, I wrote Luchia, a Lua API for Apache CouchDB.

The library worked great, and had fair unit/integration test coverage, but after many years it was no longer compatible with the newer versions of Lua.

So, I took a few days recently to revive it and roll an updated release. It’s now compatible with Lua versions 5.1, 5.2, and 5.3, and also sports 100% unit test coverage.

Installation via LuaRocks, Lua’s package manager, is a breeze, just do:

luarocks install luchia

You can check out a summary and API usage in the online documentation.

Happy Luchia’ing. :)

Using Salt with services managed by Monit

September 29, 2015

I use Salt for configuration management on all my newer servers. I’m particularly fond of its watch requisite, and use it thoroughly to handle restarting all my Salt managed services if need be.

This generally works without much fuss. However, when a service that’s managed by Salt is also being managed by Monit, there’s a chicken and egg problem: when Salt automatically restarts a service using its standard method, Monit thinks the service has died, and problems ensue.

I really wanted my Salt service management goodness and Monit, so after a bit of thinking I came up the the idea of creating a psuedo-service. Salt manages the psuedo-service instead of the regular service, and the psuedo-service simply wraps the Monit commands for starting, stopping, and restarting the service. This allows Salt to trigger service actions via Monit.

This approach solved the issue beautifully without much code or effort. Below I’m including the RHEL/CentOS version of the psuedo-service – other platforms would require some minor adjustments, but the idea is the same.

As seen from the line defining the service name, I manage this script in Salt as a template, so that I can install it for multiple services.

Hope this helps anybody who gets stuck on this same issue!

Vagrant crash course for the busy developer

May 12, 2015

Today a friend remarked on his interest to learn Vagrant, and lack of time to do so. It occurred to me that the script I’ve been building to quickly knock up and down Vagrant VMs could be a handy aid along the shortest path for developers to begin their journey into this amazing toolset.

So without further ado, the shortest path I know of for a busy dev to start playing with Vagrant:

  • Install VirtualBox and Vagrant

    …or for Homebrew Cask users, the even easier brew cask install virtualbox vagrant

  • Run the following from CLI:

    vagrant box add bento/centos-7.1 --provider virtualbox
    vagrant box add bento/debian-8.2 --provider virtualbox

    …or pick some other box you like here.

  • Download the script below, stick it in your PATH, make it executable
  • Execute without args for the well-written help

    …or run quick-vagrant.sh -c to spin up your first box…

  • Enjoy :)

I also made the script a bit like a cheat sheet for Vagrant commands – if you search it for ‘vagrant’, you’ll see the first time any command is used, there’s a comment describing what it does. Or, here’s a more neatly formatted cheat sheet.

If you find this helpful getting up to speed, please pass it along to your busy developer friends! If you’d like to suggest improvements to the script, feel free to contact me.

General node init script for RHEL/CentOS 5.x/6.x

March 16, 2015

I wanted to have a general RHEL/CentOS init script that I could drop onto servers to start node processes. The features I wanted were:

  • Ability to reuse it for multiple node processes on the same server.
  • Ability to run as non-root user.
  • The classic service start/stop/restart/status functionality.

I had previously written a node init script using forever, but I ended up not liking it. This script still isn’t perfect, but it seems more generally useful to me.

Drop the script in /etc/init.d/[name] and make it executable, the custom configuration in /etc/sysconfig/[name], and use service [name] start to fire it up.

Installing Jekyll on RHEL/CentOS 5.x and 6.x with modern Ruby and Python versions

January 20, 2015

Jekyll can be run fairly easily on older (5.x and 6.x) versions of RHEL/CentOS, even though the stock versions of the necessary software are too old. The key is to use some simple supporting software to install what you need in a clean way.

The first handy tool is Ruby Version Manager, or RVM. Here’s a handy cheat sheet – use that to install RVM and the latest version of Ruby, set the installed Ruby as the default, and install the Jekyll gem.

Once that’s done, you may run into this error when trying to use Jekyll:

Liquid Exception: Failed to get header

This Jekyll issue indicates that Python greater than 2.6 and less the 3.x needs to be installed in order for syntax highlighting to work. Never fear, pyenv to the rescue!

Use the pyenv installer to get pyenv set up and running on your server, and have a look at the pyenv command reference to install an appropriate version of Python and set it as the default. Note: If you’re running RHEL/CentOS 5.x, you’ll have one more hurdle to cross before using pyenv, see this post for detailed instructions.

If you’d also like to set up your Jekyll site to update from a git push, I’ve detailed one workable approach in this post – if you do use it, just make sure you put the necessary RVM/pyenv environment set up stuff in the .bashrc file of the user the git push command runs as on the server.

Happy Jekyll’ing!

Older posts