How to have a Play framework app autostart during boot on Elastic Beanstalk CentOS ec2 instances

So you’ve created an Elastic Beanstalk environment, you have a play framework distribution which you’ve created using play dist (either on your local environment, or right there on the server, whatever you prefer)

play dist outputs a my-app-1.0.zip file which has a self-contained version of your app with all the necessary libraries and a start script.

Afer you unzip it, you end up with a my-app-1.0/lib/ folder and a start script.

[ec2-user@ip-10-235-8-106 bullq-1.0]$ ls -l
total 24
drwxrwxr-x 2 ec2-user ec2-user 4096 Sep 27 15:35 lib
-rwxrwxr-x 1 ec2-user ec2-user 4328 Sep 27 15:35 start

Make sure it’s executable by using chmod +x start on the start script.

So now, this is all in the first ec2 instance of your elastic beanstalk environment, if you’re like me and you’ve used ubuntu/debian for your server management things can be slightly different here, since Amazon preferred CentOS for their default image, and here I’ll show you how to make your play app auto start when the server boots because you want every new machine that may be instanciated to have your app installed and to start the service as soon as the machine is up.

Create a /etc/init.d/myappd script
(I’m using ‘myapp’ here as an example, your app can be named whatever is named, so replace accordingly)

#!/usr/bin/env bash
#myappd
#Script to start|stop|restart myappd from /etc/init.d/
#By Gubatron – @gubatron – gubatron@gmail.com

#replace accordingly in these variables ‘myapp’ for the name of your app
PID_FILE=/home/ec2-user/myapp/dist/myapp-1.0/RUNNING_PID
DAEMON_NAME=myappd
DAEMON_PATH=/home/ec2-user/myapp
DAEMON=$DAEMON_PATH/dist/myapp-1.0/start

test -x $DAEMON || exit 0

set -e

function killDAEMON() {
echo “start kill daemon”
kill -9 cat /home/ec2-user/bullq/dist/bullq-1.0/RUNNING_PID
echo “end kill daemon”
}

function removePIDFile() {
if [ -e $PID_FILE ]
then
rm -f $PID_FILE
fi
}

case $1 in
start)
removePIDFile
echo “Starting $DAEMON_NAME… $DAEMON”
nohup $DAEMON &
;;
restart)
echo “Hot restart of $DAEMON_NAME”
killDAEMON
removePIDFile
COMMAND=”nohup $DAEMON &”;
echo $COMMAND
$COMMAND
rm -f $PID_FILE
;;
stop)
echo “Stopping $DAEMON_NAME”
killDAEMON
removePIDFile
;;
*)
echo “Usage: $DAEMON_NAME {start|restart|stop}” >&2
exit 1
;;
esac

exit 0

 

Wire it to autostart

The simplest way I found to have this script start when the server would boot was to add it at the end of the
/etc/rc.local file. (In ubuntu you’d register the new script with the upate-rc.d command)

#!/bin/sh
#
This script will be executed after all the other init scripts.
You can put your own initialization stuff in here if you don’t
want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

/etc/init.d/myappd start

 

How can we all own a robotic workforce?

As people become useless, how can capitalism survive?

As technology advances exponentially the fields of robotics and artificial intelligence will start taking over our jobs. More and more people already can’t find work, yet the nation is still very productive.
Yes, a lot in part due to globalization and cheaper foreign labor, but those cheap labor countries will only remain competitive against fully automated factories for so long.

Self driving vehicles will eventually be here, it’s just a matter of time before we think of driving ourselves as the most barbaric thing we ever did, our kids won’t believe we actually drove ourselves.

Self driving vehicles will take the jobs of millions of people, think bus drivers, truck drivers, taxi drivers, and these robotic vehicles will do their job infinitely better, not getting tired and for way less money.

Think Fedex, UPS, USPS announcing their first robotic delivery fleets, an then in a matter of years they start reducing their costs exponentially by letting go of +90% of their human workforce, shipping worldwide becomes faster and cheaper than ever.

If things keep going the way they are as they happen on the internet, only a handful of people will own powerful computers, shrinking economies due to technological efficiency and more wealth will be concentrated in a few.

If the same thing happens to robotized labor, we’ll find ourselves soon in civil war with so many “useless” people unemployed.

But I think there’s another end to it, while keeping capitalism.

If we are all smart about it, as we see robotization happening, we must make the decision to change a few things, without turning completely into a socialist country which in the case of latin america’s implementation of socialism, the result is usually an all too powerful government and oppressed citizens.

I believe that instead of handouts (like having a government that provides everything to people who are just useless thanks to robots being so useful) we should look at this as an opportunity to make everyone in society a stake holder of the robotic workforce.

If things would happen the right way, robots would be doing our job and we’d be getting paid for it while we play outside.

The only way this could happen would be to distribute the ownership of all the robots to as many citizens as possible. The implementation of such distributed ownership is the part that I still don’t have quite clear and I’d love for you to give me some ideas on how this could come true.

Perhaps it could all start with a law to avoid the ultimate inequality gap, as things are today the rich will be the only ones to own the majority of robots, ending up with a robotic workforce that produces goods that nobody will be able to afford since they’re all unemployed, then people would start talking about a communist revolution and we don’t want that, we need capitalism evolved. A nation made from a lot of rich people out of robotic production and a renassaince of American product exports.

I think if the people now living off of unemployment checks would own a portion of the robotic workforce, they would instead get larger and larger divident checks that come off their robot’s productivity (I see this as some sort of Robotic ETF that pays monthly dividends).

This ownership could initially come from a portion of their tax contributions/returns (through some initial law that would make as many americans as possible robotic-workforce-entrepreneurs by force), maybe there could be incentives toward robotic equity, such as people who continue to get a high level education getting tax credits or rebates on the price of the robotic labor ETF.

The first country to figure this out will be king, itwould have a society mainly composed of a highly educated and almost rich middle class, people that don’t have to spend 8 hours a day doing work that’s done 1000 times better by their robotic counterparts.

A society that would have a surplus of money they could use to travel the world, study, research, or invest in whatever they please, being highly educated an peaceful we’d find times to take mankind to far more interesting directions like clean and free energy research, space exploration and mining, medical advances, the pursuit of much longer life spans, and solving real problems affecting developing nations.

But the question remains, how do you motivate the currently rich elite to not eat/cook the whole robotic labor pie, or to somehow share it so that we all get to own a piece of it and live worry free, happily unemployed because robots are the ones that are supposed to work for us?