How to stop Jenkins CI build by extract a value from a JSON endpoint in bash using Curl

Curl the URL to get the JSON response and pipe it to the python tool. The python code will extract the value mapped to the given key (number in this case).

machine='dbelab04'
machineport=8080
jobname='mkat_fpga_tests_4k'
buildnumber=$(curl --silent -X POST http://$machine:$machineport/job/$jobname/lastBuild/api/json?tree=number | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["'number'"]';)
curl -X POST http://$machine:$machineport/job/$jobname/$number/stop

Note: the above command actually works

System V init script(start-stop-daemon)

I’ve been looking for efficient ways to start at boot my NodeJS dependent applications, with inspiration from https://gist.github.com/alobato/1968852, I modified it to my own needs.

Link might interest you as well:
http://big-elephants.com/2013-01/writing-your-own-init-scripts/
https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

Copy template to /etc/init.d and rename it to something meaningful. Then edit the script and enter that name after Provides:(between ### BEGIN INIT INFO and ### END INIT INFO).

#!/bin/bash
# Inspired by https://gist.github.com/alobato/1968852
# Needs Provides, Descriptions

### BEGIN INIT INFO
# Provides:
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description:
# Description:
### END INIT INFO

set -e
NAME=""
PIDFILE="/run/$NAME/$NAME.pid"
# Application one wants to upstart
DAEMON=""
DAEMON_OPTS=""
# Run as user
RUN_USER=""
RUN_GROUP=""
function daemon_run {
	mkdir -p /run/$NAME
	chown $RUN_USER:$RUN_GROUP /run/$NAME
	start-stop-daemon --start --background --quiet --chuid $RUN_USER:$RUN_GROUP --chdir /run/$NAME --pidfile $PIDFILE --make-pidfile --exec $DAEMON $DAEMON_OPTS
}
exec > /var/log/$NAME.log 2>&1

case "$1" in
start)
	echo -n "Starting $NAME ... "
	daemon_run
	echo "done."
;;

silent)
	echo -n "Starting $NAME in silent mode ... "
	daemon_run
	echo "done."
;;

stop)
	echo -n "Stopping $NAME ... "
	start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --remove-pidfile
	echo "done."
;;
restart|force-reload)
	echo -n "Restarting $NAME ... "
	start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE --remove-pidfile
	alexa_run
	echo "done."
;;
*)
	echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

When done,

sudo systemctl enable 'name_of_filename'
reboot

Mpho

Ubuntu media server WakeOnLan

I have always been conservative when it comes to saving electricity in my household not because I want to but because 1 kWh costs me R1.87, hence I had to think of a better solution rather than running my server 24 hours per day with an average load wattage of 532W, if one does the maths it costs me roughly R23.87 per day when always on.

So not cool, hence why I had to think of a better way to conserve energy:- WakeOnLan

In Ubuntu 16.04, make changes:

# Install ethtgool (Dependency)

sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get install -y ethtool

# To avoid getting WOL disabled by TLP power management make changes to:-

sudo nano /etc/default/tlp

WOL_DISABLE=N

# To prevent powering off the network card during shutdown make changes to:-

sudo nano /etc/default/halt


NETDOWN=no

# Enable Wake on LAN when static network configuration is used.

sudo nano /etc/network/interfaces</code>

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface

auto lo
iface lo inet loopback
# The primary network interface

auto eth0
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 192.168.0.1
up ethtool -s eth0 wol g

Enable wake on lan in BIOS, enter the BIOS setup and look for something called “Wake up on PCI event”, “Wake up on LAN” or similar. Change it so that it is enabled. Save your settings and reboot.

From there you should be good to go.