Blog Archives

Setting up NUT on Solairs

This is a copy from : https://blogs.oracle.com/mikey/entry/network_ups_tools_on_solaris

Network UPS Tools on Solaris

I have become the lucky owner of a Trust 1200VA management UPS. The bad news is that, the manufacturer provides software for Microsoft systems only. However, I found an opensource ups monitor called Network UPS Tools, that is said to work under unix a-like systems. And yes, I managed to make it work on Solaris 10, this short howto tells you how.
The first thing we need is a user account that will be used to run nut daemons. I say, the user ‘ups’, and the group ‘ups’ (also), with the home directory in /var/ups, that will be used as the state directory (this is mentioned later).

# groupadd -g 999 ups
# useradd -u 999 -g ups -d /var/ups -s /bin/false -m ups
# chown ups:ups /var/ups
# chmod 750 /var/ups

At this point you need NUT sources, that are available for download at www.networkupstools.org/source.html. You have to download, extract, and compile them:

# /usr/sfw/bin/wget www.networkupstools.org/source/2.2/nut-2.2.0.tar.gz
# gunzip -c nut-2.2.0.tar.gz | tar -xf -
# cd nut-2.2.0
# ./configure --prefix=/opt/nut --with-statepath=/var/ups --with-user=ups --with-group=ups
# make && make install

Let’s stop here for a second, as I need to explain couple of things, with regards to the configure command. The prefix is where nut is going to be installed, the statedir is the same as the home directory of previously created user, the user and the group are self-explanatory.

I presume everything went fine, there were not errors – just like in the ideal world. Ok, its time configure it a little bit. So be prepared to edit couple of files in the text editor of your choice, but please do also read the comments, as some of the options (e.g. the password) have to be changed.

/opt/nut/etc/ups.conf:

[trust]
# full list of deivers at www.networkupstools.org/compat/stable.html)
driver = megatec
port = /dev/ttya

/opt/nut/etc/upsd.conf:

# bind to localhost only
LISTEN 127.0.0.1
# define ACLs
ACL all 0.0.0.0/0
ACL localhost 127.0.0.1/32
# Accept connections from localhost...
ACCEPT localhost
# ... and reject anything else
REJECT all

/opt/nut/etc/upsd.users

# define monitor user
[monuser]
password = YOUR_PASSWORD
allowfrom = localhost
upsmon master

/opt/nut/etc/upssched.conf

CMDSCRIPT /opt/nut/bin/upssched-cmd

/opt/nut/etc/upsmon.conf

RUN_AS_USER root # root is required for shotdown
MONITOR trust@localhost 1 monuser YOUR_PASSWORD_AGAIN master
MINSUPPLIES 1
SHUTDOWNCMD "/usr/sbin/poweroff"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
NOTIFYCMD /opt/nut/bin/notify # will create this later
POWERDOWNFLAG /etc/killpower
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC
NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC
NOTIFYFLAG FSD SYSLOG+WALL+EXEC
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5

Done, now simply change permissions to only created config files, so that only ups user is able to read them as your password is stored there.

# chgrp ups ups.conf upsd.conf upsmon.conf upssched.conf
# chmod 640 ups.conf upsd.conf upsmon.conf upssched.conf

I have previously mentioned the notify script that, would mail you whenever the UPS status changes (e.g. low battery).

#!/bin/bash
echo "$\*" | mail -s "UPS state changed" foo@bar.com

Don’t forget to make it exacutable

# chmod 755 /opt/nut/bin/notify

We are almost home, the only thing left here is the SMF, so that the nut daemons would start auto-magically on system boot. You need the method and manifest files to make this work.

# mkdir -p /opt/nut/lib/svc/method
# vi nut

#!/usr/bin/sh

. /lib/svc/share/smf_include.sh

NUT_DIR=/opt/nut
STATE_DIR=/var/ups
PID_UPS=${STATE_DIR}/upsd.pid
PID_MON=/var/run/upsmon.pid

ups_stop () {
if [ -f ${PID_MON} ]; then
/usr/bin/kill `cat ${PID_MON}` > /dev/null
/usr/bin/rm -f ${PID_MON}
fi
if [ -f ${PID_UPS} ]; then
/usr/bin/kill `cat ${PID_UPS}` > /dev/null
/usr/bin/rm -f ${PID_UPS}
fi
${NUT_DIR}/bin/upsdrvctl stop > /dev/null 2>&1
}

ups_start () {
$NUT_DIR/bin/upsdrvctl start >/dev/null 2>&1
$NUT_DIR/sbin/upsd >/dev/null 2>&1
$NUT_DIR/sbin/upsmon >/dev/null 2>&1
}

##
# Start of script
#
case “$1″ in
start)
ups_start
;;
stop)
ups_stop
;;
restart)
ups_stop
while pgrep upsd > /dev/null
do
sleep 1
done
ups_start
;;
\*)
echo “”
echo “Usage: `basename $0` { start | stop | restart }”
echo “”
exit 64
;;
esac

# vi /var/svc/manifest/network/nut.xml

<?xml version=”1.0″?>
<!DOCTYPE service_bundle SYSTEM “/usr/share/lib/xml/dtd/service_bundle.dtd.1″>

<service_bundle type=’manifest’ name=’nut’>
<service name=’application/nut’ type=’service’ version=’1′>

<instance name=’default’ enabled=’false’>

<dependency name=’network’
grouping=’require_all’
restart_on=’error’
type=’service’>
<service_fmri value=’svc:/milestone/network:default’/>
</dependency>

<dependency name=’filesystem-local’
grouping=’require_all’
restart_on=’none’
type=’service’>
<service_fmri
value=’svc:/system/filesystem/local:default’/>
</dependency>

<exec_method
type=’method’
name=’start’
exec=’/opt/nut/lib/svc/method/nut start’
timeout_seconds=’60’>
<method_context />
</exec_method>

<exec_method
type=’method’
name=’stop’
exec=’/opt/nut/lib/svc/method/nut stop’
timeout_seconds=’60’>
<method_context />
</exec_method>

<exec_method
type=’method’
name=’refresh’
exec=’/opt/nut/lib/svc/method/nut restart’
timeout_seconds=’60’>
<method_context />
</exec_method>

</instance>

<stability value=’Evolving’ />
<template>
<common_name>
<loctext xml:lang=’C’>
Network UPS Tools
</loctext>
</common_name>
</template>

</service>
</service_bundle>

You can download them directly from:
blogs.sun.com/mikey/resource/method-nut and blogs.sun.com/mikey/resource/manifest-nut

That’s everything, time to enable the service and test the configuration:

# svccfg import nut.xml
# svcadm enable svc:/application/nut:default
# /opt/nut/bin/upsc trust@localhost

battery.charge: 95.0
battery.voltage: 13.50
battery.voltage.nominal: 12.0
driver.name: megatec
driver.parameter.pollinterval: 2
driver.parameter.port: /dev/ttya
driver.version:
driver.version.internal: 1.5.4
input.frequency: 49.9
input.voltage: 247.0
input.voltage.fault: 247.0
input.voltage.maximum: 252.3
input.voltage.minimum: 243.0
output.voltage: 247.0
output.voltage.nominal: 230.0
ups.beeper.status: enabled
ups.delay.shutdown: 0
ups.delay.start: 2
ups.load: 11.0
ups.mfr: unknown
ups.model: unknown
ups.serial: unknown
ups.status: OL
ups.temperature: 25.0

You should be able to see the output similar to this above, which is a kind of confirmation that everything works fine.

SACalendar

SACalendar is a customizable iOS 7 Calendar.



Download here

Logging service for Swift – Swell

Swell is a logging utility for Swift and Objective C.

Features

????Turn on logging during development, turn them off when building for the App Store
????Enable or disable logging for specific classes
????Different log levels allow for finer-grained control of logging within a class
????Log to the console, text file, or a custom location
????Log message isn’t computed when logging is disabled (thanks to the @auto_closure feature)

Download here

How to create ring ton for iPhone using iTunes

Create iPhone ringtone is a fairly easy process.

  1. Start iTunes and find the song (MP3) you want to convert.
  2. Using song info, in the Options tab, check the Start Time and Stop Time boxes, then enter times for each (no more than 30 seconds). Click OK.
  3. From song sub-menu (right-click) choose Create AAC Version. New 30-second version of the song will be added immediately.
  4. Copy this new song out of iTunes and into the folder of your choice.
  5. Delete the 30-second version from iTunes and revert the Start Time/Stop Time changes to the original.
  6. In the folder containing the 30-second AAC file you dragged out of iTunes, change the file extension from .m4a to .m4r. Double-click it and it immediately gets added to iTunes’ ringtone library.
  7. Finally, sync your iPhone to get this new ring ton into ringtone list.

Autolayout views evenly spaced

Good solution to autolayout evenly spaced components in the view.
Link: stackoverflow.com/a/14568394

Usage:

[self.view addConstraints:       [NSLayoutConstraint constraintsForEvenDistributionOfItems:@[label1, label2, label3, label4]                                          relativeToCenterOfItem:self.view                                                      vertically:YES]];

NSLayoutConstraint+EvenDistribution.h

@interface NSLayoutConstraint (EvenDistribution)    /**   * Returns constraints that will cause a set of views to be evenly distributed horizontally   * or vertically relative to the center of another item. This is used to maintain an even   * distribution of subviews even when the superview is resized.   */  + (NSArray *) constraintsForEvenDistributionOfItems:(NSArray *)views                               relativeToCenterOfItem:(id)toView                                           vertically:(BOOL)vertically;    @end

NSLayoutConstraint+EvenDistribution.m

@implementation NSLayoutConstraint (EvenDistribution)    +(NSArray *)constraintsForEvenDistributionOfItems:(NSArray *)views                             relativeToCenterOfItem:(id)toView vertically:(BOOL)vertically  {      NSMutableArray *constraints = [NSMutableArray new];      NSLayoutAttribute attr = vertically ? NSLayoutAttributeCenterY : NSLayoutAttributeCenterX;        for (NSUInteger i = 0; i < [views count]; i++) {          id view = views[i];          CGFloat multiplier = (2*i + 2) / (CGFloat)([views count] + 1);          NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view                                                                        attribute:attr                                                                        relatedBy:NSLayoutRelationEqual                                                                           toItem:toView                                                                        attribute:attr                                                                       multiplier:multiplier                                                                         constant:0];          [constraints addObject:constraint];      }        return constraints;  }  @end  

Objective-C execute once

Ref: http://stackoverflow.com/a/9572119

Making code run only once is simple with Objective-C:

static dispatch_once_t once;  dispatch_once(&once, ^ {  // Code to run once  });  

Make sure that you properly define once variable.

FreeNAS UPS configuration

I am using a small UPS CyberPower 425VA with my FreeNAS server. After upgrading to latest 8.2 (BETA3), the UPS services stopped working.

I had similar issue in the past, but manage to find compatible selection of arguments and UPS monitor was working great (even get email while been in Spain on vacation about power outage).

But now, it wan’t start at all:

Jun 16 11:20:17 freenas notifier: Network UPS Tools – Generic HID driver 0.35 (2.6.2)
Jun 16 11:20:17 freenas notifier: USB communication driver 0.31
Jun 16 11:20:17 freenas notifier: No matching HID UPS found
Jun 16 11:20:17 freenas notifier: Driver failed to start (exit status=1)
Jun 16 11:20:17 freenas notifier: Network UPS Tools – UPS driver controller 2.6.2

After several attempts and search on internet I found a link to this article: usbhid-ups and APC Smart-UPS 1500

So once I get report from usbhid-ups, which correspond to my UPS connection (see below), I grab VendorID and ProductID:

0.001034 Checking device (0764/0501) (/dev/usb//dev/ugen0.2)
4.886523 – VendorID: 0764
4.886550 – ProductID: 0501
4.886557 – Manufacturer: unknown
4.886566 – Product: unknown
4.886573 – Serial Number: unknown
4.886579 – Bus: /dev/usb

and changed UPS Settings for service:

Note: make sure you put few spaces in front of each line.

Once settings are saved, start the UPS service.

Enjoy!

How to find the soil type in your area.

I was looking for an information about soil type in my area and come across the online GIST system Web Soil Survey, which give me all information I need to know.

You will need select an area of interest using Soil Survey area section and pressing on “Set AOI”.

Navigate to soil map and navigate the map to see your area.

Setting up IIS 6 for HTTPS

In order to set IIS 6 to respond HTTPS requests the server must be configured with Certificate.
The certificate can be requested from Certificate Authorities, or you can simply self certificate the server.
For the second option you need to follow these simple steps:
1) Download and Install IIS 6.0 Resource Kit Tools from:

http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499&displaylang=en

2) Once IIS Resource Kit installed, open IIS Metabase Explorer (Start menu->Programs->IIS Resources->Metabase Explorer). Go to LM->W3SVC and select the items on the left to see on the right a description of them and find your virtual site (the default Web Site usually has ID 1). At this point, suppose the site has ID=123 you have to issue run from command prompt (you might need to change current directory to ‘Program FilesIIS ResourcesSelfSSL’):

SelfSSL /N:CN=yoursite.yourdomain.com /V:365 /S:123

where:

/N:CN is the name of your site on the internet (or LAN)
/V: sets the number of days before the new certify expires
/S: is the ID we found

After this command line is completed, the site is ready to go.

iOS 4: Exchange Mail, Contacts, or Calendars may not sync after update

I know you guys have iPhones, this may be interesting for you.  If you know anyone else using iPhones with Exchange server, you might want to read this:

support.apple.com/kb/TS3398

WP Like Button Plugin by Free WordPress Templates