This guy deserves a beer

Chances are if you are a developer or a sysadmin you had to work with regular expressions. Well I hate them. With passion. So when I discovered this website I was jumping for joy:

http://txt2re.com/

Basically you type in your clear text and select what you want extracted (certain word, integers, dates) and as a bonus you also get back code already written. Of course you probably have to adapt that one.

Transmission start-up script for slackware.

I installed transmission on a headless server so I need it to start on boot. The included start-up script was dependent on start-stop-daemon that is mission on Slackware. The examples on the transmission forums were ok but would resulted in transmission running as root and I want it to run as a non-privileged user. So I modified an example script to read like this:

 
[cce_bash]
#!/bin/bash
#Slackware startup deamon script

# Name of Service
NAME=”Transmission Daemon”

# Command to run
CMD=”/usr/bin/transmission-daemon”

# Option to run with deamon
# -a means from where to accept incoming connections, comma separated
# you may want to add your local network if you have multiple clients
OPTIONS=”-a 127.0.0.1″

# Process name of daemon, for killing it.
PROCESSNAME=”/usr/bin/transmission-daemon”

# The name of the user that should run Transmission.
# It’s RECOMENDED to run Transmission in it’s own user,
# by default, this is set to ‘transmission’.
# For the sake of security you shouldn’t set a password
# on this user
USERNAME=”transmission”

func_stop() {
if [ “$(ps aux | grep $PROCESSNAME | grep -v grep)” ]; then
echo -n “Stopping $NAME … ”
killall $PROCESSNAME
sleep 2
fi

if [ ! “$(ps aux | grep $PROCESSNAME | grep -v grep)” ]; then
echo “Done!”
else
echo “Error!”
fi
}

func_start() {
echo -n “Starting $NAME … ”
su – $USERNAME -c “$CMD $OPTIONS”
sleep 2

if [ “$(ps aux | grep $PROCESSNAME | grep -v grep)” ]; then
echo “Done!”
else
echo “Error!”
fi
}

case $1 in
“start”)
func_start
;;

“stop”)
func_stop
;;

“restart”)
func_stop
sleep 2
func_start
;;
*)
echo “Usage; start|stop|restart”
;;
esac
[/cce_bash]

After you test this script (make sure it starts as the user you want it to) be sure to add stop calls in /etc/rc.d/rc.6 , rc.K and start calls in rc.M (if you have a look at how rc.ntpd is called for example you’ll know how to add this one). Take care, breaking those scripts could leave you with a non functional system.

Adding pcntl_fork support on a cpanel server

A php application on a cpanel server kept throwing this:

[cceN_bash]
Fatal error: Call to undefined function pcntl_fork() in /path/blah.php on line 5
[/cceN_bash]

The fix requires recompiling php with –enable-pcntl Fortunately cpanel offers the Easy Apache script. The bad part is that it doesn’t have an option for pcntl. So you have to specify it as a custom compile time option. Edit (or create – for PHP5) and add /var/cpanel/easy/apache/rawopts/all_php5
[cceN_bash]
–enable-pcntl
[/cceN_bash]
On one line

Then rebuild Easy Apache.

 

Got a packet bigger than ‘max_allowed_packet’ bytes

I got this on a newly installed server when I tried to import a database:
[cce_bash]
[root@host ~]# mysql -u user -pPassword database < database.sql
Enter password:
ERROR 1153 (08S01) at line 53: Got a packet bigger than ‘max_allowed_packet’ bytes
[/cce_bash]

It’s easily fixable. The default is probably 16M, I added the following in /etc/my.cnf
[cceN_bash]
max_allowed_packet=32M
[/cceN_bash]

And restarted mysql (depending on your distro you will do this differently):
[cceN_bash]
service mysqld restart
[/cceN_bash]