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);
};


No comments: