ru Русский

Reticularium

NETWORKS PLACE

Well, I don’t know whether it was a good idea to make init scripts systems have dependencies, it had been perfectly simple and straightforward in FHS. And anyone could place scripts in needed order. Seems unnecessary automation to me, and KISS principle violation.

But what happened happened, and we have to live with it. Once it was a simple task to write a init script: just trivial case $1 in start) ;; stop) and so on. What we have now is a complete mess. If you google “missing LSB tags and overrides”, you’ll get the idea. Every init script needs special LSB headers now, but a lot of software just links some internal script to /etc/init.d during the install process, and there is no LSB headers. So you get a lot of complains from e.g. modern Debians and Ubuntus each time you install some package and even installation failures. Might be bad implementation though (insserv). Anyways, fortunately there is a good workaround (bad workaround that is often recommended being to uninstall insserv).

Just put the code below to an override file /etc/insserv/overrides/your_real_script_name

1
2
3
4
5
6
7
### BEGIN INIT INFO
# Provides:          your_init_script_name
# Default-Start:     2 3 5
# Default-Stop:      0 1 6
# Required-Start:
# Required-Stop:
### END INIT INFO

Note one thing that is not obvious: the name of the override file must be the same as your real script name, but inside the file the header “Provides:” must point to the init script name. Normally it is the same name, but in case you have symlinked a real file to /etc/init.d, and the symlink has a different name, it needs to be done like this, otherwise won’t work.

Useful to sync gems across servers. Converts gem list --local output to a bunch of gem install commands. Rails related gems are removed from the initial list.


gem list --local | grep -v '\*' | grep -v ^$ | grep -v ^action | grep -v ^active | grep -v ^rails | grep -v ^rack | grep -v ^rake | sed 's|(|-v=|' | sed 's|)||' | sed 's|^\(.*\),|\1\n\1|' | sed 's|=.*[[:space:]]|=|' | sed 's|^|gem install |'

In fact, it isn’t. Let me explain.

When you see the next time a complaint like this, note what exactly that complaint is related to. I mean operating system. I am sure you’ll find out that it’s some sort of binary distributives like Centos or Ubuntu. But they are not exactly Linux! They are what they are: Linux-based operating systems distributable in binary form. You can’t refer to them as to Linux, because 1) Linux is a kernel, not an operation system, and 2) being a monolithic kernel, it’s supposed to be carefully configured and compiled natively for each system. And operating system (GNU), should be compiled against this kernel. And the whole toolchain, too.

You might say, well, why does it matter? Is there any difference?

Yes, there is, and it’s huge. Let me show you.

Read the article

Command mount --rbind mounts recursively, which is handy, but umount has no recursive capabilities, so several umount commands are needed to unmount. The easiest way to do this is to look into /proc/mounts :

cat /proc/mounts

Even better:

cat /proc/mounts | awk '{print $2}'

Take a look and if you can grep needed mountpoints out of it, just add |grep <something> | sort -r | xargs umount to the above line.

This and a bit more here

With graphs!

Everybody knows that LOAD DATA INFILE is fast, many did benchmarks, but nobody cared to publish results with graphs, so that others could use them to illustrate the approach :) Thanks a lot, Kevin

I am used to ask Linux utility date about everything related to date/time, like date -d "next friday" or date -d "+245 min", but it doesn’t answer one question I have pretty often: what time is it now in certain timezone?

So I had to create a simple script for this:

1
2
3
4
5
6
7
#!/bin/bash

localtime=`date +"%x %X"`
zonediff=`date -d "$1" +"%H:%M"`
hours="`echo $zonediff | cut -d':' -f1` hours"
minutes="`echo $zonediff | cut -d':' -f2` minutes"
date -d "-$hours -$minutes" +"%x %X"

Zone here is represented by alphabetic abbreviation, that is if you named this script e.g. “timein”, you use it like this:

timein EDT

Old-time problem comes back: coreutils doesn’t roll back to calls supported by your older kernel. This results in errors like:


Failed 'touch .unpacked': No such file or directory

or:


Failed 'touch .unpacked': Bad address

Funny little helpful hack taken here

1
2
3
4
mv /bin/touch /bin/oldtouch
echo '#!/bin/sh' > /bin/touch
echo 'echo -n >> "$1"' >> /bin/touch
chmod +x /bin/touch

Don’t forget to restore it back later.

Just to save for future use..

passenger-memory-stats | sed 's|[^[:print:]]||g' | sed 's|\[44m\[1m\[33m||g' | sed 's|\[37m||g' | sed 's|\[0m||g'

I wonder why at all they use colors for the output. Since it’s the only way for Passenger based setups to get some info about memory usage, its output should have at least plain text option to be used in other scripts.

Taken from the Fedora forum

..........

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#modprobe dm-mod
#vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "VolGroup00" using metadata type lvm2
# vgchange -a y VolGroup00
# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
. . .
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
# mkdir /mnt/VolGroup00/01
# mount /dev/VolGroup00/LogVol01 /mnt/VolGroup00/01

Reference the man pages for lvm, pvdisplay, vgdisplay, lvcreate, lvdisplay, lvextend

..........

As you can see, you need two things: dm-mod kernel module and LVM2 package (apt-get install lvm2 on Debian, emerge lvm2 on Gentoo and so on)

My personal note: LVM provides several useful features but has one huge drawback. If your disk or file system crashes, you won’t be able to access your LVM partitions using any liveCD. At least I don’t know any that would have both dm-mod module and LVM2 package.

For some reason the example below taken from Apache documentation didn’t work for me

1
2
3
4
5
<Proxy balancer://mycluster>
BalancerMember http://192.168.1.50:80
BalancerMember http://192.168.1.51:80
</Proxy>
ProxyPass /test balancer://mycluster

That is, it did work, but mod_dir was adding trailing slashes to both host and path, like this: http://www.example.com/mypath --> http://www.example.com//mypath/ if it found mypath to be a directory of course.

Well, perhaps there is some reason for this that I couldn’t find, but the working solution I found is to add slashes to BalancerMember declarations, like so:

1
2
3
4
5
<Proxy balancer://mycluster>
BalancerMember http://192.168.1.50:80/
BalancerMember http://192.168.1.51:80/
</Proxy>
ProxyPass /test balancer://mycluster

UPDATE

This needs an additional investigation, it seems that this may affect other things, namely PHP $_SERVER variables may get messed up. This doesn’t necessarily mean this solution is wrong, but it requires a deeper look.

The better solution is to use Nginx as a proxy balancer anyway :)

Well, quite self-explanatory. Only Bash and Ruby. Options “folder” and “name” are examples, replace them with what you need… Shared in hope this can help someone.

Read the article

The subject is extremely annoying. I am not that lazy to add a comment symbol myself. This would have been a good idea though, if it wasn’t sometimes needed to insert blocks of code via clipboard. With auto-comment on, if I insert

some line
# some comment
some line

I get

some line
# some comment
# some line

because there is a CR at the end of commented line and the auto-comment function adds the # symbol to the next line automatically.

The real problem begins when you try to insert many lines with some of them commented. You end up with each line after the first comment commented, the next comment commented twice so the next lines all commented twice and so on.

The solution:

Add this to your vimrc file:


au FileType * setl fo-=cro

where:

  • au = autocmd
  • FileType * – any file type
  • setl = setlocal
  • fo = formatoptions
  • -=cro disables c, r and o options ( see documentation )

This is a really annoying problem we meet pretty often. You can meet it even if you don’t use Bash. For example, you upload an image named “my lovely cat.jpg” to your website and find no image there. Or it has no thumbnail. This may happen because you are using some program for making thumbnails that is being called from, say, PHP via backtick operator (that is, using unix shell) and that program interprets the file name passed to it as three different command line options: my, lovely and cat.jpg.

Read the article

It’s not easy to remember, so here’s the reference.

var=aaa.bbb.ccc

  % %% # ##
  .*  ${var%.*} => aaa.bbb ${var%%.*} => aaa ${var#.*} => aaa.bbb.ccc (doesn’t work) ${var##.*} => aaa.bbb.ccc (doesn’t work)
  *.  ${var%*.} => aaa.bbb.ccc (doesn’t work) ${var%%*.} => aaa.bbb.ccc (doesn’t work) ${var#*.} => bbb.ccc ${var##*.} => ccc
Read the article

I was doing a simple test of pwgen (handy utility to generate passwords) and since this test was creating a lot of files in a folder I decided to combine it with a test of ls speed vs find speed:

Read the article