Saturday, December 17, 2022

Browsing Synology shared drives from Mac is slow

 Browsing network volumes on a Synology NAS from my Mac was very slow. In particular, previewing (even small!) PDFs. The solution posted here seems to work.

Monday, June 13, 2022

Disconnecting USB-C hub kills network

 I have had several problems with my home network recently, where parts of the Ethernet connected devices were not reachable anymore. The problem seemed to be a recently new 8-port Ethernet switch. Turning off and on one of the switch solved the problem for a while.

I figured out (after a long time) that the switch would fail when I disconnect my DELL DA310u USB-C hub from my Macbook. When I plugged the hub back in (even after hours), the network switch came back. Interestingly, the network connection from the USB-C hub to the failing switch is through another switch.

I found this article that describes a pause frame to be sent across the network from the USB-C hub. Man, that sucks....

Sending emails about live/dead server

This code checks if a host on a network is reachable via ping; if not, it sends an email through ssmtp (which needs to be configured beforehand). All parameters are declared in the first few lines.

TODO: remove duplicate code

#!/bin/bash

NUMBER_OF_PINGS=3

HOST_NAME="myhostname.local"

FLAG_FILE=/home/pi/$HOST_NAME.isdead

EMAIL_SENDER=foo@gmail.com

EMAIL_RECEIVER=bar@gmail.com


#ping returns 0 if target could be reached


if ping -c $NUMBER_OF_PINGS $HOST_NAME &> /dev/null

then # host is reachable

  if test -f $FLAG_FILE  # flag file exists

  then

  { echo To: $EMAIL_RECEIVER

    echo From: $EMAIL_SENDER

    echo Subject: 👍 $HOST_NAME is alive again

    echo Congrats! $HOST_NAME is alive again. 

  } | /usr/sbin/ssmtp $EMAIL_RECEIVER

  rm $FLAG_FILE   # delete flag file and send email

  else # nothing to do

    :

  fi

else # host is NOT reachable

  if test -f $FLAG_FILE  # flag file exists, which means that an email has already been sent

  then  # nothing to do

    :

  else  # send an email otherwise and create flag file

  { echo To: $EMAIL_RECEIVER

    echo From: $EMAIL_SENDER

    echo Subject: ☠️  $HOST_NAME is dead

    echo My condolences. I tried to ping $HOST_NAME $NUMBER_OF_PINGS times, but did not get a response. 

  } | /usr/sbin/ssmtp $EMAIL_RECEIVER

  touch $FLAG_FILE

  fi

fi

Sunday, January 30, 2022

apache2, flask, python3 on macos 12.2 (Monterey)

   Here are the steps:

1. Install homebrew

    https://brew.sh/

2. Install apache

    brew install apache2

3. Install python

    brew install python3 

4. Install mod-wsgi (apache module to run scripts)

    pip3 install mod-wsgi

5. Modify /opt/homebrew/etc/httpd/httpd.conf; add this (and adapt names in bold to your specific installation)

LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

LoadModule wsgi_module /opt/homebrew/lib/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-darwin.so

WSGIApplicationGroup %{GLOBAL}

<Directory "/Users/wahl/Development/excel_ws">

        Options Indexes MultiViews

        AllowOverride none

        Require all granted

</Directory>

WSGIScriptAlias /excel_ws /Users/wahl/Development/excel_ws/WebService.wsgi        

        assuming that the Flask application resides in /Users/wahl/Development/excel_ws and that the relative URL is /excel_ws.

6. Create the .wsgi file - this is a short python script that launches flask (in the example above, it is called WebService.wsgi residing in our flask application directory). We further assume that the Python source files reside in the directory src relative to the .wsgi file. The flask app is defined in src/WebService.py.

        #! /usr/bin/python3

    import logging

    import sys

    import os

    logging.basicConfig(stream=sys.stderr)

    sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/src')

    from WebService import app  as application

    application.secret_key = 'some super secret string'