Saturday, 6 January 2018

A run-once system for linux

Current development of the Linux image for the community centre I'm involved with requires me to be able to carry out tasks just once (a "run once" capability). Moreover, I have need to run such tasks at three different stages in the overall process:
  1. At start up before the network is active (to manipulate network definitions)
  2. At start up after the network is active but before users log in (in my case to incorporate the IP address into a workspace wallpaper)
  3. At shut down, after the users are logged off but while the filesystems are still mounted.

The run-once script

I have a run-once script /usr/local/bin/runonce, based on one I found here.
[ -z $RUNONCE_DIR ] && RUNONCE_DIR=/etc/local/runonce.d

[ ! -d $RUNONCE_DIR/ran ] && mkdir -p $RUNONCE_DIR/ran

for FILE in $RUNONCE_DIR/*; do
    [ -d "$FILE" ] && continue
    COMMAND_NAME=$(basename $FILE)
    logger -it runonce -p "Running: $FILE"
    mv "$FILE" "$RUNONCE_DIR/ran/$COMMAND_NAME-$$-$(date +%Y%m%d-%H%M%S)"
    logger -it runonce -p "Ran: $FILE"

I use it in all three places, with three directories /etc/local/runonce-a.d, /etc/local/runonce-b.d and so on.  The parameter to the runonce job specifies which one to use.

The three jobs are then controlled by systemd unit files (I'm just getting used to systemd ..), as follows:


# Run-once service; runs any executable in /etc/local/runonce-a.d
# Ensuring that it runs before the network is active
Description=Run once programs (pre network)

ExecStart=/usr/local/bin/runonce /etc/local/runonce-a.d



# Run-once service; runs any executable in /etc/local/runonce-b.d
# Ensuring that it runs after the network is active
Description=Run once programs (post-network)

ExecStart=/usr/local/bin/runonce /etc/local/runonce-b.d



# Run-once service; runs any executable in /etc/local/runonce-c.d
# before the system is shut down or rebooted.
Description=Run once programs (before shutdown)

ExecStop=/usr/local/bin/runonce /etc/local/runonce-c.d


It took quite a while to assemble the various bits of this from around the web; hope it helps someone else.

Wednesday, 12 October 2016

Windows 7 PC can't see anything on the network

If you have this problem and go searching on the web you'll find a huge number of posts: it's terribly common.  So common that you'd have thought that Microsoft would have fixed it, but there we are.

Here's my experience today, which isn't as far as I can see the same as any of the twenty or so hits (none of them saying anything definitive) which I looked at this morning.


  • Clicking on "network" showed only the local machine, the defined network printers, and an icon representing the NAS to which I was trying to get access.  Not the sort of icon that allows you to get at the files, though.
  • Opening a command window and pinging the device by name (I haven't bothered creating a hosts file) worked fine, so the TCP/IP parts were working.

The cure

I can't call this a "fix" since it makes no sense.  In order to check whether some firewall rule was dropping the relevant traffic I turned the firewall off.  Bingo!  The network appeared.  "Ah, a firewall problem," I said to myself.  "Now what on earth is causing that?"

I turned the firewall back on again, and the network was still visible.  Job done ... but why?  Oh well, Windows is like that. 

Friday, 30 September 2016

You told Windows 10 that your network was "public": what do you do now?

When you connect to a new network Windows 10 will ask you whether it's "private" or "public".  It's clear that some people don't understand the real intention of this, which isn't to do with whether or not the network is used by "the public", but rather is to do with whether you trust the people that configure and administer it.  So the network at the community centre whose IT I look after is "private".

If you designate a network "public" Windows 10 will--correctly in my opinion--tightly constrain what the machine will "see" in that network.  File shares won't work, printers can't be seen, and so forth.  The only trouble comes if you designate a network as "public" by mistake: there is no easy way to change it to "private"!  This seems to be a major oversight on Microsoft's part.

Faced with the problem this morning I found the way to fix it.  It involves using the Deep Magic of the powershell, but it worked first time for me.  It comes from this page, about half way down.
  1. Windows-key and search for "power"; you'll get a list of "powershell" options.
  2. Right click on the simple "powershell" one and select "Run as Administrator".
  3. In the blue window that comes up, type Get-NetConnectionProfile
  4. You'll get a list of network connections, each with a number.  Select the one you want to change and make a note of its number (let's say it's number 2).
  5. Now type Set-NetConnectionProfile -InterfaceIndex 2 -NetworkCategory Private, where you replace "2" with whatever your interface is.
That web page says you should reboot after this but I found it worked fine without.  And I've no idea whether you need to respect the upper- and lower-case letters in those commands: I typed them as they are.

Thursday, 29 September 2016

Windows 10 file sharing: frustration and a workround

Setting up a new laptop for a colleague; it runs Windows 10 and my knowledge stopped, more or less, at Windows 7.

There's software I need on the Samba file server on the home network.  But can I get this thing to see the server?  I've spent hours on it, and seen hundreds of articles on the web in which the same problem is discussed, and almost as many attempts to fix it.  I tried a few of the most likely (enable discovery and file sharing, fiddle around with SMB protocols) all to no avail.

I can ping the server; I can list the shares with net view; I just can't get them to appear in the "Network" explorer.

I still haven't fixed it, but I have managed to get access to the drive I need by the simple expedient of selecting "Map a network drive", filling in the IP address of the server and telling it to use different credentials.  Up it comes.

It appears that Microsoft have changed (spell that b-r-o-k-e-n) something in the way that Windows 10 connects to file shares, but nobody knows quite what.

Thursday, 1 September 2016

Disabling the Google Chrome sign-on screen

When you start Google Chrome it comes up with a page inviting you to "sign in to Chrome" (which I think is the same as signing in to Google).  The users that sit in front of my "teaching" machines have only the vaguest clue about "signing in" to something, and they certainly won't understand the difference between signing in to Google and signing in to some other application (such as the DWP's job-search system, which is often the only thing they use).  If they take any notice of the screen at all it would put them off, since they wouldn't have an account and a password and would think they couldn't continue until they had signed in.

So I'd like to disable the sign-in screen as part of the build, using some preferences file somewhere.  But guess what?  The Chrome sign-in screen isn't controlled by a preferences file.  Assiduous web searching suggests that it was once controlled by a "sync_promo" section in the "Preferences" file, but testing shows that that section isn't there, at least in the 32-bit version that I'm obliged to use.  And in any case you can't pre-populate a user with a Preferences file because it's different for every user and every time that Chrome is opened.

I'd like this blog to contain solutions to problems, but in this case it records the fact that I've given up trying to do this.  Thanks, Google.

Wednesday, 31 August 2016

Default desktop configuration XFCE 4.12 (Ubuntu 16.04)

Migrating my standard "teaching room" build of Ubuntu (with the xubuntu package installed, so possibly I should describe it as Xubuntu) from 14.04 to 16.04.  I've found several differences, including this one

The default desktop configuration file is no longer


but is instead


In order to provide every user with the same default desktop I copy in a version of the first file. Under 16.04 the user's background is the default XFCE wallpaper.  So now I copy in the second file and everything is as it was.

Wednesday, 4 May 2016

Oh, not another blog, surely?

Yes, I'm afraid so.

Why?  Because as I'm working on "technical" things I keep finding that what I'm trying to do isn't exactly the same as what others who went before me have done, so it occurred to me that documenting successful solutions to problems might help those who come after.

It might help me remember what those solutions were too, come to that.

There's nothing here yet; the cup of coffee I just drank gave me time to set the blog up, but I've got other things I must do right now.