Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
"""
A generic daemon class.
Usage: subclass the Daemon class and override the run() method

1. Install needed repositories

  • Remi Dependency on CentOS 6 and Red Hat (RHEL) 6

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

  • Remi Dependency on CentOS 5 and Red Hat (RHEL) 5

rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

@infinityhacks
infinityhacks / gist:dca0b3a7dafc481667d4
Last active September 16, 2015 04:49 — forked from louiszuckerman/gist:3908490
Logstash grok parser for custom varnishncsa log format
I pass these options to the varnishncsa daemon (this line is from my /etc/init.d/varnishncsa)...
DAEMON_OPTS="-a -F "\''%h "%{X-Forwarded-For}i" %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i" %{Varnish:time_firstbyte}x %{Varnish:handling}x'\'" -c -w ${LOGFILE} -D -P $PIDFILE"
I parse that with the following grok pattern...
VARNISHNCSALOG %{IPORHOST:remoteip} %{QUOTEDSTRING:xforwardedfor} %{USER:auth} \[%{HTTPDATE:timestamp}\] "%{WORD:verb} %{NOTSPACE:request} HTTP/%{NUMBER:httpversion}" (?:%{NUMBER:status}|\(null\)) (?:%{NUMBER:bytes}|-) "(?:%{NOTSPACE:referrer}|-)" %{QUOTEDSTRING:agent} %{BASE10NUM:berespms} %{WORD:cache}
@infinityhacks
infinityhacks / logstash-template.json
Last active September 17, 2015 16:16 — forked from deverton/logstash-template.json
Logstash Elasticsearch Template
{
"template": "logstash-*",
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 0,
"index" : {
"query" : { "default_field" : "@message" },
"store" : { "compress" : { "stored" : true, "tv": true } }
}
},
@infinityhacks
infinityhacks / README.md
Created September 6, 2012 14:38 — forked from chuangbo/README.md
Python dynamic DNSPod DNS Script

替换上你的Email,密码,域名ID,记录ID等参数,就可以运行了。 会在后台一直运行,每隔30秒检查一遍IP,如果修改了就更新IP。

获得domain_id可以用curl curl -k https://dnsapi.cn/Domain.List -d "login_email=xxx&login_password=xxx"

获得record_id类似 curl -k https://dnsapi.cn/Record.List -d "login_email=xxx&login_password=xxx&domain_id=xxx"

@infinityhacks
infinityhacks / gist:ab62a84ed9cfbe22e4189d36a9495812
Created April 21, 2016 04:39 — forked from pnommensen/gist:707b5519766ba45366dd
Ghost CMS with NGINX for Maximum Performance

Full blog post can be found here: http://pnommensen.com/2014/09/07/high-performance-ghost-configuration-with-nginx/

Ghost is an open source platform for blogging founded by John O'Nolan and Hannah Wolfe. It's a node.js application and therefore works great in conjunction with nginx. This guide will will help you create a high performance nginx virtual host configuration for Ghost.

"Don't use #nodejs for static content" - @trevnorris. If #nginx isn't sitting in front of your node server, you're probably doing it wrong.

— Bryan Hughes (@nebrius) August 30, 2014
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

The node.js application runs on a port on your server

@infinityhacks
infinityhacks / monitrc
Created July 12, 2016 08:30 — forked from 3rd-Eden/monitrc
monit nodejs deployment
###############################################################################
## Includes
###############################################################################
##
## It is possible to include additional configuration parts from other files or
## directories.
#
# include /etc/monit.d/*
#
#
@infinityhacks
infinityhacks / nginx.conf
Created July 26, 2016 05:22 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@infinityhacks
infinityhacks / monit.conf
Created March 9, 2017 05:56 — forked from raminv80/monit.conf
PPTP auto reconnect with Monit
...
#assuming the host behind vpn has local ip of 192.168.1.2
check host my_host_behind_vpn with address 192.168.1.2
# create a shell script at /usr/local/bin/start_pppd.sh
# Add your vpn connection setup there
# example conect of this file can be:
# pppd call my-vpn #to connect to pptp client
# sleep 5 #wait few seconds for connection to start
# route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev ppp0 # route your traffic
start program "/usr/local/bin/start_pppd.sh"
@infinityhacks
infinityhacks / purge-multi.lua
Created May 15, 2017 16:00 — forked from titpetric/purge-multi.lua
Delete NGINX cached items with a PURGE with wildcard support
-- Tit Petric, Monotek d.o.o., Tue 03 Jan 2017 06:54:56 PM CET
--
-- Delete nginx cached assets with a PURGE request against an endpoint
-- supports extended regular expression PURGE requests (/upload/.*)
--
function file_exists(name)
local f = io.open(name, "r")
if f~=nil then io.close(f) return true else return false end
end