Sunday, 24 March 2013

Creating An RPM for openSUSE - some notes

I wanted to create an rpm which I had not done before. Here are some notes on the process.

I created a user on my machine for this process called rpmbuilder.  

Create a folder for development and create the layout for developing rpms

mkdir rpmdevenv; cd rpmdevenv

mkdir BUILD RPMS SOURCES SPECS SRPMS

Create the file ~/.rpmmacros with

%packager       High Fructose Corn Syrup

%_topdir        /home/rpmbuilder/rpmdevenv

%_rpmtopdir     %{_topdir}
%_builddir      %{_rpmtopdir}/BUILD
%_rpmdir        %{_rpmtopdir}/RPMS
%_sourcedir     %{_rpmtopdir}/SOURCES
%_specdir       %{_rpmtopdir}/SPECS
%_srcrpmdir     %{_rpmtopdir}/SRPMS

Add source code to SOURCES
Add .spec file to SPECS
Build the rpm from the SPEC

rpmbuild -ba SPECS/something.spec

Some good references

Tuesday, 5 February 2013

Returning the HTTP code of a HTTP request

This is really useful for returning HTTP code of a request.

curl --write-out "%{http_code}\n" --silent --output /dev/null www.example.com

Find all unique url's from Apache log files

I needed to build a list of all unique hits that had been made on a website in Apache.

Here's what I came up with using awk and sed.  This should match any HTTP 2xx or 3xx requests and strip of any GET request parameters.


awk '$9 ~/^(2|3)/ {print $7}' somelogs* | sed 's/\?.*$//' | sort | uniq

Wednesday, 23 January 2013

Global search and replace with sed

So today I needed to replace a few hundred href link in varying content today.  Here's my take on solving it. This works in zsh.  I think for bash you need to add the do and done parts of the for loop, i'm not sure.

for file in `grep -lR "href=\"\/static\/" .`; sudo sed -i -e 's/href=\"\/static\//href=\"\/applications\/static\//g' $file

Thursday, 17 January 2013

SSH Pseudo terminals

There is always so much more to SSH than I know about.  Here is another discovery I made today.  This allows me to ssh into a machine via a gateway in just one command care of the -t flag

ssh -t agatewaymachine.com "ssh 192.168.1.253"

Wednesday, 16 January 2013

Disable php deprecation warnings per apache virtual host

php_value error_reporting 6135

Seems you have to use the numerical value in apache for this.  This should be all E_ALL minus E_DEPRECATED AND E_USER_DEPRECATED

This will only work if the error handling function is not overridden in the php code.

Thursday, 15 November 2012

Life with systemd Part 2

systemd rocks!  I really did not think I had the patience to learn it, but now I understand it and have played about with it, I think it is brilliant if not for one reason alone - creating service files are trivial, which is how it should be.  In SysVInit I rarely bothered.

Here's one I knocked up for icecast.  There was already a rc script for it running under under systemd but I decided to create my own systemd service file as a test.  To install was was simply a matter of:-
systemctl stop icecast.service 
systemctl disable icecast.service
cp icecast.service /lib/systemd/system/icecast.service,  
and then activating it again with systemctl enable icecast.service 

systemd realised it had a service file for it and uses that rather that the installed /etc/rc.d/icecast file which I could leave installed.  I'm impressed.

Here's the icecast.service file I created.  I had to uncomment the pid file option in icecast.xml.  I also changed the path to /var/run


[Unit]
Description=Icecast 2.x Server

[Service]
ExecStart=/usr/bin/icecast -b -c /etc/icecast.xml
Type=forking
PIDFile=/var/run/icecast.pid

[Install]
WantedBy=multi-user.target