paint-brush
How Termux saved my assby@sebastian212000
24,365 reads
24,365 reads

How Termux saved my ass

by Antonis TsagarisMarch 26th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

I have a dirty secret.

People Mentioned

Mention Thumbnail

Company Mentioned

Mention Thumbnail
featured image - How Termux saved my ass
Antonis Tsagaris HackerNoon profile picture

One of the reasons why Android rocks

I have a dirty secret.

Looxie, my location-based photo request app, sends push notifications. That’s not the secret: lots of apps do that.

Still not a secret: Looxie uses Google Cloud Messaging (now renamed into Firebase Cloud Messaging) to send the notifications. Up until recently, before the introduction of Firebase Cloud Functions, you had to have your own server running & following the Firebase real-time database for changes.

I am still using this architecture because, for some reason, I can’t seem to get the node.js server I created to run as a Firebase Cloud Function.

Here comes the secret: the node.js server is running on an old ASUS laptop I bought for $300. After a catastrophic HDD failure that came completely out of nowhere (OK, I punched it during a particularly challenging section in Limbo), I replaced the hard disk with an SSD and installed Ubuntu because I was too cheap to purchase a Windows license.

Doesn’t sound too bad, right? Well, here’s where it gets good: the laptop is connected to the web using Wi-Fi. When the router starts spazzing out (which happens with alarming frequency) the connection drops and Ubuntu requests the password again before it can connect to the web. If I am not around to enter the password and press “enter”, Looxie stops sending push notifications.

Thankfully, I live minutes from my office, so when the connection drops I go there and reconnect the PC to the internet. Which is still a silly thing to do but at least it works.

So imagine how stressful it was for me to leave Cyprus for twenty days for a trip, all the while thinking “how the hell am I going to bring the server back if (or more realistically, when) the connection drops while I’m away?”


Buy Antonis Tsagaris a Coffee - BuyMeACoffee.com_I'm an Android developer and designer with a love for beautiful UIs!_www.buymeacoffee.com

Connection drops while I’m away

Five days into the trip, Looxie stops sending push notifications.

Shit.

I call my brother and ask him to go reconnect the laptop to the internet. My brother happily obliges but, as these things tend to go, one day later the laptop disconnects again.

At that point I felt something like this:

Frustrated, I walk into a T-Mobile store in San Francisco with a plan. I buy a SIM card loaded with 2GBs of data and put my plan into action.

Termux comes into the picture

I had heard of Termux before in the /r/androiddev subreddit. I actually had it installed on my Nexus 6P but never really used it. Having a Linux terminal emulator on your phone is one of those things that sounds cool at first but ends up having too little practical use in the end.

Not this time. This time I went

apt install git

and… what? Git was installed. After initializing a repo in Termux, I pulled the entire Looxie repository from Github.

So far, so good. But… how the hell am I going to get node.js running on here? Well, how about

apt install nodejs

It was a shot in the dark but, to my surprise, something started happening.

A couple of minutes later, I had a node.js installation running in Termux. This was as far as my luck would possibly stretch though, right?

“Well, it’s not like I have anything to lose”, I thought, as I started typing

npm install nodemon

And… holy crap, it worked!

More than a little addicted to the awesomeness, I typed

apt install nano

because I had thought of a change I could do in the JavaScript source code that would solve a minor bug in the server.

You get the idea: it worked.

It couldn’t possibly be this easy, right? Something was going to go horribly wrong when I typed

nodemon looxieapp.js

to start the server.

Nothing went horribly wrong.

Nothing.

The server started and it worked perfectly. Looxie was sending push notifications once again.

My only worry? The server stopping when the phone would go into Android’s infamous “Doze” mode — which does not work when you want it to and works when you don’t want it to.

Doze mode: does not work when you want it to and works when you don’t want it to

Termux had me covered, again: in its notification in the notification drop-down, it had the option to “acquire wakelock”.

I acquired wakelock.

And went to sleep.