Skip to content

Commit

Permalink
daily
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor committed Jan 29, 2017
1 parent 5251847 commit 9c834fe
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 73 deletions.
2 changes: 1 addition & 1 deletion debian-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#
# - Apache 2.4 latest with HTTP/2 and event MPM
# - PHP 5.6 or 7.0 through PHP-FPM
# - CLI tools (WP-CLI, Drush)
# - CLI tools (WP-CLI, Drush, CacheTool)
# - Redis in-memory cache (maxmemory 512mb, maxmemory-policy allkeys-lru)
# - MariaDB 10
#
Expand Down
25 changes: 0 additions & 25 deletions install-all.sh

This file was deleted.

17 changes: 9 additions & 8 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Install a tool from debian-server-tools.
#
# VERSION :0.4.2
# VERSION :0.4.3
# DATE :2015-05-29
# AUTHOR :Viktor Szépe <[email protected]>
# LICENSE :The MIT License (MIT)
Expand All @@ -11,7 +11,7 @@


Die() {
local RET="$1"
local -i RET="$1"

shift
echo -e "$*" 1>&2
Expand All @@ -25,11 +25,13 @@ Die() {
# META
#####################################################
Get_meta() {
# defaults to self
# Defaults to self
local FILE="${1:-$0}"
# defaults to "VERSION"
# Defaults to "VERSION"
local META="${2:-VERSION}"
local VALUE="$(head -n 30 "$FILE" | grep -m 1 "^# ${META}\s*:" | cut -d':' -f 2-)"
local VALUE

VALUE="$(head -n 30 "$FILE" | grep -m 1 "^# ${META}\s*:" | cut -d ":" -f 2-)"

if [ -z "$VALUE" ]; then
VALUE="(unknown)"
Expand Down Expand Up @@ -87,7 +89,7 @@ Do_install() {

# Create symlink
head -n 30 "$FILE" | grep "^# SYMLINK\s*:" | cut -d ":" -f 2- \
| while read SYMLINK; do
| while read -r SYMLINK; do
echo -n "Symlinking "
ln -s -v -f "$SCRIPT" "$SYMLINK" || Die 12 "Symbolic link creation failure (${SYMLINK})"
done
Expand All @@ -103,7 +105,6 @@ Do_install() {
Get_meta "$FILE" DEPENDS | sed -n -e 's/^apt-get install \(.\+\)$/\1 /p' \
| while read -r -d " " PKG; do
if [ "$(dpkg-query --showformat="\${Status}" --show "$PKG" 2> /dev/null)" != "install ok installed" ]; then
#if ! grep-status -sPackage -FProvides "$PKG" | grep -qx "Package: \S\+"; then
echo "MISSING DEPENDECY: apt-get install ${PKG}" 1>&2
fi
done
Expand Down Expand Up @@ -131,7 +132,7 @@ Do_dir() {
local FILE

find "$DIR" -maxdepth 1 -type f \
| while read FILE; do
| while read -r FILE; do
Do_install "$FILE"
done
}
Expand Down
4 changes: 2 additions & 2 deletions monitoring/monit/services/fail2ban
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# From Fail2ban
check process fail2ban with pidfile /run/fail2ban/fail2ban.pid
group services
start program = "/etc/init.d/fail2ban force-start"
stop program = "/etc/init.d/fail2ban stop"
start program = "/etc/init.d/fail2ban force-start" with timeout 90 seconds
stop program = "/etc/init.d/fail2ban stop" with timeout 90 seconds
if failed unixsocket /run/fail2ban/fail2ban.sock then restart
if 5 restarts within 5 cycles then unmonitor
depends on fail2ban_db
Expand Down
4 changes: 2 additions & 2 deletions mysql/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Installation of system tables failed!
MariaDB upgrade error message: *Installation of system tables failed!*

```bash
mcedit /var/lib/dpkg/info/mariadb-server-10.0.postinst:227
Expand All @@ -19,7 +19,7 @@ http://nathan.rambeck.org/blog/28-drop-all-mysql-tables-command-line
# check for credentials in ~/.my.cnf
mysqldump --no-create-info --no-data information_schema > /dev/null && echo "USE information_schema;" | mysql

mysqldump --no-data <DATABASE> | grep "^DROP TABLE IF EXISTS " | ionice mysql
mysqldump --no-data <DATABASE> | grep "^DROP TABLE IF EXISTS " | mysql
```

### Check and optimize a databases
Expand Down
25 changes: 13 additions & 12 deletions mysql/alter-table.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
-- Source: http://georgepavlides.info/?p=628
-- Alter table engine
--
-- Usage: mysql -N DATABASE-NAME < alter-table.sql|mysql
-- Source: http://georgepavlides.info/?p=628
-- Usage: mysql -N DATABASE-NAME < alter-table.sql | mysql


-- To Aria
-- https://mariadb.com/kb/en/mariadb/aria-storage-engine/
-- SET @engine_string = 'Aria, TRANSACTIONAL = 1, PAGE_CHECKSUM = 0';
-- SET @engine_string = 'ENGINE = Aria, TRANSACTIONAL = 1, PAGE_CHECKSUM = 0';

-- To TokuDB w/LZMA
-- https://www.percona.com/doc/percona-server/5.6/tokudb/tokudb_compression.html
-- SET @engine_string = 'TokuDB, ROW_FORMAT=TOKUDB_LZMA';
-- SET @engine_string = 'ENGINE = TokuDB, ROW_FORMAT=TOKUDB_LZMA';

-- To TokuDB w/Quick LZ
-- SET @engine_string = 'TokuDB, ROW_FORMAT=TOKUDB_QUICKLZ';
-- SET @engine_string = 'ENGINE = TokuDB, ROW_FORMAT=TOKUDB_QUICKLZ';

-- To InnoDB
-- Table compression algorithm (lz4) support from MariaDB 10.1.0
-- https://mariadb.com/kb/en/mariadb/innodb-xtradb-page-compression/
SET @engine_string = 'InnoDB';
SET @engine_string = 'ENGINE = InnoDB';

SET @data_base = ( SELECT DATABASE() );

Expand All @@ -25,10 +27,9 @@ SELECT CONCAT(
`tbl`.`TABLE_SCHEMA`,
'`.`',
`tbl`.`TABLE_NAME`,
'` ENGINE = ',
'` ',
@engine_string,
';'
) AS `alters`
FROM `information_schema`.`TABLES` `tbl`
WHERE `tbl`.`TABLE_SCHEMA` = @data_base
LIMIT 0,1000;
';' ) AS `alters`
FROM `information_schema`.`TABLES` `tbl`
WHERE `tbl`.`TABLE_SCHEMA` = @data_base
LIMIT 0,1000;
6 changes: 3 additions & 3 deletions mysql/mysql-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Complete MySQL backup daily.
#
# VERSION :0.1
# VERSION :0.1.0
# DATE :2014-10-22
# AUTHOR :Viktor Szépe <[email protected]>
# LICENSE :The MIT License (MIT)
Expand All @@ -15,6 +15,6 @@

BACKUP_TARGET="/root/backup/mysql-today.sql.gz"

# IO nice and CPU nice
# CPU nice
/usr/bin/mysqldump --all-databases --single-transaction --events \
| ionice -c 3 nice gzip -9 > "$BACKUP_TARGET"
| nice gzip -9 > "$BACKUP_TARGET"
4 changes: 3 additions & 1 deletion mysql/mysql-reset-pwd.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
-- http://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html#resetting-permissions-unix

-- EDIT
SET @my_password = '<PASSWORD>';

UPDATE mysql.user SET Password=PASSWORD(@my_password) WHERE User='root';
FLUSH PRIVILEGES;

-- $ service mysql stop && mysqld_safe --init-file=/path/to/this/file.sql &
-- service mysql stop && mysqld_safe --init-file=./mysql-reset-pwd.sql &
24 changes: 15 additions & 9 deletions mysql/wp-createdb.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#!/bin/bash
#
# Create database and database user from wp-config.php
# Needs user, password and default-character-set in ~/.my.cnf [mysql] section.
#
# VERSION :0.3.0
# VERSION :0.3.1
# DATE :2016-02-22
# AUTHOR :Viktor Szépe <[email protected]>
# LICENSE :The MIT License (MIT)
# URL :https://github.com/szepeviktor/debian-server-tools
# BASH-VERSION :4.2+
# LOCATION :/usr/local/bin/wp-createdb.sh
#
# Needs user, password and default-character-set
# in ~/.my.cnf [mysql] section.

WP_CONFIG="./wp-config.php"

Get_wpconfig_var() {
local VAR="$1"
local DEFAULT="$2"

# UNIX or Windows lineends
# Support UNIX or Windows line endings
if ! [ -r "$WP_CONFIG" ] || ! grep -q "^define.*${VAR}.*;.\?$" "$WP_CONFIG"; then
if [ -z "$DEFAULT" ]; then
read -r -e -p "${VAR}? " DB_VALUE
Expand All @@ -34,8 +36,9 @@ Get_wpconfig_var() {
grep "^define.*${VAR}.*;.\?$" "$WP_CONFIG" | cut -d"'" -f4
}

which mysql &> /dev/null || exit 1
# Check credentials
hash mysql 2> /dev/null || exit 1

# Check database access
mysql --execute="EXIT" || exit 3

DBNAME="$(Get_wpconfig_var "DB_NAME")"
Expand All @@ -57,18 +60,21 @@ echo "Charset: ${DBCHARSET}"
echo
read -r -p "CREATE DATABASE? " -n 1

[ "$DBHOST" == "localhost" ] || echo "Connecting to ${DBHOST} ..."
if [ "$DBHOST" != "localhost" ]; then
echo "Connecting to ${DBHOST} ..." 1>&2
fi

mysql --default-character-set=utf8 --host="$DBHOST" <<EOF || echo "Couldn't setup up database (MySQL error: $?)" 1>&2
CREATE DATABASE IF NOT EXISTS \`${DBNAME}\`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';
-- "GRANT ALL PRIVILEGES" creates the user
-- CREATE USER '${DBUSER}'@'${DBHOST}' IDENTIFIED BY '${DBPASS}';
GRANT ALL PRIVILEGES ON \`${DBNAME}\`.* TO '${DBUSER}'@'${DBHOST}'
GRANT ALL PRIVILEGES ON \`${DBNAME}\`.*
TO '${DBUSER}'@'${DBHOST}'
IDENTIFIED BY '${DBPASS}';
FLUSH PRIVILEGES;
EOF

echo -n "wp core config --dbname=\"$DBNAME\" --dbuser=\"$DBUSER\" --dbpass=\"$DBPASS\" "
echo "--dbhost=\"$DBHOST\" --dbprefix=\"prod_\" --dbcharset=\"$DBCHARSET\" # --extra-php <<EOF"
echo -n "wp core config --dbname=\"$DBNAME\" --dbuser=\"$DBUSER\" --dbpass=\"$DBPASS\""
echo " --dbhost=\"$DBHOST\" --dbprefix=\"prod_\" --dbcharset=\"$DBCHARSET\" # --extra-php <<EOF"
8 changes: 5 additions & 3 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Show update instruction for installed tools.
#
# VERSION :0.1.1
# VERSION :0.1.2
# DATE :2015-07-06
# AUTHOR :Viktor Szépe <[email protected]>
# LICENSE :The MIT License (MIT)
Expand All @@ -21,15 +21,17 @@ Get_meta() {
local FILE="${1:-$0}"
# defaults to "VERSION"
local META="${2:-VERSION}"
local VALUE="$(head -n 30 "$FILE" | grep -m 1 "^# ${META}\s*:" | cut -d':' -f 2-)"
local VALUE

VALUE="$(head -n 30 "$FILE" | grep -m 1 "^# ${META}\s*:" | cut -d ":" -f 2-)"

if [ -z "$VALUE" ]; then
VALUE="(unknown)"
fi
echo "$VALUE"
}

which colordiff &> /dev/null || unset PARAM
hash colordiff 2> /dev/null || unset PARAM

#Input_motd Get_meta input/update-motd.d - Get_meta /etc/update-motd.d/update-motd.d

Expand Down
39 changes: 39 additions & 0 deletions webserver/WordPress.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ add_action( 'plugins_loaded', function () {
global $vc_manager;
if ( method_exists( $vc_manager, 'disableUpdater' ) ) {
$vc_manager->disableUpdater( true );
add_filter( 'pre_option_wpb_js_js_composer_purchase_code', '__return_true' );
}
} );
```
Expand All @@ -344,11 +345,49 @@ Envato Market plugin for ThemeForest updates
wp plugin install https://envato.github.io/wp-envato-market/dist/envato-market.zip --activate
```

`envato-market-update.sh`

```bash
#!/bin/bash

WP_CONTENT_DIR="$(wp --no-debug eval 'echo WP_CONTENT_DIR;')"

if [ -n "$WP_CONTENT_DIR" ] && [ -d "$WP_CONTENT_DIR" ]; then
wp --no-debug plugin install "https://github.com/envato/wp-envato-market/archive/master.zip" --force
fi
```

Gravity Forms plugin

```php
// Disable Gravity Forms updates
define( 'GRAVITY_MANAGER_URL', null );
define( 'GRAVITY_MANAGER_PROXY_URL', null );
add_filter( 'pre_transient_gform_update_info', '__return_true' );
add_filter( 'option_gform_enable_background_updates', '__return_false' );
```

Unity theme

`external-plugin-update.sh`

```bash
#!/bin/bash

CURRENT="$(dirname "$0")/external-plugin-update.log"

# From wp-content/themes/unity/inc/frontend.php
EXTERNAL_PLUGINS=(
http://www.wpopal.com/thememods/appthemer-crowdfunding.zip
http://www.wpopal.com/thememods/js_composer.zip
http://www.wpopal.com/thememods/revslider.zip
)

for PLUGIN in ${EXTERNAL_PLUGINS[*]}; do
wget -q --spider -S "$PLUGIN" 2>&1 | grep "Last-Modified:"
done | diff "$CURRENT" -

#exit 0
```

### On deploy and Staging->Production Migration
Expand Down
3 changes: 3 additions & 0 deletions webserver/hosting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ ssl:
cdn:
enabled: yes
hostname: cdn.example.com
email:
provider: Mailjet
login: [email protected]
cms:
core: WordPress
theme: Theme Name
Expand Down
Loading

0 comments on commit 9c834fe

Please sign in to comment.