Showing posts with label computer related stuff. Show all posts
Showing posts with label computer related stuff. Show all posts

07 May 2015

On Debian's init process

Are you tired of badly written, complex, buggy and generally shitty init systems on Debian based systems?
Do you wonder what certain Debian developers have been smoking lately?
Do you think upstart, systemd and the likes need to stay the fuck away from your otherwise pretty stable Debian systems and do you long for the simpler SysV days?
Yeh, me too.

apt-get install sysvinit systemd-
or

apt-get install sysvinit upstart-

takes care of it.
That's all.

19 March 2014

Unsetting a trap

Quick one: catching a trap in bash is fairly easy with bash' trap command (search for 'trap \[' in bash' man page) but how to clear a set one?
It's in the man page, of course, but who reads those, right? I'm betting the answer is bound to be found on some blog through Google in 0.76 seconds flat ;)
"If arg is absent (and there is a single sigspec) or -, each specified signal is reset to its original disposition (the value it had upon entrance to the shell)."
So it turns out it's fairly simple and this demonstrates it:
root@mgmtsrv:~# cat test.sh
#!/bin/bash
trap 'echo TRAPPED!; break' SIGINT
while [ True ]; do
        sleep 1
done
echo 'end of script'
exit 0
root@mgmtsrv:~# ./test.sh
^CTRAPPED!
end of script
root@mgmtsrv:~#
Now, let's unset the trap:

root@mgmtsrv:~# cat test.sh
#!/bin/bash
trap 'echo TRAPPED!; break' SIGINT
while [ True ]; do
        sleep 1
done
trap - SIGINT
while [ True ]; do
        sleep 1
done
echo 'end of script'
exit 0
root@mgmtsrv:~# ./test.sh
^CTRAPPED!
^C
root@mgmtsrv:~#
So, in short: the 'trap - SIGINT' line clears the set trap :)

05 February 2014

On loopback device creation

I was having some problems with loop back device creating & almost immediately detaching; it seems sometimes a kernel thread holds on to the device and the detach fails.
I decided to have a look what's going on so I created a script which automates the creation, attaching and detaching of loopback devices:


# ./test.sh

Creating sparse 4TB file: Done
----START----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
----NEXT PASS----
Loopback devices currently in use:
/dev/loop0
Checking for free loopback device: /dev/loop1
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
----NEXT PASS----
Loopback devices currently in use:
/dev/loop0
/dev/loop1
Checking for free loopback device: /dev/loop2
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
----NEXT PASS----
Loopback devices currently in use:
/dev/loop0
/dev/loop1
/dev/loop2
Checking for free loopback device: /dev/loop3
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
----NEXT PASS----
Loopback devices currently in use:
/dev/loop0
/dev/loop1
/dev/loop2
/dev/loop3
Checking for free loopback device: /dev/loop4
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
----NEXT PASS----
Loopback devices currently in use:
/dev/loop0
/dev/loop1
/dev/loop2
/dev/loop3
/dev/loop4
Checking for free loopback device: /dev/loop5
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
----NEXT PASS----
Loopback devices currently in use:
/dev/loop0
/dev/loop1
/dev/loop2
/dev/loop3
/dev/loop4
/dev/loop5
Checking for free loopback device: /dev/loop6
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
----NEXT PASS----
Loopback devices currently in use:
/dev/loop0
/dev/loop1
/dev/loop2
/dev/loop3
/dev/loop4
/dev/loop5
/dev/loop6
Checking for free loopback device: /dev/loop7
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
----NEXT PASS----
Loopback devices currently in use:
/dev/loop0
/dev/loop1
/dev/loop2
/dev/loop3
/dev/loop4
/dev/loop5
/dev/loop6
/dev/loop7
Checking for free loopback device: losetup: could not find any free loop device
Exiting, couldn't find any free device any more.
So if done fast enough the pool quickly gets depleted as giving back (detaching) the device fails. A second or so later it might work, though. But let's test how much time exactly is needed to free the device? I modified the script to keep trying to detach/free the loopback device and see what happens:

Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 4 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 2 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 6 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 1 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 3 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 3 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.

Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 2 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 3 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 2 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 4 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 4 tries.
----NEXT PASS----
Loopback devices currently in use:

Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 1 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 5 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 10 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 2 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 4 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 4 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 3 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
Loopback device broken down after 0 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 4 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 3 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 2 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
Loopback device broken down after 0 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 1 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 3 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 2 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 1 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 2 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 1 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
Loopback device broken down after 1 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: ^C
So it varies. The device might get released instantaneously, but that doesn't happen too often, or it might take 10 consecutive tries. Let's see if allowing half a second's worth of pause in between creating and detaching fix the problem,

# ./test.sh
Creating sparse 4TB file: Done
----START----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0.5 seconds.
Breaking down loopback device:
Loopback device broken down after 0 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0.5 seconds.
Breaking down loopback device:
Loopback device broken down after 0 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0.5 seconds.
Breaking down loopback device:
Loopback device broken down after 0 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0.5 seconds.
Breaking down loopback device:
Loopback device broken down after 0 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0.5 seconds.

^C
It does, but what's holding on to the device exactly? I modified the script again to look up the did in the process table. This takes time of course, so the detaching phase took less tries to complete:

# ./test.sh
Creating sparse 4TB file: Done
----START----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
root     25417  0.0  0.0      0     0 ?        S<   13:25   0:00 [loop0]
Loopback device broken down after 1 tries.
----NEXT PASS----
Loopback devices currently in use:
Checking for free loopback device: /dev/loop0
Setting up loopback device: Done
Sleeping for 0 seconds.
Breaking down loopback device:
loop: can't delete device /dev/loop0: Device or resource busy
root     25437  0.0  0.0      0     0 ?        S<   13:25   0:00 [loop0]
Loopback device broken down after 1 tries.
----NEXT PASS----
Loopback devices currently in use:
^C
Right, so it's Linux that's holding on to it and I'm not sure if I like this behavior. I realize losetup can only request Linux to free up the device and it does cleanly report a 'Device or resource busy' but I don't understand why it just doesn't wait a bit until the resource is cleared from the kernel, or at least provides the option to the user to do so. I thought about pathing losetup but now I can't be bothered anymore, so I'm just putting it out there :)

18 December 2013

On bypassing mdadm's interactive mode

So I wanted mdadm to not go interactive, ever, but instead just bail out whenever something happens it doesn't understand; you'd think the developers would have thought of that, right? Turns out they haven't.
The 'fix' is easy enough though: pipe /bin/false through mdadm by default so it'll get a 'false' every time it would be looking for user input; effectively making it bail out whenever something's off:

alias mdadm="/bin/false | /sbin/mdadm"

04 December 2013

On quickly creating sparse and large files

I've been using dd(1) for as long as I can remember to create sparse files but for some reason I keep forgetting how to use dd's argument options so I set out to find something better... and found it: truncate(1):

From the man page: "Shrink or extend the size of each FILE to the specified size. A FILE argument that does not exist is created." -looking good:

root@debian64:~# time truncate -s 10T testfile

real0m0.003s
user0m0.000s
sys 0m0.004s

root@debian64:~# ls -l testfile
-rw-r--r-- 1 root root 10995116277760 Dec4 10:27 testfile

root@debian64:~# du -hs testfile
0 testfile

Awesome!
So then I set out to find me something to quickly allocate 'real' files:

fallocate(1):
"fallocate  is used to preallocate blocks to a file.  For filesystems which support the fallocate system call, this is done quickly by allocating blocks and marking them as uninitialized, requiring no IO to the data blocks.  This is much faster than creating a file by filling it with zeros."

And it truly is fast:


root@debian64:~# time fallocate -l 1G testfile

real    0m0.004s
user    0m0.000s
sys     0m0.000s

root@debian64:~# du -hs testfile
1.1G    testfile

root@debian64:~# ls -l testfile
-rw-r--r-- 1 root root 1073741824 Dec  4 10:34 testfile


01 October 2013

On OverlayFS and distilling patches (or: how to get OverlayFS)

So, I was looking at unionfs alternatives and I wanted to try overlayfs.
You'd think a project almost begging to be merged into mainline Linux would be interested in getting some traction amongst the "regular" Linux crowd and actually provide some patches making it relatively easy to try out the code until the time finally comes they're part of mainline, right?
Well, apparently you'd be wrong assuming that: getting a clean OverlayFS patch requires distilling a diff from a patched Linux source tree on git and that is left as an exercise to the user... or simply use Ubuntu's or SuSE's kernels (no...fucking...way) as those are already patched it seems.
Anyways, this is how to do it:

Branch overlayfs.v18 is intended to work with Linux 3.10.x:
https://git.kernel.org/cgit/linux/kernel/git/mszeredi/vfs.git/tree/Makefile?h=overlayfs.v18
Git clone the overlayfs.v18 branch:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git -b overlayfs.v18 overlayfs.v18
From the git log I got they merged Linux 3.10-rc7 so that's the branch we're going to diff to. Adding a new remote repo to the overlayfs.v18 local repo and fetching the v3.10-rc7 branch from it (git fetching won't actually change the local code!):
cd overlayfs.v18
git remote add v3.10-rc7 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux
git fetch v3.10-rc7
Now all we have to do is the actual git diff:
git diff v3.10-rc7/master...HEAD > ../overlayfs-v18.patch
So let's try to patch our Linux 3.10.12 tree :
root@bob:/usr/src/linux# patch -p1 --dry-run < ../overlayfs-v18.patch 
patching file Documentation/filesystems/Locking
patching file Documentation/filesystems/overlayfs.txt
patching file Documentation/filesystems/vfs.txt
patching file MAINTAINERS
patching file fs/Kconfig
patching file fs/Makefile
patching file fs/ecryptfs/main.c
patching file fs/internal.h
patching file fs/namei.c
patching file fs/namespace.c
patching file fs/open.c
patching file fs/overlayfs/Kconfig
patching file fs/overlayfs/Makefile
patching file fs/overlayfs/copy_up.c
patching file fs/overlayfs/dir.c
patching file fs/overlayfs/inode.c
patching file fs/overlayfs/overlayfs.h
patching file fs/overlayfs/readdir.c
patching file fs/overlayfs/super.c
patching file fs/splice.c
Hunk #1 succeeded at 1313 (offset 1 line).
patching file include/linux/fs.h
patching file include/linux/mount.h
root@bob:/usr/src/linux#

Lookin' good, w00t!

31 July 2013

On Linux patches and diffs

So you're running your own customized Linux, and want to stay up-to-date a bit, right?

root@box:/usr/src/linux# patch -p1 --dry-run < ../patch-3.10.4
patching file Documentation/i2c/busses/i2c-piix4
Reversed (or previously applied) patch detected!  Assume -R? [n] ^C

So what's happening here is that 'patch-3.10.4' from kernel.org actually is a diff from 3.10 to 3.10.4, not from 3.10.3 to 3.10.4.
This'd be fine except that you've already applied patch-3.10.3 the day before yesterday and you don't want to keep track of which patches are already applied and stuff, you just want to see whether or not the new 3.10.4 patches apply without problems.
Plus you've got other patches applied as well so you really just want to have a patch with the changes form one minor release to the other, right?
So that's where interdiff comes into play:

interdiff patch-3.10.3 patch-3.10.4 > patch-3.10.3-to-3.10.4

Now we have a patch that only includes the changes from 3.10.3 to 3.10.4 and that can be applied directly and cleanly to our already patched-with-the-previous-version-and-other-stuff-as-well Linux tree.

On apache's mod_proxy

Another short one, a warning; a 'heads up' if you will.
Took me some time to figure out that Apache's mod_proxy actually requires the proxied service to be accessible when Apache itself starts.
It seems logical enough writing it down now, but when I was configuring mod_proxy to work with apt-cacher it sure wasn't clear looking at the log files.
So when you're playing around with mod_proxy and a random to-be-proxied service, make sure to reload/restart the service first (and verify everything working alright) and only then reload Apache to take the new mod_proxy settings into effect.

07 March 2013

Debugging a slow KDE session.

KDE (from the Kubuntu repo) and all QT applications were slow as hell after an update so I set out to investigate:

The most obvious one to start with was kopete (sloooooooooooooow), so I straced (strace -s 500 -f kopete) and it hung on this:


11574 recvmsg(6, 0x7fffb90ddde0, MSG_CMSG_CLOEXEC) = -1 EAGAIN (Resource temporarily unavailable)
11574 sendmsg(6, {msg_name(0)=NULL, msg_iov(2)=[{"l\1\0\1\0\0\0\0\t\0\0\0o\0\0\0\1\1o\0\26\0\0\0/modules/networkstatus\0\0\6\1s\0\f\0\0\0org.kde.kded\0\0\0\0\2\1s\0\37\0\0\0org.kde.Solid.Networking.Client\0\3\1s\0\6\0\0\0status\0\0", 128}, {"", 0}], msg_controllen=0, msg_flags=0}, MSG_NOSIGNAL) = 128
11574 poll([{fd=6, events=POLLIN}], 1, 25000

It's hanging on handler 6, going up in the output I found what 6 is:

11368 socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC, 0) = 6
11368 connect(6, {sa_family=AF_FILE, path=@"/tmp/dbus-TNffZVatPK"}, 23) = 0
11368 fcntl(6, F_GETFL)                 = 0x2 (flags O_RDWR)
11368 fcntl(6, F_SETFL, O_RDWR|O_NONBLOCK) = 0
11368 geteuid()                         = 1000
11368 getsockname(6, {sa_family=AF_FILE, NULL}, [2]) = 0

Right, so kopete is slow because it's waiting to receive something sent through dbus to kded.
Let's try to use dbus to contact kopete manually:


timothy@xps:~$ time qdbus org.kde.kopete                                         Error: org.freedesktop.DBus.Error.NoReply
Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
real    0m25.018s
user    0m0.004s
sys     0m0.008s


It timed out, let's try it again:


timothy@xps:~$ time qdbus org.kde.kopete
/
/KDebug
/KIO
/KIO/Scheduler
/Kopete
/MainApplication
/ManagerIface_contact
/Statistics
/kopete
/kopete/MainWindow_1
/kopete/MainWindow_1/actions
/kopete/MainWindow_1/actions/settings_prefs
/kopete/MainWindow_1/actions/file_quit
/kopete/MainWindow_1/actions/settings_showmenubar
/kopete/MainWindow_1/actions/settings_showstatusbar
/kopete/MainWindow_1/actions/settings_keys
/kopete/MainWindow_1/actions/options_configure_toolbars
/kopete/MainWindow_1/actions/settings_notifications
/kopete/MainWindow_1/actions/AddGroup
/kopete/MainWindow_1/actions/contactSendMessage
/kopete/MainWindow_1/actions/contactStartChat
/kopete/MainWindow_1/actions/contactMove
/kopete/MainWindow_1/actions/contactCopy
/kopete/MainWindow_1/actions/makeMetaContact
/kopete/MainWindow_1/actions/contactRemove
/kopete/MainWindow_1/actions/contactSendEmail
/kopete/MainWindow_1/actions/contactSendFile
/kopete/MainWindow_1/actions/contactAddContact
/kopete/MainWindow_1/actions/contactAddTemporaryContact
/kopete/MainWindow_1/actions/contactProperties

real    0m3.720s
user    0m0.028s
sys     0m0.004s


So now it works. Consistent with what I'm experiencing in the KDE session right now.
Everything works, more or less, but it's all extremely slow.
Let's have a look at kded:


timothy@xps:~$ qdbus org.kde.kded
Error: org.freedesktop.DBus.Error.NoReply                                        Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.                         


I want to see what's kded's problem, let's look at it's status:


timothy@xps:~$ ps aux | grep kded
timothy  10298  0.0  0.3 793672 29280 ?        Sl   10:06   0:00 kdeinit4: kded4 [kdeinit]                     
timothy  10455  0.0  0.1 414756 11236 ?        Sl   10:06   0:00 kdeinit4: kio_trash [kdeinit] trash local:/tmp/ksocket-timothy/klauncherT10296.slave-socket local:/tmp/ksocket-timothy/kdeda10298.slave-socket
Sleeping eh, could be worse. Let's see what's it actually is doing/hanging on:
timothy@xps:~$ gdb kdeinit `pidof kded4`
[... lots of stuff...]
(gdb) bt
#0  0x00007f6aa1952023 in select () at ../sysdeps/unix/syscall-template.S:82
#1  0x00007f6aa2d99366 in qt_safe_select(int, fd_set*, fd_set*, fd_set*, timeval const*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#2  0x00007f6aa2d466da in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#3  0x00007f6aa2d47fab in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#4  0x00007f6aa2d0248e in QProcess::waitForFinished(int) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#5  0x00007f6aa31def32 in KProcess::execute(int) () from /usr/lib/libkdecore.so.5
#6  0x00007f6a80f3f1a5 in ?? () from /usr/lib/kde4/kded_notificationhelper.so
#7  0x00007f6a80f3bca5 in ?? () from /usr/lib/kde4/kded_notificationhelper.so
#8  0x00007f6a80f39ad4 in ?? () from /usr/lib/kde4/kded_notificationhelper.so
#9  0x00007f6a80f39d24 in ?? () from /usr/lib/kde4/kded_notificationhelper.so
#10 0x00007f6aa2d86446 in QObject::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#11 0x00007f6aa20ef894 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#12 0x00007f6aa20f4713 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#13 0x00007f6aa3b063f6 in KApplication::notify(QObject*, QEvent*) () from /usr/lib/libkdeui.so.5
#14 0x00007f6aa2d6ce9c in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#15 0x00007f6aa2d70c6a in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#16 0x00007f6aa2d9bf93 in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#17 0x00007f6a9ea5fd53 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#18 0x00007f6a9ea600a0 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#19 0x00007f6a9ea60164 in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#20 0x00007f6aa2d9c3bf in QEventDispatcherGlib::processEvents(QFlags) ()
   from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#21 0x00007f6aa2197d5e in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#22 0x00007f6aa2d6bc82 in QEventLoop::processEvents(QFlags) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#23 0x00007f6aa2d6bed7 in QEventLoop::exec(QFlags) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#24 0x00007f6aa2d70f67 in QCoreApplication::exec() () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#25 0x00007f6a8f4fde55 in kdemain () from /usr/lib/kde4/libkdeinit/libkdeinit4_kded4.so
#26 0x00000000004086a4 in _start ()
So we're in the kded_notificationhelper.so module. Let's see what I've got on my system mathing that name:

timothy@xps:~$ dpkg -l | grep "notification-helper"
ii  kubuntu-notification-helper            11.10ubuntu1                            Kubuntu system notification helper

Seems fishy.

timothy@xps:~$ apt-cache show kubuntu-notification-helper
Package: kubuntu-notification-helper
Priority: optional
Section: kde
Installed-Size: 212
Maintainer: Kubuntu Developers
Original-Maintainer: Jonathan Thomas
Architecture: amd64
Version: 11.10ubuntu1
Depends: libc6 (>= 2.4), libkdecore5 (>= 4:4.4.95), libkdeui5 (>= 4:4.4.0), libqt4-dbus (>= 4:4.5.3), libqtcore4 (>= 4:4.7.0~beta1), libqtgui4 (>= 4:4.5.3), libstdc++6 (>= 4.1.1), konsole | x-terminal-emulator, qapt-batch
Recommends: apport-kde | apport-gtk
Filename: pool/main/k/kubuntu-notification-helper/kubuntu-notification-helper_11.10ubuntu1_amd64.deb
Size: 38114
MD5sum: 0c6b775a0f78cbdb138149ea0e32b60b
SHA1: 2f2c37f9d16a094ac6f215c22c6cb558f6e5eada
SHA256: 8a96a2b822e825d3d56d7dcba732061576b690077bd73ff5ddcfd896192399bf
Description-en: Kubuntu system notification helper
 Kubuntu Notification Helper is a daemon that presents various notifications
 to the user. It uses the KDE Daemon system as a base and presents the
 notifications using the KDE Notification system. It also includes a
 System Settings module for configuring the daemon. Kubuntu Notification
 Helper is lightweight and fully integrated with KDE.
 .
 Current features include:
  - Notifications for Apport crashes.
  - Notifications for upgrade information, when available.
- Notifications for the availability restrictively-licensed packages.
  - Notifications for when upgrades require a reboot to complete.
  - All notifications can be hidden temporarily or permanently.
Homepage: https://launchpad.net/kubuntu-notification-helper
Description-md5: cfe41fe07651879c49f8ca54be0c1170
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
Task: kubuntu-desktop, kubuntu-full, kubuntu-active-desktop, kubuntu-active-full, kubuntu-active, edubuntu-desktop-kde

Ubuntu bloatware I can perfectly do without, check.

timothy@xps:~$ sudo apt-get remove --purge kubuntu-notification-helper
Reading package lists... Done
Building dependency tree     
Reading state information... Done
The following packages will be REMOVED:
  kubuntu-notification-helper*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 217 kB disk space will be freed.
Do you want to continue [Y/n]?
(Reading database ... 296995 files and directories currently installed.)
Removing kubuntu-notification-helper ...

After a KDM restart everything is back to normal AND that annoying pop up 'there's are X software updates' thing is gone...

10 January 2013

On waking up computers

Introducing something I've been working on: http://code.google.com/p/wurmd/

"Wurmd tries to solve the common problem when using Wake-On-Lan on your server/desktop/fridge/... that once it's asleep it has to be woken up again, which usually is a manual operation the user has to perform. Having the device go to sleep isn't the problem but having to fire up an additional program to wake the device back up can become a PITA after some time.
The logical next step would be to incorporate WoL functionality into programs itself, but that's hardly feasible. Sure, you may get the XBMC crew to write code so if a file share isn't online it'll automagically sends a WoL packet, but that's limited to XBMC, right? What if you want to access your file server at home from your favorite file explorer but it's asleep again?
Wurmd is a standalone program that listens on an interface in the background for initial connections to your configured devices. If it detects such a connection it'll send a WoL packet to the device to wake it up. What this means, practically, is that as long as wurmd is running on the host you can use any program to make a connection with a sleeping device and wurmd will wake it up. Your program probably won't even know what happened.
Binaries are available for both x86_64 and Raspberry Pi's architecture, ARMv6. Packages for various Linux distributions are forthcoming and I might even build an OSX binary."

I guess it's not ready for prime-time yet and there's hardly any error-handling, but it's functional.
I've been running it on my laptop and on my OpenELEC Raspberry Pi for some time now and I quite like it; YMMV.

30 October 2012

imapsync revisited

Reading around the interwebs I've gained a little insight in what's happened to imapsync: the author wanted to make some money on the project and decided to change the license.
Next the Debian maintainer wasn't comfortable anymore packaging it and asked the author whether he still wanted Debian to ship imapsync... guess what the answer was[1]
Now, the gitsource repo I wrote about earlier is from a guy who's bought a license from the author, so as far as I can see he's got the right to put up the source[2].
Which, in turn, gives me the right to clone the repo, package the script and put it up here.

The package only depends on perl and libmail-imapclient-perl so it shouldn't matter which distribution you install it on, as long as it's a Debian derivative.
So, there ya go [3], install with sudo dpkg -i.


[1] http://lists.debian.org/debian-legal/2011/01/msg00044.html
[2] http://www.linux-france.org/prj/imapsync_list/msg01371.html
[3] http://bin.syphzero.net/imapsync-1.508_all.deb

13 October 2012

Disable UPnP on Scarlet's Sagem F@st3464 DSL bridge

Quickie:

telnet 192.168.1.1
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is '^]'.
login: admin
Password: ******** (OLOVDSL2)
[admin @ home]$ rg_conf_print upnp/enabled
(enabled(1))

Returned 0
[admin @ home]$ rg_conf_set upnp/enabled 0

Returned 0
[admin @ home]$ rg_conf_print upnp/enabled
(enabled(0))

Returned 0
[admin @ home]$ Connection closed by foreign host.

That's it.

24 September 2012

Preferring IPv4 over IPv6.

As more and more hosts are moving over to IPv6, you might encounter DNS A records with IPv6 entries.
That's all fine and dandy and I do realize the need for an extended IP address pool, but if it's starting to affect performance I say fuck IPv6.
Sadly, modern GNU/Linux systems prefer IPv6 addresses over IPv4 when being presented with a choice. I honestly don't see why the fuck IPv6 should be preferred right now as it's bound to be a lot slower on a lot of networks, for the time being at least.
Case in point: Debian's apt-get update over IPv4 and IPv6:

root@box:~# host security.debian.org
security.debian.org has address 195.20.242.89
security.debian.org has address 212.211.132.32
security.debian.org has address 212.211.132.250
security.debian.org has IPv6 address 2001:a78:5:1:216:35ff:fe7f:6ceb
security.debian.org has IPv6 address 2001:8d8:580:400:6564:a62:0:2
security.debian.org has IPv6 address 2001:a78:5:0:216:35ff:fe7f:be4f
security.debian.org mail is handled by 10 chopin.debian.org.

IPv6:
root@box:~# time apt-get update
[...]
real    1m18.222s
user    0m7.472s
sys     0m6.948s
IPv4:
root@box:~# time apt-get update
[...]
real    0m13.481s
user    0m7.728s
sys     0m5.332s
We could just add static ipv4 lines in /etc/hosts, but that's kinda defeating the purpose as we don't want to disable IPv6 altogether.
So, how do we tell the system to prefer IPv4 addresses over IPv6?
It's rather simple, actually: we need to have a look at getaddrinfo(3)'s configuration file; /etc/gai.conf.
Locate this line and uncomment it:
#precedence ::ffff:0:0/96  100
There ya go, IPv4 is preferred now.
This works as that's the special address range to help in the transition from 4 to 6; every IPv4 address can be written as an IPv6 one using that form.
Anyways, the format is ::ffff:0:0/96 which means that the ipv4 ip address 192.168.18.234/32 will be written as 0:0:ffff:192.168.18.234/128 and will match that line in gai.conf.

19 July 2012

Ubuntu to Debian

It happened again today and I hate it when it happens:
Ubuntu on a server...sigh
"But Ubuntu is Debian and you love Debian, why do you hate Ubuntu so much then?"
No it's not Debian, it's Ubuntu. (Oh and btw: OSX isn't BSD, Darwin is BSD... sort of.)
"But Ubuntu is so much easier than Debian..."
Yeh well, Hitler thought exterminating an entire group of people was easier than just dealing with them.
"Ubuntu LTS has long time support and is commercially supported..."
Get away from me, suit, go hug an SLA or something.
Ubuntu is bloated and I don't want it anywhere near my servers... and upstart is evil.
Not the cool evil like Behemoth, more like the bad evil like Codemasters.
So I guess I overreacted a bit and converted the Crabuntu into Debian, I've done that a couple times before and it works fine but every time I do it something unexpected happens so don't take this guide too literal.


Disclaimer: but of course I am fully responsible for what you do to you system, this won't hurt your system at all and nothing stated in this disclaimer is a lie...

First I'm going to delete everything:


dpkg -l | awk '{print $2}' | xargs --replace dpkg --purge {}

We can totally do this as the most important stuff will refuse to purge. Next, let's make apt decide what the system can do without:


apt-get autoremove

Now purge every package which only has configuration files on the system:


dpkg -l | grep ^rc | awk '{print $2}' | xargs --replace dpkg --purge {}

Good, not too much is left on the system. Let's upgrade those packages to their Debian counterparts:

echo "deb ftp.de.debian.org/debian testing main contrib non-free" > /etc/apt/sources.list

apt-get update


Install the Debian version of apt-utils as we're going to need it:


apt-get install apt-utils

Upgrade everything:


dpkg -l | awk -F' ' '{print $2}' | xargs --replace apt-get install -y --force-yes {}

Remove those pieces of shit:



dpkg --purge --force-all upstart
dpkg --purge --force-all mountall
dpkg --purge --force-all plymouth

Install something decent:


apt-get install sysvinit

Reinstall grub (not so important I think)


apt-get install grub2

Reinstall a kernel, might be useful sometimes:


apt-get install linux-base  linux-image-amd64

Throw away everything else Ubuntu related:


dpkg -l | grep ubuntu | awk '{print $2}' | xargs --replace apt-get remove --purge {} -y

I like openssh:


apt-get install openssh-server

If it's good enough for Linus, it's good enough for me:

sync
sync
sync


Reboot right the fuck now:





reboot -fn

TADA.... and gone is the Ubuntu crap.

02 July 2012

imapsync


Today I found out the immensely useful tool imapsync isn't free anymore.
A bit of browsing around and I found the source on github, I'm going to assume that being the last free version.

apt-get install libmail-imapclient-perl
apt-get install libterm-readkey-perl
apt-get install libauthen-ntlm-perl
git clone https://github.com/imapsync/imapsync.git
cd imapsync
make
./imapsync

There.

Now, the license file literally says to do whatever the fuck you want to do with it, so I'm going to do just that.
Stay tuned.

30 May 2012

On local name resolving on Linux

Local name resolving in Linux distros can get confusing.
Case in point: man hostname(1)

Anyways, our fictional situation for today is this:

hostname: what you've named your machine
domainname: which domain you're on.
FDQN: hostname+domainname
You've probably named your machine something but didn't include the record into the domain's DNS.
Then you're trying to use hostname -a or hostname -f and get this error:

hostname: Name or service not known

You need to check 2 files if that happens: /etc/hostname and /etc/hosts.
This is what you should have (provided, of course, you're not running a NIS/YP and you're using a hostname which isn't configured domain's DNS):

/etc/hostname should contain 1 line: the hostname of the host.
If you do write the FDQN in there, no problem, it gets parsed anyhow.
I found out about this just about half an hour ago when looking into a problem together with a colleague.
/etc/hosts should contain at least 1 line with:

127.0.0.1   FQDN hostname

The order is /etc/hosts is important.
 The hostname in /etc/hosts and the hostname in /etc/hostname must be identical.

27 May 2012

Making working on Windows bearable.

First things first: I've got Windows 7 installed on my laptop.
Line 6 software for my Pod just doesn't work under Wine so I had to have at least one machine running either OSX or Windows and I absolutely, positively, passionately fucking hate OSX, every time I see someone using it I throw up a little in my mouth.
Not that I hate Apple though, their hardware is insanely overpriced, but decent and I'm a big fan of the (old) iPods. Apple users and I on the other hand aren't usually best friends, we see stuff differently I guess.
I like to think a computer should stfu and do what I want it to do, how I want it to do it, not the other way around.
'Think different'... but for some reason the vast majority of their OSX users willingly plugged themselves into the Apple corporate HQ's controlled hive mind, oh the irony almost kills me sometimes.
But anyways, of course I use the laptop for more stuff than just music related stuff but the thing is over the years I've grown accustomed to software I use on my other machines... which run Debian mostly.
So here's a list of stuff I use, maybe it's useful to some poor geek finding him/herself forced using Windows:

* Amarak (http://amarok.kde.org/wiki/Download:Windows): Face it, there's not a single music player on Windows that matches Amarok. Even if it's the sucky version from KDE4 without iPod support, it's still better than everything else out there.
* Kate (http://windows.kde.org/): My preferred editor. Personal preference mostly I think. Has some pretty cool stuff I like.
* GMusic: (http://gmusic.codeplex.com/): Google Music is awesome! Standalone app to GMusic (not official though), running it in a browser blows, even more so on Windows.
* Audacity (http://audacity.sourceforge.net/): Almost as good as on my preferred platform but that's not Audacity's fault. Windows' access to lower level hardware is laughable but for some reason I don't find it funny.
* NX (http://www.nomachine.com/): I hate VNC with a passion and I don't want to run an X server on my Windows machines just to be able to tunnel X sessions. NX rocks, try it out.
* VLC (http://www.videolan.org/vlc/index.html): pretty popular even among Windows users I heard. Listed for completeness as, of course, you don't want to use Media Player.
* Handbrake (http://handbrake.fr/downloads.php): I w00ted when I found out this exists for Windows as well. Fits all my video transcoding needs.
* GIMP (http://www.gimp.org/): I don't need Photoshop, Gimp is good enough for the stuff I do.
* Truecrypt (http://www.truecrypt.org/): No dm-crypt so this fits all my encrypting needs on Windows.
* Chrome (https://www.google.com/chrome): duh.
* Pidgin (http://www.pidgin.im/): IM, all of them.
* Google Talk (http://www.google.com/talk/): Standalone. Mostly for the video calling feature. Skype is meh.
* 7-zip (http://www.7-zip.org/): Supports every compression algorithm I'll ever need.
* Cygwin (http://www.cygwin.com/): I need a decent shell and CLI tools. cmd.exe is lmfao.
* Perl (through Cygwin): same reason as Cygwin.
* OpenSSH (through Cygwin): having to use PuTTY makes my skin crawl and my blood boil, it's a program written by clickety click users for clickety click users.

That's about it.

16 May 2012

Removing audio devices in KDE4

Whenever I lock my KDE4 desktop there's no telling which audio output device I'll get.
I set it to 'Analog Stereo Output' in System Settings/Multimedia/Phonon/Audio Hardware Setup but more often than not Phonon/KDE4 (no idea what is responsible)  changes its setting to 'Digital Stereo (HDMI) Output'. It's possible to change it through Kmix as well, but it's the same UI as far as I can see.
No /etc/phonon config file to be found, so it must be a KDE component... fucking brilliant.
Of course there's no way to clickety-click remove audio devices from within KDE, that'd be too straightforward, right?
Anyways, I set out to find a config file and delete those #$(%#$ HDMI audio output entries.

~/.kde/share/config/phonondevicesrc

Entries are like this:

[AudioDevice_HDA Intel, HDMI 0\nHDMI Audio Output_playback]
cardName=HDA Intel, HDMI 0 (HDMI Audio Output)
deleted=false
deviceNumber=-1
hotpluggable=false
iconName=audio-card
index=-6
initialPreference=30
isAdvanced=false

So I just changed the deleted=false like to true for all HDMI devices.
Problem solved.

Thanks, KDE, once again... KDE 4.7 and still not on 3.5's level of functionality.

12 April 2012

KDE4 multiple screen handling

So in the good old days XFree/Xorg handled monitor configuration but apparently that was working out too well so nowadays the desktop managers are in control... sigh.

It's been 4 years since the KDE guys released 4.0 and configuring multiple monitors still doesn't work.
You'd think the 'Save as Default' button in the 'Size and Orientation' section of 'System Settings' would work, wouldn't you?
Well, think again, it still doesn't.


Introducing a nice little program called 'xrandr'.
Install it, run it, save its configuration in ~/.kde/env/ so it gets loaded at the same time KDE loads and you're done.
It'll even work when no external monitor is connected, so no weirdness anymore.

Btw:
http://www.trinitydesktop.org
It's a fork of KDE 3.5 made to run on modern day distros.
KDE 3.5, which, as we all know, was almost perfect.
It even includes the old Amarok (yes, ipod sync included).

14 March 2012

PS3 Mediatomb Debian configuration - cont.

I recently made some improvements to my mediatomb setup, so here's my config file.
It now does some server-side transcoding for stuff the PS3 doesn't have native support for like Vorbis audio, video codecs and iso images.
It's not perfect yet, but it works for most of the stuff I've got.
The mediatomb xml is pasted first, then the support scripts which handle the video transcoding, just don't forget to chmod +x them (they can be used standalone as well btw).

/etc/mediatomb/config.xml:


<?xml version="1.0" encoding="UTF-8"?>
<config version="2" xmlns="http://mediatomb.cc/config/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/config/2 http://mediatomb.cc/config/2.xsd">
  <server>
    <ui enabled="yes" show-tooltips="yes">
      <accounts enabled="no" session-timeout="30">
        <account user="mediatomb" password="mediatomb"/>
      </accounts>
    </ui>
    <name>[NAME]</name>
    <udn>uuid:dae13796-e78c-486c-ab54-f79c144a20f3</udn>
    <home>[PATH_TO_HOME]</home>
    <webroot>/usr/share/mediatomb/web</webroot>
    <storage caching="yes">
      <sqlite3 enabled="no">
        <database-file>sqlite3.db</database-file>
      </sqlite3>
      <mysql enabled="yes">
        <host>localhost</host>
        <username>mediatomb</username>
        <database>mediatomb</database>
      </mysql>
    </storage>
    <protocolInfo extend="yes"/>
    <custom-http-headers>
      <add header="X-User-Agent: redsonic"/>
    </custom-http-headers>
    <manufacturerURL>redsonic.com</manufacturerURL>
    <modelNumber>105</modelNumber>
    <extended-runtime-options>
      <ffmpegthumbnailer enabled="yes">
        <thumbnail-size>128</thumbnail-size>
        <seek-percentage>5</seek-percentage>
        <filmstrip-overlay>yes</filmstrip-overlay>
        <workaround-bugs>no</workaround-bugs>
        <image-quality>8</image-quality>
      </ffmpegthumbnailer>
      <mark-played-items enabled="no" suppress-cds-updates="yes">
        <string mode="prepend">*</string>
        <mark>
          <content>video</content>
        </mark>
      </mark-played-items>
    </extended-runtime-options>
  </server>
  <import hidden-files="no">
    <scripting script-charset="UTF-8">
      <common-script>/usr/share/mediatomb/js/common.js</common-script>
      <playlist-script>/usr/share/mediatomb/js/playlists.js</playlist-script>
      <virtual-layout type="builtin">
        <import-script>/usr/share/mediatomb/js/import.js</import-script>
      </virtual-layout>
    </scripting>
    <mappings>
      <extension-mimetype ignore-unknown="no">
        <map from="mp3" to="audio/mpeg"/>
        <map from="ogg" to="application/ogg"/>
        <map from="asf" to="video/x-ms-asf"/>
        <map from="asx" to="video/x-ms-asf"/>
        <map from="wma" to="audio/x-ms-wma"/>
        <map from="wax" to="audio/x-ms-wax"/>
        <map from="wmv" to="video/x-ms-wmv"/>
        <map from="wvx" to="video/x-ms-wvx"/>
        <map from="wm" to="video/x-ms-wm"/>
        <map from="wmx" to="video/x-ms-wmx"/>
        <map from="m3u" to="audio/x-mpegurl"/>
        <map from="pls" to="audio/x-scpls"/>
        <map from="flv" to="video/x-flv"/>
        <map from="avi" to="video/divx"/>
        <map from="mkv" to="video/x-matroska"/>
        <map from="mts" to="video/mpeg"/>
        <map from="ts" to="video/mpeg"/>
        <map from="m2ts" to="video/mpeg"/>
        <map from="mov" to="video/x-quicktime"/>
        <map from="vob" to="video/mpeg"/>
        <map from="m4v" to="video/mp4"/>
        <map from="vob" to="video/iso"/>
        <map from="VOB" to="video/iso"/>
        <map from="iso" to="video/iso"/>
        <map from="ISO" to="video/iso"/>
        <map from="img" to="video/iso"/>
        <map from="IMG" to="video/iso"/>
        <map from="rm"  to="video/realmedia"/>
        <map from="rmvb"  to="video/realmedia"/>
      </extension-mimetype>
      <mimetype-upnpclass>
        <map from="audio/*" to="object.item.audioItem.musicTrack"/>
        <map from="video/*" to="object.item.videoItem"/>
        <map from="image/*" to="object.item.imageItem"/>
      </mimetype-upnpclass>
      <mimetype-contenttype>
        <treat mimetype="audio/mpeg" as="mp3"/>
        <treat mimetype="application/ogg" as="ogg"/>
        <treat mimetype="audio/x-flac" as="flac"/>
        <treat mimetype="image/jpeg" as="jpg"/>
        <treat mimetype="audio/x-mpegurl" as="playlist"/>
        <treat mimetype="audio/x-scpls" as="playlist"/>
        <treat mimetype="audio/x-wav" as="pcm"/>
        <treat mimetype="video/x-msvideo" as="avi"/>
        <treat mimetype="video/quicktime" as="mov"/>
        <treat mimetype="video/x-quicktime" as="mov"/>
      </mimetype-contenttype>
    </mappings>
    <online-content>
      <YouTube enabled="no" refresh="28800" update-at-start="no" purge-after="604800" racy-content="exclude" format="mp4" hd="no">
        <favorites user="mediatomb"/>
        <standardfeed feed="most_viewed" time-range="today"/>
        <playlists user="mediatomb"/>
        <uploads user="mediatomb"/>
        <standardfeed feed="recently_featured" time-range="today"/>
      </YouTube>
    </online-content>
  </import>
  <transcoding enabled="yes">
    <mimetype-profile-mappings>
      <transcode mimetype="video/x-matroska" using="transcode-video"/>
      <transcode mimetype="video/x-flv" using="transcode-video"/>
      <transcode mimetype="video/x-quicktime" using="transcode-video"/>
      <transcode mimetype="video/realmedia" using="transcode-video"/>
      <transcode mimetype="application/ogg" using="vlcmpeg"/>
      <transcode mimetype="application/ogg" using="oggflac2raw"/>
      <transcode mimetype="audio/x-flac" using="oggflac2raw"/>
      <transcode mimetype="video/iso" using="video-iso"/>
    </mimetype-profile-mappings>
    <profiles>
      <profile name="transcode-video" enabled="yes" type="external">
          <avi-fourcc-list mode="ignore">
              <fourcc>DX50</fourcc>
              <fourcc>DM4V</fourcc>
              <fourcc>M4S2</fourcc>
          </avi-fourcc-list>
          <mimetype>video/mpeg</mimetype>
          <accept-url>yes</accept-url>
          <first-resource>yes</first-resource>
          <hide-original-resource>yes</hide-original-resource>
          <accept-ogg-theora>yes</accept-ogg-theora>
          <agent command="/usr/local/bin/transcode-video" arguments="%in %out"/>
          <buffer size="1048576" chunk-size="26214" fill-size="52428"/>
      </profile>
      <profile name="video-iso" enabled="yes" type="external">
          <mimetype>video/mpeg</mimetype>
          <first-resource>yes</first-resource>
          <hide-original-resource>yes</hide-original-resource>
          <accept-ogg-theora>yes</accept-ogg-theora>
          <agent command="/usr/local/bin/transcode-video-iso" arguments="%in %out"/>
          <buffer size="1048576" chunk-size="131072" fill-size="262144"/>
          </profile>
      <profile name="oggflac2raw" enabled="no" type="external">
        <mimetype>audio/L16</mimetype>
        <accept-url>no</accept-url>
        <first-resource>yes</first-resource>
        <accept-ogg-theora>no</accept-ogg-theora>
        <agent command="ogg123" arguments="-d raw -f %out %in"/>
        <buffer size="1048576" chunk-size="131072" fill-size="262144"/>
      </profile>
      <profile name="vlcmpeg" enabled="yes" type="external">
        <mimetype>video/mpeg</mimetype>
        <accept-url>yes</accept-url>
        <first-resource>yes</first-resource>
        <accept-ogg-theora>yes</accept-ogg-theora>
        <agent command="vlc" arguments="-I dummy %in --sout #transcode{venc=ffmpeg,vcodec=mp2v,vb=4096,fps=25,aenc=ffmpeg,acodec=mpga,ab=192,samplerate=44100,channels=2}:standard{access=file,mux=ps,dst=%out} vlc:quit"/>
        <buffer size="14400000" chunk-size="512000" fill-size="120000"/>
      </profile>
    </profiles>
  </transcoding>
</config>


/usr/local/bin/transcode-video:

#!/bin/bash
exec "/usr/bin/avconv" -i "$1" -vcodec mpeg2video -b 4096k -r 25 -acodec ac3 -ar 48000 -ac 2 -ab 448000 -f mpegts - > "$2"

 /usr/local/bin/transcode-video-iso:

#!/bin/bash
exec "/usr/bin/vlc" -v dvdsimple://"$1" -I dummy --sout "#transcode{vcodec=mpgv,vb=800,fps=25,acodec=mpga,ab=192,samplerate=48000,channels=2,deinterlace,soverlay,audio-sync}:standard{mux=ps,access=file,dst=$2" --sub-language=en vlc:quit >> /var/log/transcode.log 2>&1