Blog

  • Transfer Nginx Proxy Manager to a new server.

    Transfer Nginx Proxy Manager to a new server.

    As part of setting up my new lab server, I needed to transfer Nginx Proxy Manager from its old home to a new home. This is intended to capture what I did, in case I ever need to repeat the process.

    1. Backup npm_data/_data and npm_letsencrypt/_data locations on the old host.
    2. Migrate the stack from the old host to the new host using Portainer.
    3. Stop the new stack
      • It will create an empty installation, which is obviously not useful for me.
    4. Restore the backup of the stack volumes, replacing the ones the migration just created.
    5. Restart the stack,

    The transfer of Nginx Proxy Manager is now complete. Check that it has connectivity to the downstream servers, and then move any firewall rules so that it is now the external server rather than the old one.

    Obviously now clean up the old installation on the old docker server.

  • Using Home Assistant with a Proxy

    Using Home Assistant with a Proxy

    I use Nginx Proxy Manager to direct things around my URLs and web sites – including Home Assistant.

    Its a great product, but does mean I have to configure my applications right to route via it.

    This is a notes because I had forgetten I had done a thing!

    • Remember that in Home Assistant, there will need to be an entry under “http” in “trusted proxies” section for the server doing the work.
      • This was mainly caused by the fact that I was changing from a “co-locating” the docker containers that I use for HA and NPM to ones that had to route between servers.
        • My original values listed 172.20.x.x and I now needed to list the server IP address.
  • Transfer Portainer to a different host

    Transfer Portainer to a different host

    I use the product Portainer to manage the various docker containers I have at home. Periodically, I change my infrastructure set up, which results in my having to transfer the Portainer containers to a different server.

    This time, I have decided to document what I did, in an attempt to not have to recreate the wheel next time I need to perform this activity.

    1. Check you have the command line for starting Portainer.
      • Obviously, you will need this to start up portainer when it gets where it is going.
    2. Make a volume on the new host.
      • This will hold a copy of the persisted Portainer data.
    3. Stop portainer on the old host
    4. Backup the old volume on the old host.
      • You’ll likely need to be root to view the folder correctly.
    5. Transfer the backed up file to the new host using scp.
    6. Restore the backup file into the volume on the new host.
      • You’ll likely need to be root to get the permissions correct.
    7. Startup portainer using the volume
      • At this point the transfer of Portainer is technically complete.
    8. Test you can connect to portainer.
    9. Startup portainer agent on the old host.
      • This is so that I have access to the old host again.
        I’m going to need this to clean up the old host.
    10. Redirect the proxy.
      • I use NPM and I needed to fix the proxy to fetch portainer from the new host.
    11. Clean up stacks
      • In this situation i am moving to a new Lab server, so I have copied stacks from the old host to the new host, manually backing up and transferring volumes as required.
  • Install System Shock 2 on Batocera

    Install System Shock 2 on Batocera

    Installing System Shock 2 onto Batocera has proved to be tricky. The eventual solution I found these posts here:

    https://www.systemshock.org/index.php?topic=106.0

    https://www.systemshock.org/index.php?topic=4141.0

    It turns out that all that is needed is the content of the Sshock2 directory. Put that on a standard Windows PC – not a WINE instance at this stage.

    The get and run ss2tool on this directory – I tried in WINE, but the RSYNC that it needs to run would not work for some reason.

    Finally, copy the Sshock2 directory into a WINE location. This should be made using the command line as shown in WINE in Batocera.

    Everything should now work.

  • WINE in Batocera

    WINE in Batocera

    These are my notes from attempting to get some older versions of games working under WINE in Batocera.

    This makes a win32 instance:

    WINEARCH=win32 WINEPREFIX=/userdata/roms/windows/SystemShock2.wine /usr/wine/wine-proton/bin/wine wineboot

    Enable d3dx9:

    batocera-wine windows tricks /userdata/roms/windows/CIV3.wine d3dx9

    List all tricks:

    batocera-wine windows tricks /userdata/roms/windows/CIV3.wine list-all

  • Renew LetsEncrypt in Traefik

    I’d setup Traefik to use LetsEncrypt, but due to the scarey words around rate limits etc, I felt it sensible to use the staging LetsEncrypt servers, rather than the production ones – basically I wasn’t sure how many changes I’d have to make as it has been a while since I played with any of this in anger. I assumed that Traefik would renew the certificates with LetsEncrypt when I needed production ones.

    I surprisingly got this working quite straightforwardly – I had more issues with getting Apache and WordPress (mainly Apache) playing nicely with everything.

    However, the staging certificates result in a warning which I didn’t want any longer than necessary. Since it now was working, I altered my certificate resolver in Traefik to point to the production LetsEncrypt server. I then performed a bounce to pick up the changes, expecting to see a new certificate and no more errors.

    Anxious pause…

    I waited a bit (pressing F5) and was disappointed to see that it hadn’t changed. Same certificate was in use, and I could see in the log that no attempt had been made to fetch a new certificate.

    Frantic prodding ensued as I attempted to work out what I had done wrong. Nothing was the answer. The problem, such as it is, is that Traefik already has a certificate that it can use. Traefik doesn’t feel it needs to change it the certificate.

    Solution?

    A quick google later found me a couple of links:

    Whilst the last link on the face of it initially seemed less relevant (it related to fixing a security flaw), on reading it gave the simplest answer for my situation.

    In my situation, it looked like I could simply delete the storage acme.json file. No certificates needed to be kept – I could just start again from scratch.

    I stopped Traefik, moved acme.json out of the way (belts and braces right), and then restarted it.

    Traefik Renew from LetsEncypt!

    Hey, Presto! I could see in the log file the lack of certificate being identified and Traefik calls to renew certificates from the production LetsEncrypt server.

    Padlock look right, everything is gravy! Let’s move on to the next thing.

  • Traefik Log Rotation

    An explanation of how to set up Traefik Log Rotation. This covers both the access log AND the traefik log.

    I initially setup simple log rotation using the standard logrotate package i have installed for everything else. I implemented this by following this page (there are others about) but this covered my scenario the best (as I have traefik running natively, not in a container.

    The main change I made was in the directory (mine is /var/log/traefik/) and then the files (I have an access.log and a traefik.log, so I altered the pattern to be *.log. I also added size – more on that in a minute.

    This resulted in a file /etc/logrotate.d/traefik below:

    <directory location>/*.log {
      compress
      create 0640 <user> <group>
      daily
      delaycompress
      missingok
      notifempty
      rotate 5
      size 10M
    
      postrotate
        kill -USR1 `pgrep traefik`
      endscript
    }

    However, I began to spot that it did not working as anticipated.

    • access.log wouldn’t rotate
    • traefik.log rotated but still wrote to the rotated our file

    It turns out access.log not rotating was because I misunderstood what size would do. It’s not an either/or with the daily setting – size supersedes daily if it is in the file. Simply removing size made access.log rotate as expect.

    However, traefik.log still won’t rotate on a USR1 – which seems contrary to their own documentation (link).

    I decided that something weird must be going on, so I dug about a bit. If you check the code in git (link) you’ll see that the code specifically mentions rotation of the access log, and their tests also only check the access log.

    This means that USR1 signal only rotates the access log. That was annoying.

    I wondered if I was missing something, so I went in search of rotate in git (link) and found something that whilst documented at source level seems to be missing in the Traefik log documentation (link).

    It turns out that Traefik can do some quite clever stuff with rotating its own log if you configure it right.

    log:
      # Log level
      #
      # Optional
      # Default: "ERROR"
      #
      level: <whatever level you want>
    
      # Sets the filepath for the traefik log. If not specified, stdout will be used.
      # Intermediate directories are created if necessary.
      #
      # Optional
      # Default: os.Stdout
      #
      filePath: <directory location>/<file>.log
    
      # Format is either "json" or "common".
      #
      # Optional
      # Default: "common"
      #
      #format: json
      maxSize:    5
      maxBackups: 50
      maxAge:     10
      compress:   true

    This will rotate at 5Mb, compress the old copies, and keep for 10 days and keep a maximum of 50 files. There are other options in the document – I have not used them.

    This then means I can make the logrotate configuration focus just on the access log:

    <directory location>/access.log {
      compress
      create 0640 <user> <group>
      daily
      delaycompress
      missingok
      notifempty
      rotate 5
    
      postrotate
        kill -USR1 `pgrep traefik`
      endscript
    }

    Combining these two pieces of information (access log rotation and traefik log rotation) together gives me a functional solution.

    -rw-r----- 1 traefik traefik   706383 Sep 15 13:46 access.log
    -rw-r----- 1 traefik traefik  2071725 Sep 14 23:59 access.log.1
    -rw-r----- 1 traefik traefik   101616 Sep 13 23:59 access.log.2.gz
    -rw-r----- 1 traefik traefik    43272 Sep 12 23:59 access.log.3.gz
    -rw-rw-r-- 1 traefik traefik   574683 Sep 12 12:29 access.log.4.gz
    -rw-r----- 1 traefik traefik       23 Sep 10 02:11 traefik-2023-09-10T01-11-42.862.log.gz
    -rw-r----- 1 traefik traefik    62635 Sep 12 20:48 traefik-2023-09-12T19-48-36.125.log.gz
    -rw-r----- 1 traefik traefik    45843 Sep 12 23:48 traefik-2023-09-12T22-48-51.210.log.gz
    -rw-r----- 1 traefik traefik    47196 Sep 13 02:50 traefik-2023-09-13T01-50-47.804.log.gz
    -rw-r----- 1 traefik traefik    46280 Sep 13 05:51 traefik-2023-09-13T04-51-02.691.log.gz
    -rw-r----- 1 traefik traefik    59591 Sep 13 08:44 traefik-2023-09-13T07-44-32.782.log.gz
    -rw-r----- 1 traefik traefik    51714 Sep 13 11:35 traefik-2023-09-13T10-35-02.705.log.gz
    -rw-r----- 1 traefik traefik    62231 Sep 13 14:31 traefik-2023-09-13T13-31-29.208.log.gz
    -rw-r----- 1 traefik traefik    47698 Sep 13 17:30 traefik-2023-09-13T16-30-44.233.log.gz
    -rw-r----- 1 traefik traefik   114460 Sep 13 20:00 traefik-2023-09-13T19-00-49.560.log.gz
    -rw-r----- 1 traefik traefik    88101 Sep 13 22:45 traefik-2023-09-13T21-45-27.953.log.gz
    -rw-r----- 1 traefik traefik    45687 Sep 14 01:48 traefik-2023-09-14T00-48-21.418.log.gz
    -rw-r----- 1 traefik traefik    48091 Sep 14 04:48 traefik-2023-09-14T03-48-36.486.log.gz
    -rw-r----- 1 traefik traefik    45339 Sep 14 07:49 traefik-2023-09-14T06-49-32.199.log.gz
    -rw-r----- 1 traefik traefik    58615 Sep 14 10:29 traefik-2023-09-14T09-29-32.183.log.gz
    -rw-r----- 1 traefik traefik    50523 Sep 14 13:24 traefik-2023-09-14T12-24-47.288.log.gz
    -rw-r----- 1 traefik traefik   111852 Sep 14 15:48 traefik-2023-09-14T14-48-17.251.log.gz
    -rw-r----- 1 traefik traefik   102566 Sep 14 18:19 traefik-2023-09-14T17-19-54.417.log.gz
    -rw-r----- 1 traefik traefik    49430 Sep 14 21:08 traefik-2023-09-14T20-08-39.426.log.gz
    -rw-r----- 1 traefik traefik    52971 Sep 14 23:53 traefik-2023-09-14T22-53-09.416.log.gz
    -rw-r----- 1 traefik traefik    48757 Sep 15 02:45 traefik-2023-09-15T01-45-41.245.log.gz
    -rw-r----- 1 traefik traefik    47160 Sep 15 05:37 traefik-2023-09-15T04-37-56.255.log.gz
    -rw-r----- 1 traefik traefik    48261 Sep 15 08:29 traefik-2023-09-15T07-29-56.249.log.gz
    -rw-r----- 1 traefik traefik    48879 Sep 15 11:18 traefik-2023-09-15T10-18-41.241.log.gz
    -rw-r----- 1 traefik traefik  4548970 Sep 15 13:46 traefik.log
  • Pi with FAN-SHIM problem diagnosis

    I purchased a FAN-SHIM and Raspberry Pi 4 from Pimoroni last year but occasionally saw a problem, and struggled with a diagnosis.

    The FAN-SHIM generally worked great, but I noticed that it didn’t seem to always work when I didn’t have a lead coming off the header to a breadboard. The fan would just run, the LEDS wouldn’t work – it was basically unhappy. Given it was directly related to the cable, I took the easy route to fixing things – leave it attached! However, I always wanted to properly diagnose what was going on.

    A picture of a Raspberry Pi 4 showing the FANSHIM in place , showing the friction fit header pushed over the GPIO pins - waiting for diagnosing problems!
    Stock Pi 4 with a FAN-SHIM plugged in.

    Exploring Problems with the FAN-SHIM on a Pi

    I recently had a chance to look at this again, and this is collecting my exploration and thoughts. In short, I did a lot of hunting about, until I found something that really helped me diagnose things. I knew the installation was working – as I said, with the cable attached all is good. However, I didn’t really want it plugged in all the time. It looked like it was pushed on OK – but I had no control.

    How could I work out if it was the SHIM with an issue, my Pi or something else?

    Eventually, I found this page. A comment by gadgetoid suggested a really good diagnostic approach.

    Diagnosing the FAN-SHIM problem on the Pi

    Basically, turn the fanshim service off:

    systemctl stop pimoroni-fanshim.service

    Then, start up python and run the following:

    import RPi.GPIO as GPIO
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(18,GPIO.OUT)
    GPIO.output(18,0) # Should turn fan off
    GPIO.output(18,1) # Should turn fan on

    Basically, run the command to get the fanshim to do what it isn’t at the moment. Then adjust the fanshim until the action actually happens – so in my case it finally turned off!

    Having done this, I could run now run the other test scripts in the fanshim example source code.

    Finally the LED would change as expected, and the fan would turn on and off as expected.

    I now re-enabled the fan-shim service:

    systemctl start pimoroni-fanshim.service

    Now, I know how to check things if it goes wrong again!

  • Configure Microsoft Live Writer to work with Drupal

    Hey! I’ve managed to configure Microsoft Live Writer to work with my Drupal install (see this URL).

    I had a minor issue configuring Microsoft Live Writer, where I couldn’t login as my non-administration user. Initially, I worked that that returning the edit privilege in Drupal “Authenticated Users” made it work. Since then I had a more detailed look at this issue. It seems that rights to the Blog API needed to be granted. After that, I managed to restrict the rest of the rights to more or less where they were before.

    So, now I might actually start using Live Writer… it’s much easier to blog this way (yes, I like to do things the easy way were ever possible).

  • Locally persist Bering changes

    Locally persist Bering changes

    So I decided to add an user wolagent and put the script into his home directory. The question is how to backup this user.  Simply using the ‘s’ – command from the Bering 3.x – menu doesn’t backup the user and his homedir. In short, there seemed to be no way to persist this Bering change locally.

    So how can I do that?
    Add your stuff to /var/lib/lrpkg/local.local