Skip to content

Instantly share code, notes, and snippets.

alces /
Last active Sep 18, 2015
A memo on how to put all the installation of gitlab into a common root (e.g. for running a high-available solution on top of DRBD filesystem).

Putting all the Gitlab-related files into one directory prefix

  1. stop gitlab:
gitlab-ctl stop
  1. move /var/opt/gitlab inside our prefix:
alces /
Last active Sep 21, 2015
RHEL 5/6-compliant init script for Apache Tomcat
# chkconfig: 345 98 02
export CATALINA_BASE=/opt/tomcat
export CATALINA_HOME=/opt/apache-tomcat-8.0.22
export CATALINA_OPTS="-server -Xms512m -Xmx512m -XX:MaxPermSize=128m -XX:PermSize=128m"
export JAVA_HOME=/opt/jdk1.8.0_51
alces /
Last active Oct 13, 2015
logrotate config for apache with rotating by files' size and gathering statistics from the old logs before compressing them.

Put the following into your /etc/logrotate.d/httpd:

# use the standard parameters for error log
/var/log/httpd/error_log {
	/sbin/service httpd graceful 2> /dev/null || true
alces /
Created Oct 28, 2015
How to leave only one sub-directory in a git repository

The following command leaves only content of my/sub/dir in a master branch:

git filter-branch --subdirectory-filter my/sub/dir --prune-empty master

as a side effect, my/sub/dir becomes a root directory of a repository.

Full documentation on git filter-branch command could be found here:

alces /
Last active Nov 9, 2015
A short instruction on what to touch in Java and git installations in order to make Jenkins Git plugin work via HTTPS with an SSL certificate seeming somewhat incorrect

How to Make Jenkins Git Plugin Work via HTTPS with "Incorrect" SSL Certificate

If your Jenkins server works with the git server via HTTPS and the latter uses a self-signed (or might be seeming incorect in some other sense) SSL certificate, you'll likely get an error like this:

hudson.plugins.git.GitException: PKIX path building failed: unable to find valid certification path to requested target

In order to get rid of it the steps bellow could be helpful (at least, they were helpful for me while setting up Jenkins build nodes on both Linux and Windows boxes):

  1. determine JAVA_HOME of JVM your build node is run by. If there're multiple Java installations on your build server (and I think, that's a common case for such sort of servers),
alces /
Last active Nov 9, 2015
How to show a name of user a process with a given PID runs on behalf of

In order to see a name of user starting a process with a given PID the command bellow could be helpful:

ps ho user -p `cat /some/pid/file`

Entering a dash before h argument doesn't work on Linux with the following error message:

Warning: bad syntax, perhaps a bogus '-'?
alces /
Created Nov 12, 2015
A script searching for computers in AD by names' wildcard
# get a list of hosts with names matching a wildcard from AD
# on RedHat-based systems python-ldap package is required
import ldap
# get a field from ldap results
res_field = lambda r, n: r[1][n][0]
# send search query to ldap and get a result
ldap_search = lambda ldap_srv, wld_card: ldap_srv.search_s('ou=servers,dc=example,dc=com',
alces / listJenkinsUsersPermissions.groovy
Created Nov 16, 2015
A groovy script listed all permissions a given user has on Jenkins jobs
View listJenkinsUsersPermissions.groovy
USERNAME = 'testuser'
import hudson.model.Hudson
println Hudson.instance.items.collect {
[name:, matrix: it.getProperty(AuthorizationMatrixProperty.class)]
}.findAll {
}.collect {
alces / listJenkinsGlobalPermission.groovy
Created Nov 17, 2015
Extract list of global permissions a particular user has from Jenkins' config.xml
View listJenkinsGlobalPermission.groovy
USERNAME = 'dummy'
import hudson.model.Hudson
println new XmlSlurper().parse(
new File(Hudson.instance.root, 'config.xml')
).authorizationStrategy.permission.collect {
}.findAll {
it[1] == USERNAME
alces / ansible_python_hacks.yml
Last active Dec 25, 2015
Some examples of Pythonic ways of working with Ansible variables
View ansible_python_hacks.yml
#!/usr/bin/env ansible-playbook
- name: Learn about some Pythonic ways to work with Ansible variables
hosts: all
env_name: prod
java_root: /opt
jdk_ver: 1.8.0_51
rhel_major_version: 7