Monday, February 23, 2009

ps on Solaris -- zone tip

This is a mini-tip. I was running a ps command to see if snmp was running on a particular host and got back way too much information:

# ps -ef |grep snmp
root 938 1 1 Jan 17 ? 2906:56 /usr/local/sbin/snmpd -r
root 13536 1 0 Jan 25 ? 59:46 /usr/local/sbin/snmpd -r
root 2545 1 0 Jan 17 ? 19:32 /usr/local/sbin/snmpd -r
root 6050 26619 0 08:48:36 pts/2 0:00 grep snmp


At a glance I wanted to know what host the command was running on and it wasn't obvious, so I looked at the man page for the ps command and sure enough there was a new option that I didn't know about -- the "Z" option, which tells you which zone it's running on.

Very nice job SUN! Here's the new command:


# ps -efZ |grep snmp
global root 938 1 1 Jan 17 ? 2907:03 /usr/local/sbin/snmpd -r
host1 root 13536 1 0 Jan 25 ? 59:46 /usr/local/sbin/snmpd -r
host2 root 2545 1 0 Jan 17 ? 19:32 /usr/local/sbin/snmpd -r
global root 6189 26619 0 08:50:32 pts/2 0:00 grep snmp

Friday, February 20, 2009

Upgrading Solaris on hosts without a DVD or CDROM drive

http://docs.sun.com/app/docs/doc/817-5504/6mkv4nh96?a=view

This is the easiest way to upgrade hosts that don't have a local cdrom or DVD disk.

One thing to remember is that the two hosts need to be on a subnet that have no other tftpboot servers...

Thursday, January 15, 2009

Solaris SMF import failure

Ever get the following message when trying to import an SMF manifest:
# svccfg import /var/svc/manifest/system/syslog-ng.xml
svccfg: Temporary service "TEMP/system/syslog-ng" must be deleted before this manifest can be imported.
svccfg: Import of /var/svc/manifest/system/syslog-ng.xml failed. Progress:
svccfg: Service "system/syslog-ng": not reached.
svccfg: Instance "default": not reached.

The answer is to delete it using:

# svccfg delete -f TEMP/system/syslog-ng

Then you can re-import it and enable it:

# svccfg import /var/svc/manifest/system/syslog-ng.xml
# svcadm enable syslog-ng

Tuesday, December 30, 2008

Script to set up syslog-ng on Solaris 10 hosts



#!/bin/sh
# This script is for Solaris 10

echo Creating syslog-ng.conf
mkdir /etc/syslog-ng 2>/dev/null
cat << END > /etc/syslog-ng/syslog-ng.conf
options {
stats(0);
sync(0);
time_reopen(1);
log_fifo_size(4096);
long_hostnames(off);
use_dns(no);
use_fqdn(no);
create_dirs(yes);
keep_hostname(yes);
};

source sys {
sun-streams("/dev/log" door("/etc/.syslog_door"));
internal();
udp();
tcp(ip("0.0.0.0") port(5150) max-connections(300));
};

filter notdebug {
level(info...emerg);
};
destination perhost {
file("/var/log/perhost/$HOST.log.$YEAR$MONTH$DAY");
};
log {
source(sys);
filter(notdebug);
destination(perhost);
};

destination syslog-ng-server {
tcp("10.10.10.10" port(5150));
};
log {
source(sys);
filter(notdebug);
destination(syslog-ng-server);
};
END
chown root:sys /etc/syslog-ng/syslog-ng.conf
chmod 644 /etc/syslog-ng/syslog-ng.conf

echo Removing old init script links if they exist
rm -f /etc/init.d/syslog /etc/rc2.d/S74syslog /etc/init.d/syslog /etc/rc0.d/K40syslog /etc/init.d/syslog /etc/rc1.d/K40syslog /etc/init.d/syslog /etc/rcS.d/K40syslog

echo Disabling stock syslog
svcadm disable system-log

echo Setting up syslog-ng method script
cat </lib/svc/method/svc-syslog-ng
#!/bin/sh
. /lib/svc/share/smf_include.sh

# Start processes required for syslog-ng

# Required for certain libgcc and eventlog libraries
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/sfw/lib
export LD_LIBRARY_PATH

if [ -x /usr/local/sbin/syslog-ng ]; then
/usr/local/sbin/syslog-ng -f /etc/syslog-ng/syslog-ng.conf
else
echo "syslog-ng is missing or not executable."
exit $SMF_EXIT_ERR_CONFIG
fi

exit $SMF_EXIT_OK
E0F
chown root:bin /lib/svc/method/svc-syslog-ng
chmod 755 /lib/svc/method/svc-syslog-ng

echo Setting up SMF manifest
cat </var/svc/manifest/system/syslog-ng.xml




name='system/syslog-ng'
type='service'
version='1'>





name='milestone'
grouping='require_all'
restart_on='none'
type='service'>




name='filesystem'
grouping='require_all'
restart_on='none'
type='service'>




name='autofs'
grouping='optional_all'
restart_on='none'
type='service'>




name='name-services'
grouping='require_all'
restart_on='none'
type='service'>



name='syslog-ng_single-user'
grouping='optional_all'
restart_on='none'>




type='method'
name='start'
exec='/lib/svc/method/svc-syslog-ng'
timeout_seconds='60' />

type='method'
name='stop'
exec=':kill'
timeout_seconds='60' />

type='method'
name='refresh'
exec=':kill -HUP'
timeout_seconds='60' />



value='solaris.smf.manage.syslog-ng' />








E0F
chown root:sys /var/svc/manifest/system/syslog-ng.xml
chmod 444 /var/svc/manifest/system/syslog-ng.xml

echo Validating manifest
svccfg validate /var/svc/manifest/system/syslog-ng.xml

echo Importing manifest
svccfg import /var/svc/manifest/system/syslog-ng.xml

echo Starting syslog-ng
svcadm enable syslog-ng
root@maass> more /etc/syslog-ng/syslog-ng.conf
options {
stats(0);
sync(0);
time_reopen(1);
log_fifo_size(4096);
long_hostnames(off);
use_dns(no);
use_fqdn(no);
create_dirs(yes);
keep_hostname(yes);
};

source sys {
sun-streams("/dev/log" door("/etc/.syslog_door"));
internal();
udp();
tcp(ip("0.0.0.0") port(5150) max-connections(300));
};

filter notdebug {
level(info...emerg);
};
destination perhost {
file("/var/log/perhost/$HOST.log.$YEAR$MONTH$DAY");
};
log {
source(sys);
filter(notdebug);
destination(perhost);
};

destination florey {
tcp("144.83.19.28" port(5150));
};
log {
source(sys);
filter(notdebug);
destination(florey);
};


Syslog-ng log evacuation

#!/bin/sh

#calculate yesterday's date
YESTERDAY=`env TZ=EST29EDT date +%Y%m%d`

#find the logs associated with yesterday
LOGS=`/usr/bin/find /var/log/perhost -name "*.$YESTERDAY"`
PROXYLOGS=`/usr/bin/find /var/log/proxy -name "*.$YESTERDAY"`

#compress the logs
/usr/bin/gzip $LOGS
/usr/bin/gzip $PROXYLOGS

#now select the logs.gz
GZLOGS=`/usr/bin/find /var/log/perhost -name "*.$YESTERDAY.gz"`
PROXYGZ=`/usr/bin/find /var/log/proxy -name "*.$YESTERDAY.gz"`

#change ownership of the files so the remote sawmill process can read them
/usr/bin/chmod 644 /var/log/perhost/*


#cp the files to sawmill ~logevac
/usr/bin/cp $GZLOGS /nfsserver/servers/sawmill/evacuated-logs
/usr/bin/cp $PROXYGZ /nfsserver/servers/sawmill/proxy-logs-to-be-processed
#
/usr/bin/chmod 644 /nfsserver/servers/sawmill/evacuated-logs/*
/usr/bin/chown 55555:55555 /nfsserver/servers/sawmill/evacuated-logs/*

# remove the local syslog-ng server files after 7 days
oldlogs=`/usr/bin/find /var/log -mtime +7`
/usr/bin/rm $oldlogs

# clear out the logfiles older than 21 days
/usr/bin/find /hjfnfs/servers/sawmill/evacuated-logs -name "*log*.gz" -mtime +21 -exec /usr/bin/rm -f {} \;

Script to clear out Solaris corefiles

Run this from the global zone...




#!/bin/sh
#
# clear out corefiles
# miw 9/1/06
#
/usr/bin/rm /var/core/core*
/usr/bin/rm /zones/*/root/var/core/core*


Script to email basic system info



#!/bin/sh

#
# This script emails basic system info to sysadmin
#
#
SERVERNAME=`uname -n`
file=/usr/local/scripts/safe
#
uname -a > $file
#
/usr/bin/df -F ufs -o i >>$file
#
for i in /etc/passwd /etc/group /etc/vfstab
do
echo "">>$file
echo "***********************************************************************" >
> $file
ls -l $i >> $file
cat $i >> $file
done
#
#for a in "swap -l" "df -k" "prtvtoc /dev/dsk/c1t0d0s0" /usr/sbin/metastat "/usr
/sbin/metadb -i"
#do
#echo "***********************************************************************"
>>$file
#echo "$a" >> $file
#$a >> $file
#done
#
cat $file|mailx -s recovery_info_$SERVERNAME me@myhost.com