Skip to content

Instantly share code, notes, and snippets.

@alces
alces / gitlab_common_prefix.md
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).
View gitlab_common_prefix.md

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
alces / tomcat.sh
Last active Sep 21, 2015
RHEL 5/6-compliant init script for Apache Tomcat
View tomcat.sh
#!/bin/bash
# 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 CATALINA_PID=$CATALINA_BASE/work/tomcat.pid
export JAVA_HOME=/opt/jdk1.8.0_51
PATH=/usr/bin:/bin:/usr/sbin:/sbin
@alces
alces / httpd_logrotate.md
Last active Oct 13, 2015
logrotate config for apache with rotating by files' size and gathering statistics from the old logs before compressing them.
View httpd_logrotate.md

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

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

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: https://git-scm.com/docs/git-filter-branch

@alces
alces / using_jenkins_git_plugin_over_https_with_incorect_certificate.md
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
View using_jenkins_git_plugin_over_https_with_incorect_certificate.md

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: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: 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
alces / process_owner_by_pid.md
Last active Nov 9, 2015
How to show a name of user a process with a given PID runs on behalf of
View process_owner_by_pid.md

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
alces / find_hosts_in_ad.py
Created Nov 12, 2015
A script searching for computers in AD by names' wildcard
View find_hosts_in_ad.py
# 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
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
import hudson.security.AuthorizationMatrixProperty
println Hudson.instance.items.collect {
[name: it.name, matrix: it.getProperty(AuthorizationMatrixProperty.class)]
}.findAll {
it.matrix
}.collect {
@alces
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 {
it.text().split(':')
}.findAll {
it[1] == USERNAME
@alces
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
vars:
env_name: prod
java_root: /opt
jdk_ver: 1.8.0_51
rhel_major_version: 7
linux_distros: