Here’s a small script I threw together to check the number of DHCP leases on an Ubiquiti EdgeRouter. It’s made for use with Nagios.
It basically connects to the router via SSH, executes
show dhcp leases and returns OK, WARNING, or CRITICAL depending on how many leases exist. See the comments for a little bit of documentation.
Continue reading Nagios – Checking DHCP Leases with Ubiquiti EdgeRouter
Universal Media Server originally started as a fork of PS3 Media Server. It is a great DLNA server for Linux. It has a large device support among other features. In our home, it is used to stream from our media server in the basement to the PS3 in the living room.
The following steps will get it installed in a headless fashion on CentOS 7. They should also be easily adapted for any recent versions of Fedora. The biggest difference from this guide and others I’ve seen is I provide a service file for systemd.
- Install EPEL’s and Nux’s repositories. Visit each project’s website for the latest release, but the following should work:
$ sudo yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm
$ sudo yum install http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
- Install programs needed for transcoding:
$ sudo yum install mplayer mencoder ffmpeg mediainfo
- Install Java. You have two choices here. Install the appropriate openjdk package, or get the latest RPM from Oracle’s website. I’ve found Oracle’s java release works best with UMS.
Install the files for UMS
- Download a tarball of the latest version from UMS’ website to your home directory.
- Extract the tarball, and move it to /opt. Create a symlink from /opt/ums-#.#.# to /opt/ums. This allows you to add new versions and just replace the symlink, preserving the old installs if you want.
$ tar zxf UMS-4.2.2-Java7.tgz
$ sudo mv ums-4.2.2 /opt
$ sudo ln -s /opt/ums-4.2.2 /opt/ums
- Copy the config files to /etc/ums. This makes more sense than keeping them with the UMS files.
$ sudo mkdir /etc/ums
$ sudo cp UMS.conf WEB.conf /etc/ums
- Create a user, ums, to run the UMS application under. This user will need permissions to read the media files, as well as write permissions to the folder for the config files and the application files. Don’t set a password, use /opt/ums for the home directory, and use /sbin/nologin for the shell.
$ sudo useradd -d /opt/ums -s /sbin/nologin ums
$ sudo chown -R ums:ums /opt/ums-4.2.2
$ sudo chown -R ums:ums /etc/ums
- Now, open up /etc/ums/UMS.conf in your text editor. Go through and adjust the parameters as necessary for your setup.
Systemd is the init system in CentOS 7 and the more recent versions of Fedora. It will be utilized to start UMS on startup, as well as provide easy logging of events.
- Create the file /etc/systemd/system/ums.service. This gives systemd information about how to start UMS. It should have the following contents:
Description=Universal Media Server
- Next, instruct systemctl reload its configuration, then enable, and start the service:
$ sudo systemctl daemon-reload
$ sudo systemctl enable ums
$ sudo systemctl start ums
- Provided everything started fine, there should be no output from systemctl after starting it. You can utilize systemctl to verify everything started correctly:
$ sudo systemctl status ums
ums.service - Universal Media Server
Loaded: loaded (/etc/systemd/system/ums.service; enabled)
Active: active (running) since Sun 2014-11-30 19:12:20 MST; 32min ago
Main PID: 12912 (java)
└─12912 java -Xmx768M -Xss2048k -Dfile.encoding=UTF-8 -Djava.net.p...
- Systemd captures all the output from UMS and stores it in its logs. You can access all that information with journalctl. This is extremely useful if there are problems. To view all messages from UMS, you could use the command: sudo journalctl _SYSTEMD_UNIT=ums.service
Open the firewall
Unless you’ve already mucked with the defaults, the CentOS firewall should be up and running, and likely only allowing port 22/tcp in. You will need to open some holes in the firewall.
Let’s first look at the ports that UMS uses:
$ sudo netstat -pln | grep java
tcp 0 0 0.0.0.0:9001 0.0.0.0:* LISTEN 12912/java
tcp 0 0 10.0.0.204:5001 0.0.0.0:* LISTEN 12912/java
udp 0 0 0.0.0.0:1900 0.0.0.0:* 12912/java
Unless you’ve changed anything, by default, those are 5001/tcp, 9001/tcp and 1900/udp. Port 9001/tcp is optional. Enable it if you want to browse your media via a web browser. Let’s utilize the firewall-cmd utility to poke the holes:
- Determine the active zone for your network interface. In the command below, the zone in use is internal. Yours will likely be the default, which is public. Notate it, and use it for the next commands:
$ sudo firewall-cmd --get-active-zones
- Open the ports on the zone, and reload the firewall:
$ sudo firewall-cmd --add-port=5001/tcp --zone=<zone> --permanent
$ sudo firewall-cmd --add-port=9001/tcp --zone=<zone> --permanent
$ sudo firewall-cmd --add-port=1900/udp --zone=<zone> --permanent
$ sudo firewall-cmd --reload
- Verify the ports are open:
$ sudo firewall-cmd --list-ports --zone=<zone>
5001/tcp 9001/tcp 1900/udp
Congrats! You’re done! Launch your DLNA client (or PS3 as it were) and make sure things are working. Utilize journalctl to gather diagnostic information if things aren’t working right.
Update: I’ve made some changes in the systemctl setup and noted that port 9001 is optional. These were at the advice of Vallimar on the UMS forums. Thanks!
I have an 18 month old toddler that loves to run up to my laptop while I’m working and push the eject button on CD-ROM drive and pull on the tray. One of these days, I’m worried he’s going to break it off.
It is possible, using the ‘eject’ command, to lock the tray and prevent it from being ejected by the button.
On Fedora 20, you’ll need to perform a few steps as root to get it working.
- Open the copied file, and comment out the line beginning with
- You may need to force udev to trigger your rules:
You can now use the eject command to enable the lock. Executing
eject -i on will spit out
eject: CD-Drive may NOT be ejected with device button, effectively locking your toddler out of your CD-ROM drive.
Microsoft Hyper-V is a great hypervisor if all you have are Windows guests. Unfortunately, the support for Linux guests is not the greatest. KVM, on the other hand, has great support for both Windows and Linux guests. For this reason, I’ve been working on moving the hypervisor I have in my home from Hyper-V to KVM.
This post will detail the steps necessary to migrate a Windows guest from Hyper-V to KVM. The version of Hyper-V I’m running is 2012R2 and the guest is Windows 8.1.
Continue reading Migrate Hyper-V Windows Guest to KVM w/ libvirtd
Finnix is a great rescue live CD. I recently wanted to use it in an environment where I only had a serial console for the machine. Here’s how I tweaked Finnix to work over the serial console.
Continue reading Making Finnix Use Serial Console
You learn something new everyday. This morning, I just learned of the “at” program.
‘at’, like its cousin, ‘cron’, allows scheduling of commands. The difference, while ‘cron’ will run the command repeatedly on a schedule, ‘at’ will run the command once. Here’s how to use it. Continue reading Scheduling Commands for the Future in Linux