Sync server time

sudo service ntp stop
sudo ntpd -gq
sudo service ntp start

sources:
http://askubuntu.com/questions/254826/how-to-force-a-clock-update-using-ntp#answer-256004
https://www.digitalocean.com/community/tutorials/how-to-set-up-timezone-and-ntp-synchronization-on-ubuntu-14-04-quickstart
https://help.ubuntu.com/lts/serverguide/NTP.html

create git:// protocol

$ sudo apt-get install xinetd
$ sudo nano /etc/xinetd.d/git

# where highlighted if incorrect the service may not start

service git
{
        disable = no
        type            = UNLISTED
        port            = 9418
        socket_type     = stream
        wait            = no
        user            = nobody
        server          = /usr/bin/git
        server_args     = daemon --inetd --export-all --base-path=/var/fsq
        log_on_failure  += USERID
}

$ sudo /etc/init.d/xinetd restart
$ sudo /etc/init.d/xinetd status

# view the number of active services

active_services = 2
available_services = 2
descriptors_free = 1014
running_servers = 0
Logging service = enabled

# Now, all git repositories beneath /var/fsq will be available to anyone who asks.
# git clone git://[hostname]/my-repo.git
$ git clone git://baligena.com/my-repo.git

# sources
http://stackoverflow.com/questions/2538015/why-wont-git-daemon-serve-my-repository#answer-2539138

Installing Gitlab

Raspberry Pi

# login as root
$ sudo su

# follow gitlab installation for specified operating system
$ apt-get install gitlab-ce

# install web server
$ apt-get install nginx

# check log for errors. Port conflicts will be notified
$ cat /var/log/nginx/error.log

# change port if desired
$ nano /etc/nginx/sites-enabled/default

server {
        listen 81 default_server;
        listen [::]:81 default_server;

        # SSL configuration

# reconfigure gitlab
$ gitlab-ctl reconfigure

# change gitlab port to match nginx port
$ nano /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: gitlab.example.com
    port: 81
    https: false

.......

test:
  <<: *base
  gravatar:
    enabled: true
  gitlab:
    host: localhost
    port: 81

# change gitlab port to match nginx port
$ nano /etc/gitlab/gitlab.rb

## Url on which GitLab will be reachable.
## For more details on configuring external_url see:
## https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/configuration.md#configuring-the-external-url-for-gitlab
external_url 'http://gitlab.com.local:81/'

........

## Advanced settings
# unicorn['listen'] = '127.0.0.1'
# unicorn['port'] = 8081
# unicorn['socket'] = '/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket'
# unicorn['pidfile'] = '/opt/gitlab/var/unicorn/unicorn.pid'

# reconfigure gitlab
$ gitlab-ctl reconfigure

# restart gitlab
$ sudo gitlab-ctl restart

# restart server
$ sudo reboot

# restart nginx
$ /etc/init.d/nginx restart

# check if listen to port
$ nmap -sS 192.168.0.14

# navigate to page. Be careful with browser cache (especially firefox)
http://192.168.0.14:81/

sources

http://www.thecfguy.com/blog/how-to-change-default-port-for-gitlab/

troubleshooting

# Reconfigure freezes at ruby_block[supervise_redis_sleep] action run
https://gitlab.com/gitlab-org/omnibus-gitlab/issues/430#note_1308607
http://stackoverflow.com/questions/22328923/impossible-to-install-gitlab-on-ubuntu-12-04#answer-25785708

when accessing the file tab there was an ajax request that was loading a 500 error page.
Looked into the log by running
$ sudo gitlab-ctl tail
and found this error message

Errno::ENOMEM (Cannot allocate memory - /opt/gitlab/embedded/bin/git):
.......

Found out that not enough memory was being allocate. May be because its a raspberry pi and it has limited memory.
The solution was to reduce unicorn worker processes thus reducing the memory consumption.
$ nano /etc/gitlab/gitlab.rb

##################
# GitLab Unicorn #
##################
## Tweak unicorn settings.

# unicorn['worker_timeout'] = 60
unicorn['worker_processes'] = 1

# remove GitLab
$ apt-get purge gitlab-ce

# remove nginx
$ apt-get purge nginx nginx-common nginx-full

Use apache server instead of nginx

followed these these steps

# Additional
Before running 'gitlab-ctl reconfigure', first run 'gitlab-ctl start postgresql', else there will be an error that postgresql is not running.

# enable apache modules
# http://stackoverflow.com/questions/25785903/gitlab-7-2-1-with-apache-server-instead-of-nginx#comment-65475363
# http://askubuntu.com/questions/64454/how-do-i-enable-the-mod-rewrite-apache-module-for-ubuntu-11-04#answer-64460
$ sudo a2enmod rewrite
$ sudo a2enmod proxy_http

If you get permission errors like "You don't have permission to access /assets/logo-white-0b53cd4ea06811d79b3acd486384e047.png on this server." then you need "Require all granted" in the <Location> in your apache vhost configuration file

# sources
http://stackoverflow.com/questions/25785903/gitlab-7-2-1-with-apache-server-instead-of-nginx#answer-25809733

Winscp notes

Setting the Putty path

View->Preferences->Applications->Putty/Terminal client path

for putty in programs folder

%PROGRAMFILES%\PuTTY\putty.exe -t -m "%TEMP%\putty.txt" !`cmd.exe /c echo cd "!/" ; /bin/bash -login > "%TEMP%\putty.txt"`

for putty in quicklaunch folder with ability to change the window size on open

"%appdata%\Microsoft\Internet Explorer\Quick Launch\putty.exe - Shortcut.lnk" -t -m "%TEMP%\putty.txt" !`cmd.exe /c echo cd "!/" ; /bin/bash -login > "%TEMP%\putty.txt"`

Setting Master Slave Mysql Replication

Configuration and Setup

On Master and Slave

edit /etc/mysql/my.cnf
# http://stackoverflow.com/questions/8605318/mysql-replication-slave-server-on-one-database#answer-8606998
# http://forums.mysql.com/read.php?35,369191,370003
# if you only want to replicate a specified database you need to add line to my.cnf
# !!! IMPORTANT in selecting the correct database name or replication will run without errors but nothing will be updated

replicate-do-db=dbname

# name reported to the master during slave registration

report_host=hostname

# give a server id

server-id=1323

# give bin log file location

log_bin=/var/log/mysql/mysql-bin.log

master server configuration file changes

# restart database

$ sudo /etc/init.d/mysql restart

# add the user the slave will use

mysql> CREATE USER 'repl'@'%' IDENTIFIED BY 'slavepassword'; 
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';

On master

Dump mysql databases WITH compression

# all databases

$ mysqldump -uUSERNAME -pPASSWORD --all-databases --master-data | gzip > master_dbname_dump.sql.gz

# individual database

$ mysqldump -uUSERNAME -pPASSWORD --databases dbname --master-data | gzip > master_dbname_dump.sql.gz
Dump mysql databases WITHOUT compression

# individual database

$ mysqldump -uUSERNAME -pPASSWORD --databases dbname --master-data > master_dbname_dump.sql

# View Master information in the file dumped that will set the slave.

$ grep CHANGE *sql | head -1

# show slaves that are connected

mysql> SHOW SLAVE HOSTS;

# send file to slave server

$ scp master_dbname_dump.sql username@address.com:

On Slave

edit /etc/mysql/my.cnf
the slave server has a ‘read-only’ variable because that is its purpose. (Do not use this in master-master replication)
http://dba.stackexchange.com/questions/30128/should-a-mysql-replication-slave-be-set-to-read-only#answer-30129

read_only=ON

# The purpose of the import is because both the master and slave database must be the equal at point where the binlog started recording the replication.
# import the dump.

$ mysql -uroot < master_dbname_dump.sql

# Set the slave user

mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.3', MASTER_USER='repl', MASTER_PASSWORD='slavepassword';

# Set a user that will only have an read ability.
# This is a safeguard and repetitive because setting the 'read-only' variable in my.cnf would prevent slave writing. Slave should not have writing permissions.

mysql> CREATE USER 'read_user'@'%' IDENTIFIED BY 'password';
mysql> GRANT SELECT ON *.* TO 'read_user'@'%';

# start slave

mysql> START SLAVE;
mysql> SHOW SLAVE STATUS \G 

Notes

The location of either the master or slave logs are located in /var/log/mysql.
Its a binary(.bin) file contain the queries ran to sync the slave.

# view what inside the bin, mysql view queries logs

$ mysqlbinlog /var/log/mysql/mysql-bin.000001

# show the bin name

mysql> SHOW MASTER STATUS;
mysql> SHOW BINARY LOGS;

# dba.stackexchange.com/questions/47046/why-do-the-mysql-bin-log-files-still-exist-after-a-purge-or-flush#answer-47048
# to reset all the queries and purge all binary logs. This will also do the same in the slave.

mysql> RESET MASTER;

# Sometimes there's errors in the 'slave status' you can skip queries but more error may lie ahead. This is not a permanent fix.
# https://www.howtoforge.com/how-to-repair-mysql-replication

mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;

# the slave is working when you see this in the status

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

# To detect a Master and Slave being out of sync
# Pick any table and run CHECKSUM TABLE against a table on the Master and the Slave's copy of the same table.
# If the values do not come back the same, then something is out-of-sync.

mysql> CHECKSUM TABLE dbname.table;

Reset everything

On master when changing the replicate user password there was an error on the slave. Then the slave needed to be reset.

On Master

$ mysqldump -uUSERNAME -pPASSWORD --databases dbname --master-data | gzip > master_dbname_dump.sql.gz

# will clear/delete/purge all bin log. Be careful this may cause issues if there's mulitple slave to this master.

mysql> RESET MASTER;

On Slave

mysql> STOP SLAVE;
mysql> RESET SLAVE ALL;
mysql> RESET MASTER;  # will clear/delete/purge all bin log.

if this error 'ERROR 1186 (HY000): Binlog closed, cannot RESET MASTER' is because 'log_bin' was not specified in mysql configuration file my.cnf

# import the dump

$ mysql -uroot < master_dbname_dump.sql
mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.3', MASTER_USER='repl', MASTER_PASSWORD='slavepassword';
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS;

the slave is working when you see in the status

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

Master to master replication

# simply make master a slave as well.
# https://www.digitalocean.com/community/tutorials/how-to-set-up-mysql-master-master-replication

mysql> CHANGE MASTER TO MASTER_HOST='hostname', MASTER_USER='repl', MASTER_PASSWORD='slavepassword';

# values need to be equal where the colors match
master-master relationship

Miscellaneous

# http://stackoverflow.com/questions/2366018/how-to-re-sync-the-mysql-db-if-master-and-slave-have-different-database-incase-o#answer-3229580
# an option to reset the slave position

mysql> CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;

Logitech Headset H800 Pairing with Samsung Galaxy S5

To pair your wireless headset with a Bluetooth device:
1.Set the slider switch to the Bluetooth icon.
2.Slide the track switch to “Next” and hold, and press and hold the “Volume up” button at the same time, until the link LED indicator blinks rapidly.
NOTE: For initial Bluetooth setup, your headset will automatically be in pairing mode.
3.Make sure Bluetooth is active on your device and then select “H800 Logitech Headset” in the Bluetooth devices list (see your Bluetooth device’s documentation for more help).

source:
https://forums.logitech.com/t5/Earphones-Headphones-Headsets/Logitech-H800-Pairing-with-Samsung-Galaxy-S5/td-p/1348208#messageview_1

tags:
microphone, headphones, bluetooth

Validating a downloaded program

# import company key into your system
# sometimes called signing key or public key
# the file of import should start with this line ‘—–BEGIN PGP PUBLIC KEY BLOCK—–‘
$ gpg --keyid-format long --import [public_key/signing_key]

# run validation with signature and program.
$ gpg --keyid-format 0xlong --verify program.exe.sig program.exe

# you may get several different responses but the one that is bad for sure is ‘gpg: BAD signature from …’

good example and instructions
https://tails.boum.org/doc/get/verify/index.en.html
click on ‘Using Linux with the command line’

# view imported keys
$ gpg --list-keys

# remove keys
$ gpg --delete-keys "name"
$ gpg --delete-keys "Tails developers"

# site to hold manage keys
https://keybase.io/

Configuring ddclient

ddclient updates IP addresses at dynamic DNS services.

# install ddclient
$ sudo apt-get install ddclient

Configuring dyndns.com

Selected dyndns.com in the installation process and followed the prompts. Did not need to manually enter anything.

Configuring namecheap.com

Enable Dynamic DNS for your domain
Login to your Namecheap control panel and enable dynamic DNS for your domain.
You’ll get a really long password string to use. Save that for now as you’ll need it later on.
namecheap dynamic dns password

$ sudo nano /etc/ddclient.conf

# namecheap.com example configuration
# the login is the domain name and password is the hash you saved in the prior step called ‘Dynamic DNS Password’.

# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf

protocol=namecheap
use=web, web=dynamicdns.park-your-domain.com/getip, web-skip='IP Address'
server=dynamicdns.park-your-domain.com
login=baligena.com
password='36e39d6fief87be5e38c7d7507863'
@,www

# remove cache
$ sudo rm /var/cache/ddclient/ddclient.cache

# force update, you may need to delete cache
$ sudo ddclient --daemon=0 --debug --verbose --noquiet

# another configuration file
$ sudo nano /etc/default/ddclient
# to enable automatic updates you must enable the daemon, see specified settings

run_dhclient="false"
run_ipup="false"
run_daemon="true"
daemon_interval="300"

# restart ddclient
$ sudo /etc/init.d/ddclient restart

source:

tags:
ddns, Dynamic DNS

Setup linux Motion Camera Raspberry pi

After you have a working raspberry pi with internet working. I used a raspberry pi 2.

Setup:
$ sudo apt-get update
$ sudo apt-get install motion

$ sudo nano /etc/motion/motion.conf
daemon on
logfile /tmp/motion.log
stream_localhost off
stream_auth_method 2
stream_authentication username:password
webcontrol_localhost off
webcontrol_authentication username:password

$ sudo nano /etc/default/motion
start_motion_daemon=yes

$ chmod -R 777 /var/lib/motion
$ chown -R pi:pi /var/lib/motion

# start motion
$ sudo service motion start
or
$ sudo /etc/init.d/motion start

You can now open up a browser from another computer on the same network and go to: http://192.168.0.85:8081 to view your web cam.
You can remotely control the web cam settings by going to http://192.168.0.85:8080.

trouble shooting:
# View if ports are listening
$ netstat -tapen | grep “LISTEN”
$ sudo nmap -sS 192.168.0.85

# test connection
telnet 127.0.0.1 8080

# view if there is any errors. Make sure log is enabled in motion.conf
# At one point the ports were not staying open after motion started was due to permission issues on /var/lib/motion. Error was found in the log.
$ cat /tmp/motion.log

# view if motion is running
$ ps aux | grep motion

# other commands
$ motion start

resources:
http://www.instructables.com/id/Raspberry-Pi-Completely-Wireless-IP-Camera-Solar/
http://www.instructables.com/id/Raspberry-Pi-as-low-cost-HD-surveillance-camera/?ALLSTEPS

multiple cameras:
http://ubuntuforums.org/showthread.php?t=1897786