Thursday, April 9, 2015

Jenkins and Gradle Behind a Proxy

Getting Jenkins CI to build using Gradle behine a proxy do the following:
1. Specify proxy settings in you gradle.properties file in your project:
# for http
systemProp.http.proxyPort=80
systemProp.http.nonProxyHosts=*.cat.com|localhost
systemProp.http.proxyHost=proxy.ap.cat.com

# for https
systemProp.https.proxyHost=proxy.ap.cat.com
systemProp.https.proxyPort=80
systemProp.https.nonProxyHosts=*.cat.com|localhost

2. Copy these settings to (create if necessary) a gradle.properties file in your USER_HOME/.gradle directory
3. In Jenkins navigate to Manage Jenkins > Configure System. Under Global properties check Environment variables and fill in the following for name and value:
name: GRADLE_OPTS
value: -Dgradle.user.home=/home/tomcat/.gradle -Dhttp.proxyHost=[proxy] -Dhttp.proxyPort=[proxy_port]

Where [proxy] is the proxy url and [proxy_port] is the port for that proxy. Add https options if required.

Monday, January 6, 2014

Automatic Location Switching in OSX Mavericks

I have had this issue for a while, where I travel between different locations and hence use different networks to connect to, yet I have to manually switch between these locations and their proxies
After trawling the internet for many variant complicated solutions I came up with a simple combination of many solutions. Two files are required, which can be modified according to your network settings, placed in the specified directories.
/usr/local/bin/locationchanger.sh
#!/bin/bash

#Note: make shore the log directory exists or modify the script to create it or 
#change the path to log to another location if you want logging.
LOG_FILE="/usr/local/var/log/locationchanger.log"
[ ! -f "$LOG_FILE" ] && touch "$LOG_FILE"

#Comment this line out if you don't want logging.
exec &>$LOG_FILE

LOCATION=
sleep 2
#Create as many locations as you need giving them unique names. Make sure the 
#values are valid values as are found in the Network Preferences Location dropdown
Location_Work="WorkLocationNameGoesHere"
Location_Other="OtherLocationNameGoesHere"
Location_Custom="CustomLocationNameGoesHere"
Location_Automatic="Automatic"

#These SSIDs must be wifi and wired networks which your computer knows 
#about or connects to.
SSID_Work="WRK_NET"
SSID_OTHER="MUMS_INTERNET"
SSID_Custom="BNE_AIRPORT"

Proxy_Work="http://proxy.work.com:80"
Proxy_Custom="http://proxy.custom.com:8021"
No_Proxy=

CurrentLocation=`networksetup -getcurrentlocation`
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep ' SSID:' | cut -d ':' -f 2 | tr -d ' '`
echo `date` "New SSID found: $SSID"

#Customise the cases according to your need and what you want set or run. 
#I have only shown how we can set proxies where necessary.

case $SSID in
 $SSID_Work  ) 
    LOCATION="$Location_Work"
    export http_proxy="$Proxy_Work"
    export ALL_PROXY="$http_proxy"
    echo "http_proxy=$Proxy_Work"
   ;;
        $SSID_Other )
                  LOCATION="$Location_Other"
    export http_proxy="$No_Proxy"
    export ALL_PROXY="$http_proxy"
    echo "http_proxy=$No_Proxy"

        $SSID_Custom )
                  LOCATION="$Location_Custom"
    export http_proxy="$Proxy_Custom"
    export ALL_PROXY="$http_proxy"
    echo "http_proxy=$Proxy_Custom"

        *  )      # Default for all other networks
    LOCATION="$Location_Automatic"
    export http_proxy="$No_Proxy"
    export ALL_PROXY="$http_proxy"
    echo "Proxy disabled."
  ;;
esac
 
scselect $LOCATION
echo "Location changed to $LOCATION based on $SSID"
exit 0


After creating the /usr/local/bin/locationchanger.sh and modifying it accordingly run the following command to make it executable:
sudo chmod +x /usr/local/bin/locationchanger.sh

~/Library/LaunchAgents/LocationChanger.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>locationchanger</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/locationchanger.sh</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>/etc/resolv.conf</string>
        <string>/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist</string>
        <string>/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>
Run the following to start this list checking for network changes:
launchctl load ~/Library/LaunchAgents/LocationChanger.plist

Thursday, November 28, 2013

Automatically Setting Proxies in OSX for Terminal Windows

If you want your proxies to be set based on network locations add the following to your .bash_profile file (located in your user home directory) using your editor of choice (vi, vim, nano, etc).

CurrentLocation=`networksetup -getcurrentlocation`
if [ "$CurrentLocation" == "Caterpillar" ]; then
    export http_proxy=http://proxy.cat.com:80
    echo http_proxy=http://proxy.cat.com:80
fi

Brew update gives error: Your local changes to the following files would be overwritten by merge:

This happens if your brew repository has become corrupt for some reason or permissions have changed and brew is unable to update.

To fix run the following from a terminal window.

cd `brew --prefix`
git remote add origin https://github.com/mxcl/homebrew.git
git fetch origin
git reset --hard origin/master

Sunday, March 24, 2013

Duplicate "Open With..." Entries in Mac OSX

Removing duplicate items in the Right-Click open with menu can be done as follows:


1. Terminal: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/\
LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local\
-domain system -domain user
2. Relaunch Finder: Ctrl+Option+Click Finder -> Relaunch

Monday, August 30, 2010

How to Reset the Root Password for MYSQL DB

Windows Systems
On Windows, use the following procedure to reset the password for all MySQL root accounts:
  1. Log on to your system as Administrator.
  2. Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.
    If your server is not running as a service, you may need to use the Task Manager to force it to stop.
  3. Create a text file containing the following statements. Replace the password with the password that you want to use.
    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    FLUSH PRIVILEGES;
    Write the UPDATE and FLUSH statements each on a single line. The UPDATE statement resets the password for all root accounts, and the FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
  4. Save the file. For this example, the file will be named C:\mysql-init.txt.
  5. Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.
  6. Start the MySQL server with the special --init-file option (notice that the backslash in the option value is doubled):
    C:\> C:\mysql\bin\mysqld-nt --init-file=C:\\mysql-init.txt
    If you installed MySQL to a location other than C:\mysql, adjust the command accordingly.
    The server executes the contents of the file named by the --init-file option at startup, changing each root account password.
    You can also add the --console option to the command if you want server output to appear in the console window rather than in a log file.
    If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option:
    C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe"
             --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini"
             --init-file=C:\\mysql-init.txt
    The appropriate --defaults-file setting can be found using the Services Manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list, right-click it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.
  7. After the server has started successfully, delete C:\mysql-init.txt.
You should now be able to connect to the MySQL server as root using the new password. Stop the MySQL server, then restart it in normal mode again. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.
Unix Systems
On Unix, use the following procedure to reset the password for all MySQL root accounts. The instructions assume that you will start the server so that it runs using the Unix login account that you normally use for running the server. For example, if you run the server using the mysql login account, you should log in as mysql before using the instructions. Alternatively, you can log in as root, but in this case you must start mysqld with the --user=mysql option. If you start the server as root without using --user=mysql, the server may create root-owned files in the data directory, such as log files, and these may cause permission-related problems for future server startups. If that happens, you will need to either change the ownership of the files to mysql or remove them.
  1. Log on to your system as the Unix user that the mysqld server runs as (for example, mysql).
  2. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/. Generally, the file name has an extension of .pid and begins with either mysqld or your system's host name.
    You can stop the MySQL server by sending a normal kill (not kill -9) to the mysqld process, using the path name of the .pid file in the following command:
    shell> kill `cat /mysql-data-directory/host_name.pid`
    Use backticks (not forward quotation marks) with the cat command. These cause the output of cat to be substituted into the kill command.
  3. Create a text file containing the following statements. Replace the password with the password that you want to use.
    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    FLUSH PRIVILEGES;
    Write the UPDATE and FLUSH statements each on a single line. The UPDATE statement resets the password for all root accounts, and the FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
  4. Save the file. For this example, the file will be named /home/me/mysql-init. The file contains the password, so it should not be saved where it can be read by other users.
  5. Start the MySQL server with the special --init-file option:
    shell> mysqld_safe --init-file=/home/me/mysql-init &
    The server executes the contents of the file named by the --init-file option at startup, changing each root account password.
  6. After the server has started successfully, delete /home/me/mysql-init.
You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.
Generic Instructions
The preceding sections provide password-resetting instructions for Windows and Unix systems. Alternatively, on any platform, you can set the new password using the mysql client (but this approach is less secure):
  1. Stop mysqld and restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges.
  2. Connect to the mysqld server with this command:
    shell> mysql
  3. Issue the following statements in the mysql client. Replace the password with the password that you want to use.
    mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
        ->                   WHERE User='root';
    mysql> FLUSH PRIVILEGES;
    The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables option).

Wednesday, August 11, 2010

Windows PS and Kill Command Equivalents

tasklist /v  - equivalent to ps aux
taskkill /f /im ncover*  - equivalent to kill -9 ncover*