Docker "Extra Parameters" only seem to run on creation of container, not starting of container


Aathroser

Recommended Posts

I have a docker container that connects to my personal weather station (PWS) that is connected through USB. This device will randomly disconnect and reconnect (it's a "feature" of the panel), so I created some rules to give the device a name. This name is static, and will update when it reconnects. Let's say the device is /dev/mypws.

 

In Extra Parameters, I have this "--device=$(readlink -f /dev/mypws)"

This works great! When I create the container, everything works flawlessly.

 

However, when I restart the container, it doesn't run again, so the container still has the old endpoint. I would love for this command to run every time it starts. How do I get it to do that?

 

I have tried passing /dev/mypws as a device to the docker container, but it doesn't seem to like that very much for some reason.

 

If anyone has any ideas on how to pass the device in a way I haven't thought of, or some way to run the command every time I start the container, that would be fantastic.

Link to comment

I was able to make a workaround using user scripts, but it's definitely not my favorite.

 

#!/bin/bash
trap exit SIGQUIT SIGINT
echo $(date -u) "Starting Script"
devloc=$(readlink -e /dev/mypws)
echo $(date -u) "PWS is at: $devloc"
echo $(date -u) "Starting device watchdog..."
while :; do
    newloc=$(readlink -e /dev/mypws)
    if [[ "$devloc" != "$newloc" ]];then
        if [[ "$newloc" != "" ]];then
            echo $(date -u) "Device detected at a different node, running script"
        fi
        
        if [ -e /dev/mypws ]
        then
            echo $(date -u) "PWS Connected, setting permissions"
            sudo chown nobody:users /dev/bus/usb/003/* 
            sudo chmod 777 /dev/bus/usb/003/* 
            echo $(date -u) "Stopping Weewx"
            docker stop Weewx >> /dev/null
            echo $(date -u) "Removing Weewx"
            docker rm Weewx >> /dev/null
            echo $(date -u) "Restarting Weewx"
            docker run -d --name='Weewx' --net='bridge' --cpuset-cpus='2,8' -e TZ="America/Chicago" -e HOST_OS="Unraid" -e HOST_HOSTNAME="tower" -e HOST_CONTAINERNAME="Weewx" -e 'TIMEZONE'='America/Chicago' -e 'WEEWX_UID'='99' -e 'WEEWX_GID'='100' -l net.unraid.docker.managed=dockerman -l net.unraid.docker.icon='https://www.weewx.com/images/weewx-logo-128x128.png' -v '/mnt/user/appdata/weewx':'/data':'rw' --device=$(readlink -e /dev/mypws) 'felddy/weewx' >> /dev/null
            echo $(date -u) "Weewx Restarted"
            devloc=$newloc
            echo $(date -u) "PWS is now at: $devloc"
            echo $(date -u) "Resuming folder monitoring..."
        else
            echo $(date -u) "Device not connected"
            devloc="";
        fi
    fi
    sleep 10
done

 

Edited by Aathroser
consistency
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.