Using the salt data module in a salt runner
Salt runners don’t start with the full complement of salt modules loaded at start, but it is possible to load up some (many? all?) of the modules if they are needed.
I wanted to use the data module to store the result of a runner execution to reduce duplicate processing, but just adding an
import salt.modules.data did not work, when the
data.update() call was made, it threw an exception (something about
__opts__). It took a bit of time and experimenting, but I found that I could load the module and call it like so:
import salt.client import salt.config __opts__ = salt.config.minion_config('/etc/salt/minion') datamod = salt.loader.raw_mod(__opts__, 'data', None) datamod['data.update']('keyname', 'value')
Hopefully this will help someone else, as when I looked in Google for answers (late August 2015) it was difficult to find anything about using modules in salt runner scripts.
Tuesday September 1, 2015 · Permalink
Multiple Monitors on a Laptop with Ubuntu 9.10 (Karmic Koala)
Recent movement of machines around left me with an extra monitor that I could use as an external display with my laptop running Ubuntu 9.10 (Karmic Koala).
From reading numerous websites, I guess that multiple monitor support didn’t improve with 9.10 over 9.04, but I did find a couple of articles that helped me craft a setup that works for me.
The original articles are:
- Karmic dual monitors now assigns second monitor as primary specifically post #3
- Adding universal shortcuts in ubuntu/gnome (view the google cache version)
What I ended up with was a couple of small scripts in my bin directory called ext-on and ext-off:
#!/bin/sh xrandr --output LVDS1 --primary xrandr --output LVDS1 --auto --pos 0x0 --output VGA1 --auto --right-of LVDS1
#!/bin/sh xrandr --output VGA1 --off --output LVDS1 --auto
I then used
gconf-edit to bind those commands to <Super>-2 and <Super>-1 respectively to turn on and off the external monitor.
Hope this helps someone else looking for an easier way to manage a second monitor than having to go into display properties every time you connect to an external monitor.
Sunday January 17, 2010 · Permalink
Using SMTP AUTH as a client
If your ISP requires you to use SMTP AUTH to connect up to their mailserver for outbound email (as is the case with SBC/Yahoo) the following links will prove helpful:
Luckily for me, the cable provider I have right now seems to do IP address range checking so I can send outbound via their servers as my Sendmail smart host without setting up SMTP AUTH.
Tuesday March 28, 2006 · Permalink
I found inspiration from a hack called Making Firefox Behave Like Galeon. After cleaning the example up a bit, it became url2firefox:
#!/bin/bash FF_LIB=/opt/firefox1.0 # get URL to load url=$1; [ -z $url ] && url=about:blank what=$2; if [ -z $what ]; then $FF_LIB/mozilla-xremote-client -a firefox \ openURL\($url\,new-tab\) && exit 0 else $FF_LIB/mozilla-xremote-client -a firefox \ openURL\($url\,$what\) && exit 0 fi # if xremote failed, then launch the browser exec $FF_LIB/firefox $url &
I then set url2firefox as the Custom Web Browser Command in the Preferences -> Preferred Applications dialog and as
vm-url-browser in my XEmacs .vm file. Now I can right click on URLs in Terminal and select Open Link or middle click on URLs in VM in XEmacs and it will open a new tab with that URL.
One other thing I did was to add a
set nomarkers to my
.muttrc so long urls would not be wrapped with
+ when they hit the edge of the terminal.
Friday April 1, 2005 · Permalink
One of the first annoyances I encountered was that I couldn’t easily align windows since edge gravity isn’t the default. Reading throught the doc files in the metacity RPM revealed that pressing the shift key while moving a window will turn on edge gravity.
I’d really like to have edge gravity be the default and have the shift key turn off edge gravity, but I guess it will have to do.
Another annoyance is that I can’t seem to find any way to change the mouse bindings on the window manager. I’d like to emulate the maximize, maximize-vertical, and maximize-horizontal behavior of the titlebar maximize button in sawfish, but I can only find out how to do key bindings for those functions, not mouse buttons.
If anyone knows how to work around these annoyances, drop me an email, the address is over on the right.
Wednesday March 30, 2005 · Permalink
A Knoppix Rescue
Where I work, we’re just a bit paranoid, so it’s not enough to just mirror your bootdisk and have it backed up to tape, we also create an extra bootable volume, just in case. The extra bootdisk comes in very handy for doing OS upgrades, allowing us to install a new OS on the extra bootdisk with a very easy fallback to the original OS.
I’d been running one server on the (former) extra bootdisk and it was time to restart the cron job that keeps the extra bootdisk up-to-date. The cron job ran fine and I checked out the disk, everything looked fine. It was then time to check out the (new) extra bootdisk, so I picked a slow time, hopped on the console and issued the shutdown. BIOS checks went as expected, the screen cleared and I waited for the grub menu to appear. And I waited and all it said was “GRUB GRUB”. Ahhhhh what is happening?
What I’d forgotten was that the new extra bootdisk was actually the first disk in the system and it had the bootable partition on it. And it had the grub bootloader on it. And that the cron job recreated the ext3 filesystem using mke2fs, which ended up trashing the bootloader.
I ended up grabbing a Knoppix CD that I had at the house and ran into the office so I could attempt to recover. Knoppix can boot up the Compaq ML-380 my system is on, but for some reason, it didn’t automatically make the devices for the CCISS drives. Looking at the lsmod output, I found that it did contain the cciss.o module, so I just had to figure out what the major and minor numbers and do the appropriate mknod commands. (The cciss devices are major number 104 and c0d0 has minor number 0, c0d0p1 minor 1, c0d0p2 minor 2, c0d1 minor 16, c0d1p1 minor 17, etc.) I could then mount the partition, do a grub-install and reboot successfully.
A couple of Knoppix cheat codes also came in handy, booting with knoppix-txt instead of knoppix (to keep from going into graphics mode, just in case the kvm setup can’t handle it) and using ‘2’ so that it just drops straight to a root bash prompt (no need to go fully graphical when the command line is all you need).
I’ve also updated the cron job so that it always puts the grub bootloader on the extra bootdisk, no matter if it’s the first disk in the system or not :-)
Friday December 10, 2004 · Permalink
Web Content Filtering on Linux
Thursday July 1, 2004 · Permalink
1.2 Terabytes of Storage for under $1600
Best quote: "I'll probably be crying when I look back on this article in 5 years, when terabyte drives come free in specially-marked boxes of Captain Crunch."
Friday June 18, 2004 · Permalink
Shrinking a Partition in Linux
I recently had the need to shrink a partition that, when originally created, consumed the whole disk. Listed below are the steps that I followed to shrink the original partition down so that I could add a new 20G partition to the end of the disk.
Use fdisk to look at the partition table of the disk and decide which partion will be shrunk and what the new number of cylinders will be.
If you want to shrink the partition by a specific amount then use the “Units = cylinders …” line from the partition information to find the size of a cylinder and then divide size you want left by the cylinder size and round up.
For example, the disk c0d1 currently has just a single large partition:
Disk /dev/cciss/c0d1: 255 heads, 63 sectors, 8854 cylinders Units = cylinders of 16065 * 512 bytes Device Boot Start End Blocks Id System /dev/cciss/c0d1p1 1 8854 71119723+ 83 Linux
To shrink it down to get a 20G partition, we would compute the cylinder size as 16065*512 (8225280 bytes) and then divide 20G by that number:
(20*1024*1024*1024)/8225280 = 2610.83 = 2611 cylinders
That means partition 1 will need to be 8854-2611 = 6243 cylinders after resizing.
resize2fs uses a block size of 4K, so you’ll need to change the number of cylinders to 4K blocks. Round the number down if comes out as a fractional number.
(cylinder_size * cylinders) / 4096
In our example, cylinder size is 8225280, cylinders is 6423, so it works out to be:
(8225280*6423)/4096 = 12898186.87 = 12898186 4k blocks
Unmount the filesystem and run e2fsck on it to make sure it is cleaned up.
- stop services that are writing to the disk
e2fsck -f /dev/cciss/c0d1p1
Run resize2fs on the disk to shrink the filesystem:
resize2fs -p /dev/cciss/c0d1p1 12898186
Run fdisk to then shrink underlying partition. When running fdisk, you will delete the partition then create the same partition number starting at the same cylinder, but with the size of the new cylinder count.
Remember to write the partition table to the disk (w command) before exiting.
You can then mount up newly shrunk partition and create the new partition and filesystem.
Wednesday January 14, 2004 · Permalink
Moving email off a retiring mail server
If you’re already using the mailertable feature of Sendmail, it’s quite easy to move any undelivered email off an old server by adding a mailertable entry like the following:
where 192.168.97.21 is the IP address of the new mailserver that is now in place.
The dot entry is the wildcard for the mailertable entries that will match any resolvable host name.
Not sure how to deal with host names that are temporarily not resolvable, but since all the ones I had to deal with were bounces from spam, I ended up just deleting them.
Tuesday November 4, 2003 · Permalink