Posts Tagged ‘bash’

Posted by 6bytes at 24, March, 2010

Category: Linux

Tags: , ,

If you want to avoid situation when after server restart you have to start lots of services manually, a little thing like chkconfig would come in handy.
First you might want to take a look at a list of services handled by chkconfig:

chkconfig --list

You should see something like this:

mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
named           0:off   1:off   2:off   3:on    4:off   5:off   6:off
sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

To add for example mysql to autostart list simply type:

chkconfig --add mysql on

To remove a service from autostart list type:

chkconfig --del mysql

For full list of chkconfig options go here.

Posted by 6bytes at 13, March, 2010

Category: CentOS, Linux

Tags: , , , ,

Before we install memcached we need a dependency library libevent. Check for latest stable version at http://monkey.org/~provos/libevent/

cd /usr/local/src
wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz
tar -xzvf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure --prefix=/usr/local
make
make install
cd ..

Now lets install memcached. Check for latest stable version at http://memcached.org/

wget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz
tar -xzvf memcached-1.4.4.tar.gz
cd memcached-1.4.4
LDFLAGS='-Wl,--rpath /usr/local/lib' ./configure --prefix=/usr/local
make
make install

More information about LDFLAGS http://en.wikipedia.org/wiki/Linker

Run memcached as a daemon. Basic options: d = daemon, m = memory, u = user, l = IP to listen to, p = port

memcached -u root -d

or

memcached -u root -d -m 512 -l 127.0.0.1 -p 11211

To stop daemon type

pkill memcached

Now we’re off to installing php extension memcache.

Posted by 6bytes at 23, April, 2009

Category: CentOS, Linux

Tags: , , ,

First download and unpack xmpppy.  To install it go into the unpacked directory and run:

python setup.py install

Next you need a script that will do the sending.  Use your favourite text editor to create file i.e.:

vim xsend.py

Just paste below script which was taken from original site.  Create another jabber account that you’ll send messages from and remember to change values in line 20 to those new login details.

#!/usr/bin/python
# $Id: xsend.py,v 1.8 2006/10/06 12:30:42 normanr Exp $
import sys,os,xmpp,time

if len(sys.argv) < 2:
 print "Syntax: xsend JID text"
 sys.exit(0)

tojid=sys.argv[1]
text=' '.join(sys.argv[2:])

jidparams={}
if os.access(os.environ['HOME']+'/.xsend',os.R_OK):
 for ln in open(os.environ['HOME']+'/.xsend').readlines():
 if not ln[0] in ('#',';'):
 key,val=ln.strip().split('=',1)
 jidparams[key.lower()]=val
for mandatory in ['jid','password']:
 if mandatory not in jidparams.keys():
 open(os.environ['HOME']+'/.xsend','w').write('JID=your_jabber_id@your_jabber_server.com\nPASSWORD=your_password')
 print 'Please point ~/.xsend config file to valid JID for sending messages.'
 sys.exit(0)

jid=xmpp.protocol.JID(jidparams['jid'])
cl=xmpp.Client(jid.getDomain(),debug=[])

con=cl.connect()
if not con:
 print 'could not connect!'
 sys.exit()
print 'connected with',con
auth=cl.auth(jid.getNode(),jidparams['password'],resource=jid.getResource())
if not auth:
 print 'could not authenticate!'
 sys.exit()
print 'authenticated using',auth

#cl.SendInitPresence(requestRoster=0)   # you may need to uncomment this for old server
id=cl.send(xmpp.protocol.Message(tojid,text))
print 'sent message with id',id

time.sleep(1)   # some older servers will not send the message if you disconnect immediately after sending

#cl.disconnect()

All you need to do now is to run the script :) First run will create a file in you home directory which should contain username and password from line 20. Second run should accually send the message.

./xsend.py your_main_jabber@your_jabber.com Hello world!

Now set up your monitoring scripts that will send you jabber messages when something goes wrong.