Thursday, April 18, 2024

Give your docker host a dedicated hostname

 Docker by default has different containers running on different ports.  So you can have multiple hostnames all go to the same machine, but they won't automatically go the same ports if you're just using DNS.  

Solution is to have a webserver (we'll be using apache), which does an automatic forward to the port depending on the hostname being used.  

1) Have the multiple hostnames all refer to the docker host via IP address (if this is a home network dnsmasq or unbound will usually allow multiple hostnames to one IP if you do it manually).  

2) In your apache config file directory (mine is /etc/apache2/sites-enabled) create a config file 

-we'll call ours "docker-redirects.conf", but you can name it anything that makes sense to you.

 <VirtualHost *:80>

ServerName docker1.locadomain

Redirect 301 / http://host.localdomain:3001

</VirtualHost>

 

 <VirtualHost *:80>

ServerName docker2.locadomain

Redirect 301 / http://host.localdomain:3002

</VirtualHost>

 

etc...  


The above will allow anyone on your local network to type in docker1 (or whatever name you use instead), and then apache will automatically forward them to the right docker container based on the domain name they typed in.  

Thursday, May 30, 2019

WSUS cleaning wizard fails 'Database Error'

If while running the WSUS cleaning wizard you get a Database error that looks like this:


You could reboot the server that WSUS is running on, but if it's used for other things also (e-mail, dhcp, dns, file, printing, etc...), you'll have to wait till there's downtime, before trying again.

Another option though is to restart the database service.
If you go to administrative tools -> services (or runbox services.msc), look for 'Windows Internal Database" and right click on it, and select restart

or from an admin command prompt:
sc stop mssql$microsoft##wid
sc start mssql$microsoft##wid

Then go back to the wsus management console, click on reset server node, and you should now be able to run the cleaning wizard (it'll probably take a couple hours or more, but it shouldn't give you an error),

And you were able to do this without interrupting whatever else may be running on it.



Monday, September 21, 2015

Firefox freezing on linux (x2go)

Not scripting related however:
I am using x2go to access my linux (ubuntu) system remotely, using the kdeWM.  If I use firefox though, the moment I right click anywhere on a web page (say to open a link in a new tab or window), firefox freezes.

Turns out it's an issue with the pulse audio daemon, and at least if you're using x2go like me, it's easy to fix once you know what the problem is.

When disconnected from your linux server, in the x2go client, go into the session preferences, click on the Media tab -> and uncheck "Enable sound support".   Selecting esd might also fix it, but I haven't tried that.

Many thanks to the comment by oms-ubun at: https://bugs.launchpad.net/ubuntu/+source/firefox-3.0/+bug/528798  for directing me to the issue.




Tuesday, March 24, 2015

linux (fedora) how to change your screen resolution

The following are intended for when you're using a virtual machine (proxmox host in my case), and the resolution is too high for your 1080p laptop screen that you're using to manage the VMs remotely.
However these methods will probably work with a physical linux installation also (not just a virtual one).


As of 2015 the following method worked for me on Fedora 21 (server version):
Edit the following file with your favorite text editor (mine is VIM): /etc/default/grub
find the line starting with: GRUB_CMDLINE_LINUX=
and put at the end: video=800x600"
when you're done the line should look something like:
GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora-server/root rd.lvm.lv=fedora-server/swap rhgb quiet video=800x600"

note: instead of 800x600 you can use, 640x480 or 1024x768 also

sources:
https://fedoraproject.org/wiki/Display_resolution_of_Fedora_18_virtual_machines
https://fedoraproject.org/wiki/GRUB_2?rd=Grub2


To change the resolution off X-windows (xorg),
xrandr --output VGA-0 --mode 800x600
-if you have any errors type xrandr by itself, (and hit enter), and you will see a list of available outputs and the list of modes for each one:
source: https://wiki.archlinux.org/index.php/xrandr


edit: below is my original method, which newer versions of fedora (as of 2015/ fedora 21) doesn't appear to work very well.

If you're running fedora in a virtual machine (proxmox, vmware, virtualbox), and the screen resolution of fedora in console mode (not X), is so high that it takes up your entire screen you can change it using fbset.

If you don't have fbset, first you'll have to install it "sudo yum install fbset"

Then you can change the resolution with the following:
sudo fbset -xres 800 -yres 600
(can use 1024 768, or other resolutions also).


Wednesday, November 5, 2014

chrome for enterprise auto download

In a work environment normally you want to download one copy of an update to one computer, and then copy it to the rest of the computers.  This way you don't clog up your office's internet connection.  While proxys can work, they are often tricky to configure.

Google has a version of chrome that will install for all users on a computer, that you can manage (like disable group updates, and configure some other settings).  Details are at: http://wpkg.org/Google_Chrome.  They also have a script that will download proper version of chrome and rename it so you can deploy it using a tool to the computers in your enterprise (which is designed to work with their deployment tool but I made it work with some slight modifications).

Chrome has an rss feed at http://googlechromereleases.blogspot.com/ which will notify you when there's an update.  While you could check it every day, how likely are you going to miss the day it came out, and then end up either downloading it during the day (clogging people's bandwidth), or waiting another day to schedule the download?
Below is my batch script for checking the rss feed, and if it sees there's an updated chrome, will call a script that download it automatically.

Now when you see there's a new version of chrome, it's already downloaded (if you scheduled the checking script to run every night).  I then create a package using local update publisher or wsus package publisher.


rem -----------------------------------------------------------------------------------------------
@echo off
set updatesloc=\\server\share\folder\google-chrome
rem set debug=1 if you have any problems.
set debug=0
if %debug%==1 echo grabbing the feed at %time%
wget http://googlechromereleases.blogspot.com/ -O %temp%\chrome-updates-feed.html
rem searching the feed for the current chrome version, and breaking out as soon as we
rem find the first one (that's not for chrome OS).

if %debug%==1 echo searching the downloaded feed for the current version at %time%
for /f "tokens=8" %%v in ('find /i "The stable channel has been updated to " %temp%\Chrome-updates-feed.html ^|find /v "Chrome OS"') do (
set curver=%%v
goto endverfind
)
:endverfind

if %debug%==1 echo searching the directory of downloaded updates to see if we already have the current version %time%
rem if the curver string length is less then three characters it's probably not valid.
rem google uses very long version numbers like: 38.0.2125.111
if "%curver:~3,1%"=="" goto end

for /f "tokens=1" %%d in ('dir /s /b %updatesloc% ^|find /c "%curver%"') do set curverdownloaded=%%d
if %debug%==1 echo search complete now to figure out what to do %time%
if %curverdownloaded%==0 goto downloadnewver
if %curverdownloaded%==0 goto gotcurver

:gotcurver
echo got the current version, %curver% nothing to do
goto end

:downloadnewver
echo need to download the newest version %curver%, at %time%
c:\windows\syswow64\cscript.exe %updatesloc%\update-chrome.vbs
goto end

:end
echo %time%
rem -------------------------------------------------------------------


my modified download vbscript (based heavily on the script at http://wpkg.org/Google_Chrome)
make sure you've downloaded dsofile
www.microsoft.com/downloads/details.aspx?FamilyID=9ba6fac6-520b-4a0a-878a-53ec8300c4c2&DisplayLang=en
and that you have wget in your path, wget is needed for the batch file above also.
http://gnuwin32.sourceforge.net/packages/wget.htm


'------------------------------------------------------------------------
' update-chrome.vbs -- stored in %updatesloc%\google-chrome
'from http://wpkg.org/Google_Chrome
Option Explicit
Dim objFSO, objFile, strFileProperties, objShell, strChromePath, strChromeURL
Dim strVersion, objResult, strChromeFilename, objOleFile, arrComments
Dim strTemplateFilename, ForReading, ForWriting, strText
Dim strNewText

strChromePath = "j:\patches\google-chrome\"
'strChromePath = "c:\downloads\"
strChromeFilename = "GoogleChromeStandaloneEnterprise.msi"
strTemplateFilename = "google-chrome-template.xml"
strChromeURL = "https://dl.google.com/edgedl/chrome/install/" & _
strChromeFilename

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOleFile = CreateObject("DSOFile.OleDocumentProperties")

objShell.CurrentDirectory = strChromePath
' wget downloaded from http://users.ugent.be/~bpuype/wget/
objResult = objShell.Run("wget --limit-rate=200k --no-check-certificate " & strChromeURL, 1, True)
If objFSO.FileExists(strChromePath & strChromeFilename) Then
' Grab version number. Requires Office installation, or DSOFile.dll
' from http://support.microsoft.com/kb/224351
objOleFile.Open(strChromePath & strChromeFilename)
arrComments = Split(objOleFile.SummaryProperties.Comments, " ", 2)
strVersion = arrComments(0)
objOleFile.Close

' Make a copy of the file
Set objFile = objFSO.GetFile(strChromePath & strChromeFilename)
objFile.Copy strChromePath & "GoogleChromeStandaloneEnterprise-" & _
strVersion & ".msi", True
' Delete the original file
objFile.Delete True
' Update package definitions
' updateXML strTemplateFilename, _
' "..\..\packages\google-chrome.xml" ' legacy tree
' updateXML strTemplateFilename, _
' "..\..\dev\packages\google-chrome.xml" ' dev tree
' updateXML strTemplateFilename, _
' "..\..\stable\packages\google-chrome.xml" ' stable tree
Else
MsgBox "Selected file does not exist!"
End If

'Sub updateXML(strTemplateFilename, strPackageFilename)
' Update package definition
' ForReading = 1
' ForWriting = 2
' Set objFile = objFSO.OpenTextFile(strTemplateFilename, ForReading)
' strText = objFile.ReadAll
' objFile.Close
' strNewText = Replace(strText, "__VERSION__", strVersion)
 '
' Set objFile = objFSO.OpenTextFile(strPackageFilename, ForWriting)
' objFile.WriteLine strNewText
' objFile.Close
'End Sub
'-----------------------------------------------------------------------------

Thursday, August 7, 2014

finding your interface name for netsh

How to find the name of your interface for netsh.

In a previous post I had a ip changing script that used netsh to change the ip addresses.
The main syntax being: "netsh interface ip set address "Local Area Connection" static 192.168.1.53 255.255.255.0 192.168.1.1 1

However in windows 8, there are two issues:
1) you now have to use ipv4 instead of ip,
2) my previous method of using ipconfig to find the name of the network connection to use, doesn't work.

For the second issue I would get the error: "The filename, directory name, or volume label syntax is incorrect."

To find the correct name for your connection (where it says "Local Area Connection" above), type in:
netsh interface show interface
This will list the currently enabled interfaces, which hopefully will include the one you're trying to mess with.  If the one you want isn't listed, make sure it's associated with a wireless network (if it's the Wi-Fi interface),  or the network cable is plugged in if it's a wired interface.


Thursday, January 23, 2014

windows ip switcher

Where I work, I support multiple offices.  Most of the offices do not have DHCP, they use static ip addresses (not my decision).  So here is a script I made for changing the ip address settings on a windows laptop, this does have to be ran with full admin privileges.  You will have to change parts of this script for your usage (where ever you see an ip address, and probably want to change the labels for the networks also).

echo ip-switch ver 20081119

set baseoffice=hq

rem now we figure out what subnet we're on
for /f "tokens=2 delims=:" %%i in ('ipconfig ^|find "IP Address"') do set ipaddr=%%i
for /f "tokens=2,3 delims=." %%o in ('echo %ipaddr%') do set subnet=%%o.%%p


rem based on the sub-net we determine what our location is
if /i "%subnet%" == "10.10" set loc=hq
if /i "%subnet%" == "10.11" set loc=sub
if /i "%subnet%" == "11.11" set loc=b1
if /i "%subnet%" == "11.12"  set loc=b2
if "%loc%" == "hq" set comploc=acompanyoffice
if "%loc%" == "substation" set comploc=acompanyoffice
if "%loc%" == "branch1" set comploc=acompanyoffice
if "%loc%" == "branch2" set comploc=acompanyoffice
if "%comploc%" == "acompanyoffice" goto comploc
set comploc=remote
:comploc


echo off

:complocmenu
cls
if "%comploc%" == "acompanyoffiice" echo this computer is currently setup for %comploc% (%loc%) use
if "%comploc%" == "remote" echo this computer is currently setup for %comploc% use
echo where is this laptop now (so it can communicate with the internet)?
echo 1) your base office (%baseoffice%)
echo 2) remote, home/other office
echo x) exit (leave everything as it is)
echo if another office enter the two-three letter abbreviation for it,
echo (hq,sub,b1,b2,etc...), and press enter, otherwise,
set /p comploc=press 1,2 or x and then enter:
rem if we entered a correct choice go to the next menu
if "%comploc%" == "1" goto methodmenu
if "%comploc%" == "2" goto methodmenu
if "%comploc%" == "x" echo no changes will be made
if /i "%comploc%" == "x" goto endprog
if /i "%comploc%" == "hq" goto otheroffice
if /i "%comploc%" == "sub" goto otheroffice
if /i "%comploc%" == "b1" goto otheroffice
if /i "%comploc%" == "b2" goto otheroffice


cls
rem if we entered a wrong chose clear screen of distraction
rem and ask for correct input
echo "you must press 1 or 2, or just press enter"
goto complocmenu

:otheroffice
set baseoffice=%comploc%
goto methodmenu

:methodmenu
echo is the laptop plugged in or using wireless?
echo 1) plugged in
echo 2) wireless
echo x) endprog
set /p netmethod=press 1 or 2 and then press enter

if "%netmethod%" == "1" set conmethod="Local Area Connection"
if "%netmethod%" == "2" set conmethod="Wireless Network Connection"
if "%netmethod%" == "1" goto methodselected
if "%netmethod%" == "2" goto methodselected
if "%netmethod%" == "x" goto endprog
echo "incorrect method selected"
goto methodmenu
:methodselected


if "%comploc%" == "1" goto staticip
if "%comploc%" == "2" goto dhcpip

:staticip
echo we will configure the computer for jcc office use
rem goto endprog
rem remove the goto endprog when we fix these settings
rem set static ip address (needs to be edited)

for /f "tokens=1 delims=-" %%I in ('echo %baseoffice%') do set loc=%%I
for /f "tokens=2 delims=-" %%C in ('hostname') do set compip=%%C
echo computer ip is %compip%

if /i "%baseoffice%" == "h1" set netaddr=10.10.10
if /i "%baseoffice%" == "sub" set netaddr=10.10.11
if /i "%baseoffice%" == "b1" set netaddr=10.11.11
if /i "%baseoffice%" == "b2" set netaddr=10.11.12




echo network address is %netaddr%

rem netsh interface ip set address "Local Area Connection" static %netaddr%.%compip% 255.255.255.0 %netaddr%.1 1
rem netsh interface ip set dns "Local Area Connection" static 10.91.1.21
rem netsh interface ip set wins "Local Area Connection" static 204.130.253.130
netsh interface ip set address %conmethod% static %netaddr%.%compip% 255.255.255.0 %netaddr%.1 1
netsh interface ip set dns %conmethod% static 10.91.1.21
netsh interface ip set wins %conmethod% static 10.254.2.130
rem start /wait sysdm.cpl

goto endprog


:dhcpip
rem some netsh commands to set dhcp on the interface
netsh interface ip set address name=%conmethod% source=dhcp
netsh interface ip set dns name=%conmethod% source=dhcp
netsh interface ip set wins name=%conmethod% source=dhcp
goto endprog

:endprog
hostname
for /f "tokens=2 delims=:" %%i in ('ipconfig ^|find "Default Gateway"') do set gateway=%%i
ipconfig |find "Address"
ping %gateway%
echo if you got back replys your good, if any of the requests timed out that's not good.
pause