cod3fr3ak
December 27th, 2004, 14:15
Can anyone tell me why the follwoing script will not kick off a mysql client session from either /etc/rc or /etc/rc.local:


#!/bin/sh -x
ps=`ps -ax | grep "\--password=x" | awk '{ print $9 }'`

if [[ $ps != "" ]]; then
echo "syslog-ng2mysql is alive."
else
echo "syslog-ng2mysql is dead. Attempting to restart..."
if [ ! -p /tmp/mysql.pipe ]; then
mkfifo /tmp/mysql.pipe
kill -HUP `cat /var/run/syslog-ng.pid`
fi
mysql -u root --password=password syslog < /tmp/mysql.pipe &
fi
exit 0


I have tried everything i know to get this to startup automatically. placing it in cron just give bunches of mails from cron about the process hanging. I've tried calling the script itself both with and without and "&", as well as removing and replacing the "&" in the mysql line.

bmw
December 27th, 2004, 21:58
I'm unfamiliar with the double-square-brackets syntax ...
if [[ $ps != "" ]]; then
Unless that does something especially funky, you'd normally code it as
if [ "$ps" != "" ]; then
If you don't do that you'll get a syntax error when $ps is empty.

Other than that -- I'm not familar with mysql, but if this line doesn't dissassociate itself from the controlling tty ...
mysql -u root --password=password syslog < /tmp/mysql.pipe &
then it will hang up the shell that runs from cron. You may need to write a daemonizing script which closes stdout, stderr etc. and properly "daemonizes" mysql. I bet there's FAQs on that in MySQL dox/web-pages somewhere.

cod3fr3ak
December 30th, 2004, 14:01
Tried using an app called daemonize, but that failed to work as well.

cod3fr3ak
January 3rd, 2005, 14:14
I still haven't found a way to get this thing going automagically.

soup4you2
January 3rd, 2005, 19:10
how about something like:


#!/usr/local/bin/bash

check=$(ps -ax | grep mysql)

if [ "$check" != "" ];then
echo "Process is alive.. A-L-I-V-E!"
else
echo "syslog-ng2mysql is dead. Attempting to restart..."
if test -e /tmp/mysql.pipe
then
echo "Pipe Exists.."
else
mkfifo /tmp/mysql.pipe
kill -HUP `cat /var/run/syslog-ng.pid`
fi
mysql -u root --password=password syslog < /tmp/mysql.pipe &
fi
exit 0

soup4you2
January 3rd, 2005, 21:01
now that i think about it i've had problems in the past where crontab could not spawn processes.. there was a time that the dhcpd server kept crashing ever 3 to 4 hours.. so until i could figure it out i wrote up a script to sockstat it.. and if it found null then restart it.. never worked though because crontab could never swawn a daemon with a socket..

i ended up having to run the script by hand and have it run though a loop every couple mins, then assign it to a PID

cod3fr3ak
January 5th, 2005, 10:30
Hmmmm. I am thinking thats what I might have to do as well, which really is a pain, since I was trying to upgrade my current secure log server, and add php-syslog-ng access.

cod3fr3ak
January 5th, 2005, 10:33
Ok. So after testing the heck out of this I've found out that everything in the script runs up until the mysql command. In fact the mysql command does run, but the proggie hangs at the redirect point. Does anyone know if there are rule in OBSD about doing redirections during startup, /etc/rc, /etc/rc.local, etc.

cod3fr3ak
January 5th, 2005, 10:45
Eureka!
I think you are not allowed to start things in /etc/rc, and redirect cause the default starts as nobody. heres what I put in to get this thing going:

su - root -c "/etc/check_syslog-ng2mysql.sh" &

I know not the most secure method, but its a start.

cod3fr3ak
January 5th, 2005, 11:26
OKAY! FINAL post:

heres what I have in my /etc/rc.local file:


# MYSQL
if [ X"${mysql}" == X"YES" ]; then
if [ -x /usr/local/bin/mysqld_safe ]; then
echo -n " mysql"; /usr/local/bin/mysqld_safe --socket=/var/www/var/run/mysql/mysql.sock &
sleep 10
echo -n " syslog-ng2mysql"; su - root -c "/etc/check_syslog-ng2mysql.sh" &
fi
fi


where /etc/check_syslog-ng2mysql.sh is:


#!/usr/local/bin/bash -x

ps=`ps -ax | grep "\--password=x" | awk '{ print $9 }'`

if [[ $ps != "" ]]; then
echo "syslog-ng2mysql is alive."
else
if [ ! -p /tmp/mysql.pipe ]; then
mkfifo /tmp/mysql.pipe
kill -HUP `cat /var/run/syslog-ng.pid`
fi
mysql -u root --password=password syslog < /tmp/mysql.pipe &
fi


I am going to work on creating a no-priv user to kick this off.