Category Archives: Code

docker-registry at simulakrum

If docker on a systemd-infected system complains that it cannot log into docker-registry at simulakrum.org, add the following into docker.service file:

:~# grep simulakrum /etc/systemd/system/multi-user.target.wants/docker.service
ExecStart=/usr/bin/dockerd –insecure-registry docker-registry.simulakrum.org -H fd://

and then reload the systemd and restart docker daemon:

systemctl daemon-reload
systemctl restart docker.service

If the same things happens in a FreeBSD, add the same switch into the following file:

root@beastie:~ # grep simulakrum /usr/local/etc/rc.d/docker
daemon -p /var/run/docker.pid ${command} -d -e jail –insecure-registry docker-registry.simulakrum.org -s zfs -g ${docker_dir} -D >/var/log/docker.log 2>/var/log/docker.log

and then restart the docker daemon:

root@beastie:~ # /usr/local/etc/rc.d/docker restart
Stopping docker…
Starting docker…
root@beastie:~ #

Change check_docker Nagios’ plugin over NRPE to list all of the Docker containers

Due to the way that NRPE/Nagios reads output from this fine plugin, it will show only the first running container in the Web-interface if asked for check_docker –status running. Python solves “printf” functionality by adding a suffix, so here’s a quick diff for the plugin so it can display all of the running containers when asked by check_docker plugin:

 

--- check_docker 2016-09-06 13:16:50.396425436 +0200
+++ /opt/nagios-plugins/check_docker/check_docker-master/check_docker.py 2016-05-16 03:20:13.000000000 +0200
@@ -1,5 +1,4 @@
 #!/usr/bin/env python3
-from __future__ import print_function
 __author__ = 'Tim Laurence'
 __copyright__ = "Copyright 2016"
 __credits__ = ['Tim Laurence']
@@ -15,6 +14,7 @@
 Note: I really would have preferred to have used requests for all the network connections but that would have added a
 dependency.
 '''
+
 from sys import argv
 from http.client import HTTPConnection
 from urllib.request import AbstractHTTPHandler, HTTPHandler, HTTPSHandler, OpenerDirector
@@ -25,6 +25,7 @@
 
 
 
+
 DEFAULT_SOCKET = '/var/run/docker.sock'
 DEFAULT_TIMEOUT = 10.0
 DEFAULT_PORT = 2375
@@ -273,15 +274,15 @@
 def print_results():
 if len(messages) > 0:
 if len(performance_data) > 0:
- print(messages[0] + '|' + performance_data[0], end=' ')
+ print(messages[0] + '|' + performance_data[0])
 else:
- print(messages[0], end=' ')
+ print(messages[0])
 for message in messages[1:]:
- print(message, end=' ')
+ print(message)
 if len(performance_data) > 1:
 print('|', end='')
 for data in performance_data[1:]:
- print(data, end=' ')
+ print(data)
 
 if __name__ == '__main__':

CoD – Code of the Day – 1447441471

#include <stdio.h>

enum {WARNING, ERROR, INFO, SUCCESS};

char const *msg(int type);

int main (int argc, char **argv)
{

puts(msg(INFO));

puts(msg(0));
return 0;
}

char const *msg(int type)
{

switch (type)
{
case WARNING:
return “Warning message!”;
case ERROR:
return “Error message!”;
case INFO:
return “Info message!”;
case SUCCESS:
return “Success message!”;

}

return NULL;
}

The conjugate function for clang 3.4.1 on FreeBSD fails?

Dealing with the conjugate of complex numbers brought me some linker failures for clang 3.4.1 on FreeBSD 11 CURRENT amd64:

vanja@current:/tmp % cat konjugat.c
#include <complex.h>
#include <stdio.h>

int main(void)
{
double complex kpx = 1.0 + 3.0*I;
double complex konjugat = conj(kpx);
printf(“Kompleksni broj je %.2f%+.2fi\n”, creal(kpx), cimag(kpx));
printf(“Konjugat od kpx je %.2f%+.2fi\n”, creal(konjugat) ,cimag(konjugat));
return 0;
}

Continue reading