Moving VMware image from one directory to another.
I had to move a VMware image from one hard disk to another because I wanted to add more space to it (I use VMWare Player).
I just copied the whole VM folder to the new directory, added the copied VM to VMware, and ran it. It asked if the VM had been copied or moved. I elected to say "copy" because I didn't want it to do anything to the original VM in case I had to return to it. In retrospect, "move" would have been better than "copy", as we shall see.
The new VM ran, but couldn't connect to the Internet. The issues were the following:
- The MAC address changed. I had to register the new MAC address with my corporate network.
- eth1 no longer existed, but eth2 did. I had to replace "eth1" with "eth2" in the file
/etc/network/interfaces
.
In retrospect, "move" would have been better than "copy", because the MAC address would not have changed. Possibly the ethernet interface would have remained the same as well.
Run multiple instances of Jetty on different ports on Ubuntu 9.04.
My goal today was to run multiple instances of Jetty on different ports on Ubuntu 9.04.
The Ubuntu 9.04 repository has Jetty 5.x only. It might be best to just uninstall the Jetty package and download a Jetty 6.x from the Jetty website. But if you are stuck with Jetty 5.x, this is how to get multiple instances running.
First, we want to learn how to launch Jetty from the command line. When you start Jetty with /etc/init.d/jetty start
, what really happens is something like this:
/usr/lib/jvm/java-6-sun/bin/java -Xmx256m -Djava.awt.headless=true -Djava.io.tmpdir="/var/cache/jetty" -Djava.library.path=/usr/lib -DSTART=/etc/jetty/start.config -Djetty.home=/usr/share/jetty -jar /usr/share/jetty/lib/start.jar /etc/jetty/jetty.xml
depending on the Java envrionment on your system. You must know exactly what this command is so you can run it manually. Open /etc/init.d/jetty
and have it print what it's doing by adding
echo "$JAVA $ARGUMENTS"
above the line:
su -p -s /bin/sh "$JETTY_USER" \
-c "$JAVA $ARGUMENTS >> $LOGDIR/out.log 2>&1 & \
echo \$!" > "$PIDFILE"
echo "$NAME."
Then do /etc/init.d/jetty restart
and see what it prints out.
This long command of course boils down to:
jetty -jar start.jar /etc/jetty/jetty.xml
That last argument, the jetty.xml
conf file, controls the id of the Jetty instance. We can launch multiple Jetty instances by starting Jetty with different ids. To make it easier on you to run this command and vary the conf file, create a script start.sh
like this:
#!/bin/sh
/usr/lib/jvm/java-6-sun/bin/java -Xmx256m -Djava.awt.headless=true -Djava.io.tmpdir="/var/cache/jetty" -Djava.library.path=/usr/lib -DSTART=/etc/jetty/start.config -Djetty.home=/usr/share/jetty -jar /usr/share/jetty/lib/start.jar $1
This way we can run
$ start.sh /etc/jetty/jetty.xml
to launch Jetty. I would put start.sh
in the /usr/share/jetty/lib
directory.
If you look in the conf file you will see something like this:
It turns out that the Configure
tag has an attribute named id
. If two conf files have the same id, the conf is merged; if they have different ids, separate jetty instances are launched. So, copy the jetty.xml
file to a jetty-a.xml
file, and change the Configure
line to:
You also want the Jetty instances to run on different ports, so change
to
However, if you try to use this conf file with
jetty -jar start.jar /etc/jetty/jetty-a.xml
you will get errors like this:
org.xml.sax.SAXParseException: Attribute "id" must be declared for element type "Configure".
The culprit is that Ubuntu/Debian jetty.xml
hardcodes the Jetty configuration DTD version. According to the Jetty team, it is better to leave out the version; the code redirects it to the most recent version. So change
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure 1.2//EN" "http://jetty.mortbay.org/configure_1_2.dtd">
to
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
Now if you run
# start.sh /etc/jetty/jetty.xml &
# start.sh /etc/jetty/jetty-a.xml &
you will have two Jetty instances on separate ports.
References:
- http://capitalcodemonkey.blogspot.com/2008/04/creating-multiple-jetty-server.html -
I basically followed this exactly, but it looks like he uses Jetty 6 on Solaris 10 so ran into some issues.
- http://docs.codehaus.org/display/JETTY/How+to+serve+webbapp+A+from+portA+and+webapp+B+from+portB#HowtoservewebbappAfromportAandwebappBfromportB-alternative - Good info but not detailed enough to just follow blindly.
Setting the From header in mail from GNU Mailutils
$ mail -aFrom:me@example.com
Took a while to find.
Extracting audio from video
FFmpeg does this well:
ffmpeg -i movie.flv -ab 256k -vn -ss 23 -t 00:04:58 -vol 512 mysong.mp4
The optional arguments mean:
- -ab 256k: 256k bitrate (seems to mean the upper bound, the actual bitrate seems to turn out to be less and setting higher didn't change file size but the default of 64k was very bad)
- -vn: no video
- -ss 23: start extracting at the 23 second mark (HH:MM:SS format also accepted)
- -t 00:04:58: extract for a duration of 4:58 minutes
- -vol 512: set the volume. 256 is the default; 512 doubles that.
I chose mp4 because it seems to be portable and it worked with the seeking and truncation options. For more information, of course, see the FFmpeg documentation.
Then mysong.mp4
can be added to your iTunes library.
For extracting something that's mostly speech, you can get away with lower quality:
ffmpeg -i speech.flv -vn -ac 1 -ar 22050 audio.mp3
Why I don't like Textile
This is mostly a reminder to myself of why I prefer HTML over lighter markup languages like Textile or Markdown. I often come up with judgements of what I like or not, but it's difficult to recall the reasons when pressed.
Here are some examples of when Textile is too weak:
- Can't start a quote with bold text.
"*This will not* be in bold"
. - Depends on whitespace to delimit tokens, which doesn't work for Japanese.
"このページを登録すると正常に動作しませんので*ご注意ください*"
。 The ご注意ください will not be in bold. This is also problematic when using the #syntax to link to an issue (as in Redmine). - Cannot handle links that end in punctuation, as in:
"link text":http://www.example.com/hi.
. In Textile, the period is not part of the link, which is usually what you want, but if it is not I don't think there is a way to disambiguate it. This is also an issue for languages like Japanese without whitespace.
Yes, these are rather weak examples, but I will add on as I find problems. The point for me is I do not think the simplicity of markup gained at the expense of losing the power of HTML is worth it (for personal wikis and the like. I recognize it is good for public sites with possibly malicious users adding content.)
The other issue for me is there are too many of these in the wild. I regularly have to use four different types of markup (FreeStyleWiki, MediaWiki, Markdown, Textile). I can never remember the syntax for all of them.
ssh without password on Ubuntu Jaunty
Mostly lifted from here but for my own notes.
- On client, run
ssh-keygen
Do not supply a passphrase. This creates a keypair in~/.ssh
. - Copy the newly created file
id_rsa.pub
to server.scp -P 22 .ssh/id_rsa.pub bob@server:~/
- On server, append
id_rsa.pub
to file~/.ssh/authorized_hosts
(or create if does not exist).cat id_rsa.pub >> .ssh/authorized_hosts
- (Important) On server, in
/etc/ssh/sshd_config
change "StrictModes yes" to "StrictModes no". - Restart sshd.
sudo /etc/init.d/ssh restart
- On client, try logging in:
ssh -p 22 bob@server