deb http://archive.ubuntu.com/ubuntu precise main universe restricted multiverse deb http://archive.ubuntu.com/ubuntu precise-security universe main multiverse restricted deb http://archive.ubuntu.com/ubuntu precise-updates universe main multiverse restricted deb http://archive.ubuntu.com/ubuntu precise-proposed universe main multiverse restricted
sources.list файл для 12.04 ubuntu
Таймаут для виконання функції в python
Є скрипт під віндою, який час від часу залипає і це є проблемою. Варіант вирішення - задавати час на виконання функції, якщо він перевищує поріг, вбивати виконання функції. Нагуглив кілька варіантів, але під віндою не працює SIGALRM. А цей сніп досить гарно працює.
import multiprocessing
import time
# bar
def bar():
for i in range(100):
print "Tick"
time.sleep(1)
if __name__ == '__main__':
# Start bar as a process
p = multiprocessing.Process(target=bar)
p.start()
# Wait for 10 seconds or until process finishes
p.join(10)
# If thread is still active
if p.is_alive():
print "running... let's kill it..."
# Terminate - may not work if process is stuck for good
p.terminate()
# OR Kill - will work for sure, no chance for process to finish nicely however
# p.kill()
p.join()
Перевірка закінчення дати делегування домена в Zabbix
в zabbix_agentd.conf
EnableRemoteCommands=1
файл: checkdomain.sh
#!/bin/bash
DOMAIN="$1"
data=$(whois $1 | grep -E 'paid|Expir|expir' | grep -o -E '[0-9]{4}.[0-9]{2}.[0-9]{2}|[0-9]{2}/[0-9{2}/[0-9]{4}' | tr . / | awk 'NR == 1')
expire=$((`date -d "$data" '+%s'`))
today=$((`date '+%s'`))
lefts=$(($expire - $today))
leftd=$(($lefts/86400))
echo $leftd
Items:
Перевірка терміну придатності SSL-сертифікату в Zabbix
в zabbix_agentd.conf
EnableRemoteCommands=1
файл: checkssl.sh
#!/bin/bash
ssl-cert-check -s $1 -p $2 -n | sed 's/ */ /g' | cut -f6 -d" " | sed -e 's#|days=##'
Items:
Trigger:
Автостарт icecast через systemd
# touch /etc/systemd/system/icecast.service
[Unit]
Description=Icecast Network Audio Streaming Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/Icecast-Server/bin/icecast -c /usr/local/Icecast-Server/etc/icecast.xml
ExecReload=/bin/kill -HUP $MAINPID
User=radio
Group=radio
WorkingDirectory=/usr/local/Icecast-Server
[Install]
WantedBy=multi-user.target
# systemctl enable icecast
# systemctl start icecast
# systemctl stop icecast
# systemctl restart icecast
mysql заміна кодування в таблицях і полях на прикладі апгрейда zabbix
Таблиці:
SELECT CONCAT('ALTER TABLE ',
table_schema,
'.',
table_name,
' COLLATE=utf8_bin;') AS cmd
FROM (SELECT table_schema,
table_name,
table_collation
FROM information_schema.tables t
WHERE table_schema = 'zabbix'
AND table_collation != 'utf8_bin') AS tables
ORDER BY cmd;Поля:
SELECT CONCAT('ALTER TABLE ',
table_schema,
'.',
table_name,
' MODIFY COLUMN ',
column_name,
' ',
column_type,
' CHARACTER SET utf8 COLLATE utf8_bin',
defaultval,
nullable,
';') AS cmd
FROM (SELECT table_schema,
table_name,
column_name,
collation_name,
character_set_name,
column_type,
column_default,
CASE
WHEN column_default IS NULL THEN ''
ELSE CONCAT(' DEFAULT ''', column_default, ''' ')
END AS defaultval,
CASE
WHEN is_nullable = 'NO' THEN ' NOT NULL '
ELSE ''
END AS nullable
FROM information_schema.columns
WHERE table_schema = 'zabbix'
AND ( collation_name != 'utf8_bin'
OR character_set_name != 'utf8' )) AS cols
ORDER BY cmd;
Автозапуск docker-compose up -d при старті системи
# /etc/systemd/system/docker-compose-app.service
[Unit]
Description=Docker Compose Application Service
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/srv/docker
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
активовуємо автозапуск сервісу# systemctl enable docker-compose-app


