Appending to crontab using a single shell command

Usually to edit crontab for a user, you login as that user and then run:

This usually opens up a text editor which then lets you edit the crontab. Once you are done, you save and quit, and this magically updates your crontab.

Today I was writing a script that needed to update crontab without any user interaction. After doing some digging, I found this neat way of updating my crontab;

The above example is straight out of my shell script which renews my letsencrypt certificate and then restarts the nginx server.

Setting up an OAuth2 provider

In this post, we’re going to talk about installing and setting up your very own OAuth2 provider. If you have used Facebook or Twitter logins, you’d know that they have their own OAuth2 providers. In reality, those are more than just OAuth2 providers as they also have OpenID Connect on them, however, that will be a post for another day.

Why would I want an OAuth2 provider?

Well, there are many reasons why you’d want an OAuth2 provider.

  1. Because its cool.
  2. Because its hip.
  3. Because, why not?

On a more serious note, if you have a bunch of applications running in your house, you can use your own OAuth2 provider to provide identity and custom authorisations to every app in a way that if one of those apps gets compromised, it won’t take your whole house down. This lets you operate all of your apps in a standard way.

Also, who in your family doesn’t want “Sign in via <insert_family_name>” button? 😛

For this post, we’re going to use Forgerock’s OpenAM version 13.

Continue reading →

Fixing docker service startup after using an alternative graph driver

So I was playing around with devicemapper docker storage driver the other day. It was quite nice but when I stopped the modified docker daemon and tried to start the docker service in “normal” way, I received the following error:

Clearly something had gone wrong. Upon running:

I found the following line most helpful in fixing the error:

So I ran the following command in order to remove my devicemapper driver:

Boom it worked!

Alternatively, I could’ve backed it up to tmp instead by running:

But I didn’t need any of my images anyway so I removed it.

Hope this helps.

Which process is using this port?

Sometimes, I get errors like “address is already in use” but struggle to find out what’s using that port. This happens especially with loads of stuff running in background like docker, vagrant vms, local server instances, ssh tunnels etc.

Here’s an easy way to figure out whats running on a certain port:

The second last column refers to the process using that port.

For example, running that on my mac:

Indicates that process ID 5500 is using port 8080. Doing a process check on that tells me:

Hope this helps!

Enable tomcat debugging

Shutdown tomcat and make sure that it has properly shut down by monitoring the tomcat process.

Once it has completely shutdown, export the following environment variables:

Here, we’re setting the jpda address to port 8000. Note this down as you will need this port number in order to connect via your IDE or whatever debugging tool you’re using.

Options above will run tomcat as usual so if you want to debug something that happens early on in the lifecycle, you either need to be really quick about attaching your debugger or add the following JPDA option:

This will suspend the tomcat startup until you attach your debugger.

Next, start tomcat jpda using catalina script:

At this stage, you can monitor the log in catalina.out file to make sure everything goes smoothly.

Now setup your IDE to connect to tomcat at port 8000. If you are using vagrant as your VM, make sure you are port forwarding 8000 in your network settings. If not, you can always tunnel in:

Or if its a remote server, you can just use the normal ssh command:

Hope this helps!

Credits

  • Conor Restall: For suggesting JPDA_SUSPEND option.
%d bloggers like this: