Category: howto

How to determine the version of a memcache server

In a shell (Linux/Mac) or command prompt (Windows) type the following command:

telnet localhost 11211 

Where localhost can be replaced by the servers’ ip address and the port by a different one. 11211 is the default. A prompt will appear when the connection is succesful. Type the following command:

version

Depending on your telnet client, you might not see the text you are typing. Memcache will respond with its version, for example:

VERSION 1.2.4

Leave a Comment

Find the largest files in subdirectories

I find myself regularly with limited diskspace, and unsure which files to remove. Normally the largest files
I do not use anymore are the best candidate. When using Linux I use the command find:

find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

This command searches for the largest files. In order to find the largest redirectories, replace the -type f with -type d.

Leave a Comment

Sudo rights to group

When setting up a new Linux system you also need to set up a way to gain root access for you standard user account. This is relatively easy to do following
these simple steps as root:

Edit /etc/sudoers and find the following line and uncommit it by removing the ‘#’ from the second line:

## Uncomment to allow members of group sudo to execute any command
#%sudo ALL=(ALL) ALL

Add the useraccount you wish to grant sudo access to to the sudo group, where user is the user account you want to give sudo access to:

usermod -a -G sudo [user]

When logged in as this user, issue the following command to gain root access using your own password:

[daan@system] sudo su -

Leave a Comment

Find hosts in network using nmap

Sometimes you need to know what the IP address is of a certain system in the network. For example if you plug in a new device and need to know
which IP address it got assigned. In Linux the tool nmap can be used to scan the IP range of your local network. With the right parameters
it will report on the different system it has found.

On the console execute the following command, where you replace 192.168.121 with the IP range of your own network:

sudo nmap -sP 192.168.121.0/24

This will output something similar to the example below from which, hopefully, you can deduce which of the systems below is your system:

dean@box:~$ nmap -sP 192.168.121.0/24

Starting Nmap 5.21 ( http://nmap.org ) at 2014-04-10 20:47 CEST
Illegal character(s) in hostname -- replacing with '*'
Nmap scan report for Network (192.168.121.1)
Host is up (0.0067s latency).
Nmap scan report for Box (192.168.121.103)
Host is up (0.000056s latency).
Nmap scan report for Molvin (192.168.121.109)
Host is up (0.0013s latency).
Nmap scan report for 192.168.121.160
Host is up (0.0038s latency).
Nmap scan report for GameConsole (192.168.121.166)
Host is up (0.039s latency).
Nmap scan report for Tablet (192.168.121.198)
Host is up (0.037s latency).
Nmap scan report for android-xxx (192.168.121.238)
Host is up (0.067s latency).
Nmap scan report for 192.168.121.253
Host is up (0.0081s latency).
Nmap done: 256 IP addresses (8 hosts up) scanned in 4.42 seconds

Leave a Comment

Let Jenkins ignore shell script return code

In a build preparation script I had a shell command that was executed. This command set some permissions, but would fail if the folder to set the permissions on would not exist. If the folder does not exist it would fail the build
because the permissions command would fail. I was looking for a way to ignore that, because the settings of the permissions would only fail if the workspace was cleaned and the file would be created later on in the build process
with the correct permissions.

In a Google Group post I found the solution, append || true to the command:

chmod 777 file.xml || true

Leave a Comment

Running Second Crack on a nginx server

This blog is running on an nginx webserver. The Second Crack page contains a .htaccess file which rewrites the permalinks to html files. For example the URL http://www.example.com/2014/01/20/example-blog-post is internally rewritten to http://www.example.com/2014/01/20/example-blog-post.html. On an nginx server .htaccess files do not work (at least not on a default configuration) so this needs to be incorporated in the site configuration.

Update April 26th 2015, updated nginx configuration to support index.html index file on subfolders (in try try_files statement).

Server config file

The server configuration below is based upon an excellent post by Adufray, I only improved upon it. Most elements are pretty standard, I will only explain the ones which are not as obvious.

server {
	listen 80;
	server_name www.daangemist.nl;
	root /srv/http/webapps/www.daangemist.nl;
	index index.html;

	rewrite ^/feed/$ /rss.xml permanent;

	types {
		application/rss+xml xml;
	}

	location ~ ^/. {
		default_type text/html;
		try_files $uri $uri/index.html $uri.html =404;
		error_page 404 /404.html;
	}
}

Rewrite

This line tells nginx to return a 302 Redirect HTTP response if someone requests the /feed/ URL. It is in place for the migration from WordPress to Second Crack.

Types

The RSS feeds are XML documents, this directive tells nginx to return a Content-Type: application/rss+xml header instead of text/xml for the RSS files.

Location

_tryfiles is the nginx counter part of the .htaccess _modrewrite directive in the .htaccess file on Apache. It tells nginx to look for a .html file for every URL it cannot find. I have added the =404 to prevent a redirect loop, this occurred in combination with the error_page directive.

2014/01/03 23:23:43 [error] 21252#0: *3 rewrite or internal redirection cycle while internally redirecting to "/favicon.ico.html.html.html.html.html.html.html.html.html.html.html", client: 62.140.132.196, server: www.daangemist.nl, request: "GET /favicon.ico HTTP/1.1", host: "www.daangemist.nl"

The $uri/index.html is to support subfolders, for example by accessing the monthly index via http://site/blog/2014/02/.

_errorpage tells nginx to open a custom 404 page if a post or page cannot be found, as explained in the WordPress migration post.

Leave a Comment

Running Second Crack on a Windows computer

This blog is hosted on a Linux server, but I generate the blog on my Windows laptop. Some small changes are required in order to get it to work on Windows. The readme.md on the Second Crack is very elaborate in the installation notes. This blogpost only describes the changes I had to make to get it to work on Windows.

Installation

I have installed Second Crack in a separate folder, in C:\apps\secondcrack. The source files are placed in _C:\blog_, in the following structure:

\cache
\drafts
\media
\pages
\posts
\templates
\www
    \css
    \js
    \img

The config.php in the Second Crack folder I have changed to reflect this structure.

Code change

The update.php script in the Second Crack engine folder which triggers the blog update must be changed. A locking mechanism has been implemented in this file, but it does not work under Windows because the used PHP extension (POSIX) is not available.
Thefore the lines in update.php related to locking must be commented out. This is the following snippet as an example:

update.php
<?php
/*define('LOCK_FILE', isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '/tmp/secondcrack-updater.pid');

// Ensure that no other instances are running
...
    fwrite(STDERR, "Cannot write lock file: " . LOCK_FILE . "\n");
    exit(1);
}*/

$fdir = dirname(__FILE__);

This will disable all functionality related to locking. Now updating the blog is a matter of executing (assuming the php.exe is installed in c:\php\php.exe:

c:\php\php.exe c:\apps\secondcrack\engine\update.php

Leave a Comment

VLC fullscreen on external display

I was looking for a way to set up VLC to always start the video fullscreen on the second external monitor. I have found some ways to do this online, in two different approaches: via a batch file and via VLC settings.

Batch file

Create a batch file with the following contents:

set vlcPath="C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"
%vlcPath% %1 --video-x=1600 --video-y=400 --fullscreen --no-video-title-show --no-embedded-video --no-qt-fs-controller

Replace the values vlcPath with the exact path to your VLC installation. Also, replace video-x and video-y with the x and y values on which your second monitor is positioned. You can play a video by dragging / dropping a video file onto the batch file.

Via VLC settings

You can also set these options directly via the settings. This means that all video’s played via VLC on that computer use these settings.

  1. Open the preferences dialog (Tools –> Preferences)
  2. In the interface tab, choose Native, and un-tick “Embed video in interface” (this enables the controls to be separated from the video)
  3. Choose “All” in the “Show settings” box at the bottom left of the preferences window
  4. Choose the video options from the left
  5. Tick Fullscreen video output
  6. Scroll down and set an X and Y position that are on the second monitor – so set an X position larger then the width of the first screen. The value of the Y coordinate doesn’t matter much, but mustn’t be negative otherwise both values will be ignored.
  7. Save the settings

Leave a Comment

MySQL skip replication

Replication in MySQL is a useful tool to build a fast and reliable database infrastructure. But replication can go wrong, which leaves the MySQL slave unable to execute the queued query. This halts the entire replication process, replication commands after that are also not executed.

The cause for the replication problem can be determined by logging in and the slave and executing the command:

SHOW SLAVE STATUS\G

This shows the following output if replication is running correct, the important attribute is the Slave_IO_State:

mysql> show slave status\G
    *************************** 1. row ***************************
                 Slave_IO_State: Waiting for master to send event
                    Master_Host: 127.0.0.1
                    Master_User: replication
                    Master_Port: 3306
                  Connect_Retry: 60
                Master_Log_File: mysql-bin.000045
            Read_Master_Log_Pos: 53443450
                 Relay_Log_File: mysqld-relay-bin.001454
                  Relay_Log_Pos: 53443587
          Relay_Master_Log_File: mysql-bin.000045
               Slave_IO_Running: Yes
              Slave_SQL_Running: Yes
                Replicate_Do_DB:
            Replicate_Ignore_DB: mysql
             Replicate_Do_Table:
         Replicate_Ignore_Table:
        Replicate_Wild_Do_Table:
    Replicate_Wild_Ignore_Table:
                     Last_Errno: 0
                     Last_Error:
                   Skip_Counter: 0
            Exec_Master_Log_Pos: 53443450
                Relay_Log_Space: 53443587
                Until_Condition: None
                 Until_Log_File:
                  Until_Log_Pos: 0
             Master_SSL_Allowed: No
             Master_SSL_CA_File:
             Master_SSL_CA_Path:
                Master_SSL_Cert:
              Master_SSL_Cipher:
                 Master_SSL_Key:
          Seconds_Behind_Master: 0
    1 row in set (0.00 sec)

It may be that a certain CRUD command cannot be executed, this will be displayed in the same attribute that now shows everything is okay. After examination you may decide to skip that action, because it is not important or you decide to execute it manually. Execute the following command to skip 1 command:

SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;

For more information on replication and other skipping possibilities read this article on ducea.com.

Leave a Comment

Easy WordPress update via SSH

Have you ever struggled with the automated update feature of WordPress, not being able to use it because it requires FTP? FTP is by design a “not really secure” protocol, so if it can be avoided, avoid it. There is a plugin called SSH SFTP Updater Support which enables updates via SSH/SCP.

When using it I encountered an issue with the php_time_limit being to short (30 seconds); so I temporarily set it to 0 (unlimited) via a .htaccess file.

Leave a Comment