Software Archive

I love being lazy. In fact, it’s fair to say I take it quite seriously.

One of my favorite teachers taught me something deeply memorable one day. He taught me that being lazy is the best way to approach any job. Not just for you, but for the job itself and everyone else it affects.

Now, on the face of it this might sound like some poor advice.

Follow me along here:

1. The goal of being lazy is to not do more work than you have to.

2. Doing something once is less work than doing it twice.

3. To do something only once, you have to do it right the first time.

So, therefore, if you want to be lazy, you have to do the job right the first time.

– From the unforgettable Chris Venne.

One of the best ways to be lazy is with init scripts. Since I’m a Xubuntu/Debian fanboy, I use both upstart init and (x)init.d style scripts. Now, these can be easy, and sometimes they can be hard, especially when you don’t have useful examples. (and especially more so when half the sites reap off each other and have the same ding dong mistake. More on that later.)

To avoid confusion, when I say upstart script, I mean the newer style scripts run from /etc/init/ by Upstart. When I say init.d or init script, I mean a script run by init from /etc/init.d/. Hopefully this helps avoid confusion. (Though in the future after init is very deprecated, I will likely just call then init scripts.)

Some people reading this likely know what upstart and init/init.d scripts are. If you do not, the short version is, they are scripts run by services (called Upstart and init) that manage other services. This is how you get stuff to start and stop on boot and shutdown.

I keep around some template files, so I never have to worry too much about remembering how to do it.

For init we have: (Remember, you can click on the top blue line to download the file.)

# <name of daemon>### <Longer description>##
description "Derp"
author "Herp Herp D Derp"# The below "start on" line controls when it starts up. There are many options available.
start on (local-filesystems and net-device-up)#Ditto for stop on.
stop on runlevel [016]
respawn
respawn limit 530envuid=<user to run as>envgid=<group to run as>envumask=000
# This next line gets called on start, and killed on stop. Upstart tracks the running invocation automatically.# I use the below exec line, but you can use just about anything.exec start-stop-daemon -S-c$uid:$gid-k$umask-x<path/to/executable/>---d-l<log/me/here.log>-L warning
#exec /usr/bin/binary

And the “run some checks and scripting, before running the daemon/binary” type:

# <name of daemon>### <Longer description>##
description "Derp"
author "Herp Herp D Derp"# The below "start on" line controls when it starts up. There are many options available.
start on (local-filesystems and net-device-up)#Ditto for stop on.
stop on runlevel [016]
respawn
respawn limit 530envuid=<user to run as>envgid=<group to run as>envumask=000
#A more insane start condition. This one is based off starting lightdm
start on ((filesystem
and runlevel [!06]
and started dbus
and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
or stopped udev-fallback-graphics))
or runlevel PREVLEVEL=S)
stop on runlevel [016]#The below lines are run as a shell script on start, and the started binaries killed on stop.
script
if["$RUNLEVEL" = S -o"$RUNLEVEL" = 1]then# Single-user modeexit0fiexec<some binary>
end script
#This runs after stop
post-stop script
rm/some/tmp/files/
end script

Now, before, I mentioned some common problems with these. Permissions and environmental options are often the place to start. Using start-stop-daemon you have user selection with --chuid and --chgid. This works with both init and Upstart.

Typically, the simplest troubleshooting step is to run each line of the script, or if you suspect your flow control (IF, ELSE, etc), stuff the lines up in a script of their own, with echo output and sleeps to identify and temporally separate steps.

Sometimes, calling an external bash script can be useful as well. The binaries spawned by that script will still be watched by Upstart for the purpose of stopping them. With init, this is more difficult.

One last thing to remember, both init and Upstart scripts are interpreted as sh, or shell, not bash. Look for bashisms in your script, and if you cannot live without them, call an external script, ensuring it is executed by bash. (A bashism is a procedure or command specific to bash, and not found in other shells, such as sh and ksh.)

I use git, and I love it. I use it to hold my personal code and textual files, and I use it to share the code I use on this site, and the code pasted in some of the articles. There is, as always, a lot of contention over svn vs git vs mercurial… but that’s not the point of this article. (Though, I confess, mercurial being written in python tells me I might enjoy fiddling with it.)

The point of this article is, I love git. Most of the time, I don’t even realize I need a repository until … well until I need one. I’m a big fan of bare repos, so thats what I’ll write about. Also, I’ll talk about multiple remote repositories, which is how I manage to keep my pre-published code separate from the github repo I have linked with this blog.

Git is in all the major distros, and most package managers have a “git” you can install, plus you can find instructions for installing from source, so if you’re a masochist, you can install it on your droid or mini Linux box. There are also a lot of options for Windows. (You can also install git via git…..)

So, once you install git, you want a new repo, right? Well, usually, if you are like me, you want a bucket to hold your stuff, something you can organize, push and pull from multiple locations.

* Most of my notes are from Pro Git by Scott Chacon, the git book freely available on the git-scm website.

Often, online, you see repos being set up ending in .git. This is a convention I do not follow.

For a bare repo, go to or mkdir the empty directory, and run

git init --bare

Then, you can move in the files you need, or at least touch a file.

The usual commands are:

git push, git commit (or frequently git commit -a), git pull

man git and git --help are also of some use.

Now, once you get the push-pull working for ya, there’s some additional tricks, like your config file in /.git/config. I keep my repo on a remote server from my home, so I have both that repo, and the one I use on github to share code on here.

This allows me to do fun stuff, like, after a commit, doing git push github, or git push master, if I only want to update one place, I can do git push all to push to all repos, or I can do git push origin github to make sure both remote repos are up to speed with each other, without my copy being included.

If you are sharing to mostly Linux users, SSH is awesome to use. If you have a large amount of Windows users, http/s allows you to get away without using another program like plink.