Releasing a locked port on a Mac / OS X

Sometimes a port doesn’t release properly resulting in servers staring on non-standard ports.

How do you release the port? Easy, use this:

lsof -i :portnumber

Grab the resulting PID and kill the process. Use -9 if you really have to.

Here’s a “worked example”:

$ lsof -i :1990
COMMAND  PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    2857 david   39u  IPv6 0x23ed6292526f5971      0t0  TCP *:stun-p1 (LISTEN)
$ kill -9 2857

Customising Atlassian Confluence with header photos

header-image-demo-page

Header photos are all the rage (as my mother might say). Twitter has them. So does Facebook. Yup, even LinkedIn has them.

Confluence is a great platform for documentation, but what if you want to add extra some flare to your pages? Would a custom header photo be a good idea? Maybe so.

This post gives a simple method to do just that for pages that use the Default Theme.

In Confluence Admin | Configuration | User Macros create a new user macro:

## Macro: header-photo
## Author: David Simpson
##
## @param Photo:title=Header Photo|type=enum|enumValues=akabilk,captain_oblivion,rikpiks,renateflynn,grotan|default=red|desc=Choose a photo from one of these Flickr users
##
<script>AJS.toInit(function($){ $('body').addClass('header-photo photo-${paramPhoto}'); }); </script>

This gives you a user macro with some options to swap the background image between these images:

In Confluence Admin | Look and Feel | Stylesheet add the following:

/**  
 *  Uses the {header-photo} user macro to trigger the styles:
 */ 

.header-photo #main-header {
	margin: -20px;
	padding: 20px;
	background: #69c;
}

.header-photo #title-text {
	padding-top: 40px
}

.header-photo #breadcrumbs a,
.header-photo #title-text a,
.header-photo .page-metadata,
.header-photo .page-metadata ul li a
 {
	color: #fff;
	text-shadow: 2px 2px 5px #000;
}

/*** Hide these until mouseover/hover ***/
.header-photo #page-metadata-banner,
.header-photo #breadcrumbs,
.header-photo #navigation,
.header-photo .page-metadata {
	transition         : opacity .25s ease-in-out;
	-moz-transition    : opacity .25s ease-in-out;
	-webkit-transition : opacity .25s ease-in-out;
	opacity: 0;
}

/*** Display on mouseover/hover ***/
.header-photo #breadcrumbs:hover,
.header-photo #navigation:hover,
.header-photo .page-metadata:hover {
	opacity: 1;
}

.header-photo #main-header {
	background-size: cover;
	background-color: #000;
	background-position: 50% 50%;
}

/*** Each of these backgrounds has been selected from Flicker and uses a Creative Commons license ***/

/* From: flickr.com/photos/grotan/14035217861 */
.header-photo.photo-akabilk #main-header {
	background: #000 url(//davidsimpson.me/wp-content/uploads/2014/11/flickr.com-photos-grotan-14035217861.jpg)  no-repeat  ; 
}

/* From: flickr.com/photos/captain_oblivion/5601940290 */
.header-photo.photo-captain_oblivion #main-header {
	background-image:  url(//davidsimpson.me/wp-content/uploads/2014/11/flickr.com-photos-captain_oblivion-5601940290.jpg); 
}

/* From: flickr.com/photos/rikpiks/7721449224 */
.header-photo.photo-rikpiks #main-header {
	background-image: url(//davidsimpson.me/wp-content/uploads/2014/11/flickr.com-photos-rikpiks-7721449224.jpg); 
}

/* From: flickr.com/photos/renateflynn/8884401289 */
.header-photo.photo-renateflynn #main-header {
	background-image: url(//davidsimpson.me/wp-content/uploads/2014/11/flickr.com-photos-renateflynn-8884401289.jpg); 
}

/* From: flickr.com/photos/grotan/14035217861 */
.header-photo.photo-grotan #main-header {
	background-image: url(//davidsimpson.me/wp-content/uploads/2014/11/flickr.com-photos-grotan-14035217861.jpg); 
}

This is a simple bit of CSS that adds a different background to the page header based on the body class added in the user macro. I’ve purposefully chosen only dark backgrounds so that I can use a single text colour. Yes, that was quite lazy. You can embellish with more styles as required.

Here’s the macro configuration screen:

edit-header-photo-macro

The macro parameter values in the dropdown match the CSS classes in the custom global stylesheet. It’s pretty straightforward.

I’ve really restricted the number of photos available here. This is just an example of how you could implement a feature like this. You could easily adapt this for custom photos on every space or every page if you really feel like it.

Perhaps random photos is the way forward for you? If so, you could do worse than placekitten.com.

Secure development on Atlassian SDK using useHttps

Check the <useHttps>true</useHttps> configuration item. It appears to be a bit of a secret that could handle some more exposure. It starts Atlassian SDK running over HTTPS/SSL on port 443 without the need for a proxy server. Nice.

You can add it here:

<plugin>
    <groupId>com.atlassian.maven.plugins</groupId>
    <artifactId>maven-confluence-plugin</artifactId>
    <version>${amps.version}</version>
    <extensions>true</extensions>
    <configuration>
        <productVersion>${confluence.version}</productVersion>
        <productDataVersion>${confluence.data.version}</productDataVersion>
        <useHttps>true</useHttps>
     </configuration>
</plugin>

You’ll need to start the server like so:

sudo atlas-run

Otherwise, you’ll likely get the following error trying to bind to port 443 as a non-root user:

[INFO] [talledLocalContainer] SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-bio-443"]
[INFO] [talledLocalContainer] java.net.BindException: Permission denied <null>:443
[INFO] [talledLocalContainer] 	at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:406)
[INFO] [talledLocalContainer] 	at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:610)
[INFO] [talledLocalContainer] 	at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:429)
[INFO] [talledLocalContainer] 	at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)
[INFO] [talledLocalContainer] 	at org.apache.catalina.connector.Connector.initInternal(Connector.java:981)
[INFO] [talledLocalContainer] 	at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
[INFO] [talledLocalContainer] 	at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
[INFO] [talledLocalContainer] 	at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
[INFO] [talledLocalContainer] 	at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:814)
[INFO] [talledLocalContainer] 	at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
[INFO] [talledLocalContainer] 	at org.apache.catalina.startup.Catalina.load(Catalina.java:633)
[INFO] [talledLocalContainer] 	at org.apache.catalina.startup.Catalina.load(Catalina.java:658)
[INFO] [talledLocalContainer] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] [talledLocalContainer] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[INFO] [talledLocalContainer] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] [talledLocalContainer] 	at java.lang.reflect.Method.invoke(Method.java:606)
[INFO] [talledLocalContainer] 	at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
[INFO] [talledLocalContainer] 	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
[INFO] [talledLocalContainer] Caused by: java.net.BindException: Permission denied
[INFO] [talledLocalContainer] 	at java.net.PlainSocketImpl.socketBind(Native Method)
[INFO] [talledLocalContainer] 	at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
[INFO] [talledLocalContainer] 	at java.net.ServerSocket.bind(ServerSocket.java:376)
[INFO] [talledLocalContainer] 	at java.net.ServerSocket.<init>(ServerSocket.java:237)
[INFO] [talledLocalContainer] 	at java.net.ServerSocket.<init>(ServerSocket.java:181)
[INFO] [talledLocalContainer] 	at javax.net.ssl.SSLServerSocket.<init>(SSLServerSocket.java:136)
[INFO] [talledLocalContainer] 	at sun.security.ssl.SSLServerSocketImpl.<init>(SSLServerSocketImpl.java:107)
[INFO] [talledLocalContainer] 	at sun.security.ssl.SSLServerSocketFactoryImpl.createServerSocket(SSLServerSocketFactoryImpl.java:84)
[INFO] [talledLocalContainer] 	at org.apache.tomcat.util.net.jsse.JSSESocketFactory.createSocket(JSSESocketFactory.java:182)
[INFO] [talledLocalContainer] 	at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:393)
[INFO] [talledLocalContainer] 	... 17 more
[INFO] [talledLocalContainer] 

Does this work well?

Yes and no. It’s super easy to get going provided you remember about root permissions, but there are drawbacks.

You have to sudo on redeploys, and well, pretty much everything you do.

This seems like overkill though:

sudo atlas-package

atlas-install-plugin or sudo atlas-install-plugin doesn’t work as it tries to install to port 1990 for Confluence, 2990 for JIRA and so forth.

I ended up uploading the plugin via the UPM each time it was redeployed. That’s just rubbish.

This however, should work nicely:

sudo atlas-install-plugin --http-port 443

Will I continue to use this?

I’m not sure at the moment, unless its just for a very quick test or for JIRA development. Proxying with nginx is so easy. It’s setup and forget easy, at least for Confluence.

Debugging opensocial gadgets in IBM Connections

My standard IBM Connections installation has the following logging settings:

     *=info:
     com.ibm.social.pim.resource.*=all:
     com.ibm.lconn.homepage.services.widget.*=all:
     com.ibm.lconn.news.*=all:
     com.ibm.lconn.events.*=all:
     com.ibm.lotus.search.engine.*=all:
     com.ibm.lotus.search.index.*=all:
     com.ibm.lconn.mailin.*=all:
     com.ibm.lotus.connections.core.notify.*=all:
     com.ibm.lconn.scheduler.*=all:
     org.apache.shindig.*=all

In WebSphere, this is displayed on a single line:

*=info: com.ibm.social.pim.resource.*=all: com.ibm.lconn.homepage.services.widget.*=all: com.ibm.lconn.news.*=all: com.ibm.lconn.events.*=all: com.ibm.lotus.search.engine.*=all: com.ibm.lotus.search.index.*=all: com.ibm.lconn.mailin.*=all: com.ibm.lotus.connections.core.notify.*=all: com.ibm.lconn.scheduler.*=all: org.apache.shindig.*=all

Continue reading…

Atlassian Confluence hides create button and top navigation on license expiry

confluence-licensing

This was driving me crazy. I developed an add-on for Confluence, but sometimes the top navigation bar was missing items.

I was concerned that my add-on was really misbehaving and interfering in some way with the core product. There was no need to worry as Danielle figured it out.

On license expiry, rather than informing you that the license has expired, it simply disables features in the main header such as:

  • Spaces
  • People
  • Create button
  • The search box

If you run a product under the Atlassian SDK, you get a single day license. If you leave it overnight and come back, bits of the product (such as the Create button) get disabled. Restarting the product resets the license, so the disabled parts start working again. This doesn’t seem to be documented anywhere as far as I can tell.
Continue reading…

Entity Conversion Calculator (for CSS and JavaScript)

Filed under note to self.

I have trouble remembering how to convert characters into hex for JavaScript or CSS.

For example, sometimes I like to use » for breadcrumb separators using CSS something like this: ul.breadcrumb a:after {content:'\0064';} but can’t remember the precise hex code.

To fix this, here’s Evolution Technologies’ Entity Conversion Calculator iframed in this page:

I’m not claiming any ownership here, I’ve just embedded it for my own convenience.

How can I set environment variables for GUI apps in OS X Mavericks?

Adapted from a SuperUser answer:

/etc/launchd.conf does not exist by default, but it does still work in 10.9.

  1. Run for example sudo nano /etc/launchd.conf.
  2. Add a line like 
    setenv M2_HOME /opt/boxen/homebrew/Cellar/atlassian-plugin-sdk/5.0.0/libexec/apache-maven-3.2.1/
  3. Run 
    launchctl < /etc/launchd.conf
    sudo launchctl < /etc/launchd.conf

     and relaunch processes.