This tutorial will show how to set samba to allow read-only file sharing for your LAN computers as guest (without be prompted for a password).

Because users won’t be prompted for a user/password, this tutorial is meant to be installed in a LAN where all host are to be trusted.

There is many advantages of sharing files in a LAN. For instance, when you have a multimedia box (playing music, movies….) it is great to be able to access the music on that box from any machines in your LAN.

Let’s get started. In the first place, you need to have samba installed.

$sudo apt-get install samba

Because we are going to make samba security insecure, make sure only your local network can access samba service. To do so, open and edit/etc/samba/smb.conf

$sudo vi /etc/samba/smb.conf

and set interfaces to lo and your local network interface. In my case: eth1.

interfaces = lo eth1
bind interfaces only = true

Now, it is time to smoothen samba default security by changing the security variable: security and make sure it is set to share instead ofuser and that guest account is enabled:

security = share
...
...
guest account = nobody

Now, we can create a share to be accessible to guest users:

[Guest Share]
        comment = Guest access share
        path = /path/to/dir/to/share
        browseable = yes
        read only = yes
        guest ok = yes

You can now test that your configuration is good using testparm:

$ testparm

If everything is fine, it is time to reload samba service to have your new configuration taken into account:

$sudo /etc/init.d/samba reload

That’s it, anybody in your LAN can now access your share.

  • Comments Off

Create daemons in PHP

» Create daemons in PHP

Everyone knows PHP can be used to create websites. But it can also be used to create desktop applications and commandline tools. And now with a class called System_Daemon, you can even create daemons using nothing but PHP. And did I mention it was easy?

What is a Daemon?

A daemon is a Linux program that run in the background, just like a ‘Service‘ on Windows. It can perform all sorts of tasks that do not require direct user input. Apache is a daemon, so is MySQL. All you ever hear from them is found in somewhere in /var/log, yet they silently power over 40% of the Internet.

You reading this page, would not have been possible without them. So clearly: a daemon is a powerful thing, and can be bend to do a lot of different tasks.

Why PHP?

Most daemons are written in C. It’s fast & robust. But if you are in a LAMP oriented company like me, and you need to create a lot of software in PHP anyway, it makes sense:

  • Reuse & connect existing code Think of database connections, classes that create customers from your CRM, etc.
  • Deliver new applications very fast PHP has a lot of build in functions that speed up development greatly.
  • Everyone knows PHP (right?) If you work in a small company: chances are there are more PHP programmers than there are C programmers. What if your C guy abandons ship? Admittedly it’s a very pragmatic reason, but it’s the same reason why Facebook is building HipHop.

Possible use cases

  • Website optimization If you’re running a (large) website, jobs that do heavy lifting should be taken away from the user interface and scheduled to run on the machine separately.
  • Log parser Continually scan logfiles and import critical messages in your database.
  • SMS daemon Read a database queue, and let your little daemon interface with your SMS provider. If it fails, it can easily try again later!
  • Video converter (think Youtube) Scan a queue/directory for incoming video uploads. Make some system calls to ffmpeg to finally store them as Flash video files. Surely you don’t want to convert video files right after the upload, blocking the user interface that long? No: the daemon will send the uploader a mail when the conversion is done, and proceed with the next scheduled upload

Deamons vs Cronjobs

Some people use cronjobs for the same Possible use cases. Crontab is fine but it only allows you to run a PHP file every minute or so.

  • What if the previous run hasn’t finished yet? Overlap can seriously damage your data & cause siginificant load on your machines.
  • What if you can’t afford to wait a minute for the cronjob to run? Maybe you need to trigger a process the moment a record is inserted?
  • What if you want to keep track of multiple ‘runs’ and store data in memory.
  • What if you need to keep your application listening (on a socket for example) Cronjobs are a bit rude for this, they may spin out of control and don’t provide a

framework for logging, etc. Creating a daemon would offer more elegance & possibilities. Let’s just say: there are very good reasons why a Linux OS isn’t composed entirely of Cronjobs :)

How it works internally

(Nerd alert!) When a daemon program is started, it fires up a second child process, detaches it, and then the parent process dies. This is called forking. Because the parent process dies, it will give the console back and it will look like nothing has happened. But wait: the child process is still running. Even if you close your terminal, the child continues to run in memory, until it either stops, crashes or is killed.

In PHP: forking can be achieved by using the Process Control Extensions. Getting a good grip on it, may take some studying though.

System_Daemon

Because the Process Control Extensions‘ documentation is a bit rough, I decided to figure it out once, and then wrap my knowledge and the required code inside a PEAR class called: System_Daemon. And so now you can just:

require_once “System/Daemon.php”;                 // Include the Class
 
System_Daemon::setOption(“appName”, “mydaemon”);  // Minimum configuration
System_Daemon::start();                           // Spawn Deamon!

And that’s all there is to it. The code after that, will run in your server’s background. So next, if you create a while(true) loop around that code, the code will run indefinitely. Remember to build in a sleep(5) to ease up on system resources.

Features & Characteristics

Here’s a grab of System_Daemon’s features:

  • Daemonize any PHP-CLI script
  • Simple syntax
  • Driver based Operating System detection
  • Unix only
  • Additional features for Debian / Ubuntu based systems like:
  • Automatically generate startup files (init.d)
  • Support for PEAR’s Log package
  • Can run with PEAR (more elegance & functionality) or without PEAR (for standalone packages)
  • Default signal handlers, but optionally reroute signals to your own handlers.
  • Set options like max RAM usage

Download

You could download the package from PEAR, or, if you have PEAR installed on your system: just run this from a console:

pear install -f System_Daemon

You can also update it using that last command.

Beta

Though I have quite some daemons set up this way, it’s officially still beta. So please report any bugs over at the PEAR page. Other comments may be posted here.

Complex Example

Ready to dig a little deeper? This example program is called ‘logparser’, it takes a look at a more complex use of System_Daemon. For instance, it introduces command line arguments like:

--no-daemon              # just run the program in the console this time
--write-initd            # writes a startup file

Read this source to get the picture. Don’t forget the comments!

#!/usr/bin/php -q
<?php
/**
 * System_Daemon turns PHP-CLI scripts into daemons.
 *
 * PHP version 5
 *
 * @category  System
 * @package   System_Daemon
 * @author    Kevin <kevin@vanzonneveld.net>
 * @copyright 2008 Kevin van Zonneveld
 * @license   http://www.opensource.org/licenses/bsd-license.php
 * @link      http://github.com/kvz/system_daemon
 */
 
/**
 * System_Daemon Example Code
 *
 * If you run this code successfully, a daemon will be spawned
 * but unless have already generated the init.d script, you have
 * no real way of killing it yet.
 *
 * In this case wait 3 runs, which is the maximum for this example.
 *
 *
 * In panic situations, you can always kill you daemon by typing
 *
 * killall -9 logparser.php
 * OR:
 * killall -9 php
 *
 */
 
// Allowed arguments & their defaults 
$runmode = array(
    ‘no-daemon’ => false,
    ‘help’ => false,
    ‘write-initd’ => false,
);
 
// Scan command line attributes for allowed arguments
foreach ($argv as $k=>$arg) {
    if (substr($arg, 0, 2) == ‘–’ && isset($runmode[substr($arg, 2)])) {
        $runmode[substr($arg, 2)] = true;
    }
}
 
// Help mode. Shows allowed argumentents and quit directly
if ($runmode['help'] == true) {
    echo ‘Usage: ‘.$argv[0].‘ [runmode]‘ . \n;
    echo ‘Available runmodes:’ . \n;
    foreach ($runmode as $runmod=>$val) {
        echo ‘ –’.$runmod . \n;
    }
    die();
}
 
// Make it possible to test in source directory
// This is for PEAR developers only
ini_set(‘include_path’, ini_get(‘include_path’).‘:..’);
 
// Include Class
error_reporting(E_ALL);
require_once ‘System/Daemon.php’;
 
// Setup
$options = array(
    ‘appName’ => ‘logparser’,
    ‘appDir’ => dirname(__FILE__),
    ‘appDescription’ => ‘Parses vsftpd logfiles and stores them in MySQL’,
    ‘authorName’ => ‘Kevin van Zonneveld’,
    ‘authorEmail’ => ‘kevin@vanzonneveld.net’,
    ’sysMaxExecutionTime’ => ‘0′,
    ’sysMaxInputTime’ => ‘0′,
    ’sysMemoryLimit’ => ‘1024M’,
    ‘appRunAsGID’ => 1000,
    ‘appRunAsUID’ => 1000,
);
 
System_Daemon::setOptions($options);
 
// This program can also be run in the forground with runmode –no-daemon
if (!$runmode['no-daemon']) {
    // Spawn Daemon 
    System_Daemon::start();
}
 
// With the runmode –write-initd, this program can automatically write a 
// system startup file called: ‘init.d’
// This will make sure your daemon will be started on reboot 
if (!$runmode['write-initd']) {
    System_Daemon::info(‘not writing an init.d script this time’);
} else {
    if (($initd_location = System_Daemon::writeAutoRun()) === false) {
        System_Daemon::notice(‘unable to write init.d script’);
    } else {
        System_Daemon::info(
            ’sucessfully written startup script: %s’,
            $initd_location
        );
    }
}
 
// Run your code
// Here comes your own actual code
 
// This variable gives your own code the ability to breakdown the daemon:
$runningOkay = true;
 
// This variable keeps track of how many ‘runs’ or ‘loops’ your daemon has
// done so far. For example purposes, we’re quitting on 3.
$cnt = 1;
 
// While checks on 3 things in this case:
// - That the Daemon Class hasn’t reported it’s dying
// - That your own code has been running Okay
// - That we’re not executing more than 3 runs 
while (!System_Daemon::isDying() && $runningOkay && $cnt <=3) {
    // What mode are we in?
    $mode = ‘”‘.(System_Daemon::isInBackground() ?  : ‘non-’ ).
        ‘daemon” mode’;

    // Log something using the Daemon class’s logging facility
    // Depending on runmode it will either end up:
    //  - In the /var/log/logparser.log
    //  - On screen (in case we’re not a daemon yet)  
    System_Daemon::info(‘{appName} running in %s %s/3′,
        $mode,
        $cnt
    );

    // In the actuall logparser program, You could replace ‘true’
    // With e.g. a  parseLog(’vsftpd’) function, and have it return
    // either true on success, or false on failure.
    $runningOkay = true;
    //$runningOkay = parseLog(’vsftpd’);

    // Should your parseLog(’vsftpd’) return false, then
    // the daemon is automatically shut down.
    // An extra log entry would be nice, we’re using level 3,
    // which is critical.
    // Level 4 would be fatal and shuts down the daemon immediately,
    // which in this case is handled by the while condition.
    if (!$runningOkay) {
        System_Daemon::err(‘parseLog() produced an error, ‘.
            ’so this will be my last run’);
    }

    // Relax the system by sleeping for a little bit
    // iterate also clears statcache
    System_Daemon::iterate(2);

    $cnt++;
}
 
// Shut down the daemon nicely
// This is ignored if the class is actually running in the foreground
System_Daemon::stop();

Console action: Controlling the Daemon

Now that we’ve created an example daemon, it’s time to fire it up! I’m going to assume the name of your daemon is logparser. This can be changed with the statement: System_Daemon::setOption('appName', 'logparser'). But the name of the daemon is very important because it is also used in filenames (like the logfile).

Execute

Just make your daemon script executable, and then execute it:

chmod a+x ./logparser.php ./logparser.php

Check

Your daemon has no way of communicating through your console, so check for messages in:

tail /var/log/logparser.log And see if it’s still running:

ps uf -C logparser.php

Kill

Without the start/stop files (see below for howto), you need to:

killall -9 logparser.php Autch.. Let’s work on those start / stop files, right?

Start / Stop files (Debian & Ubuntu only)

Real daemons have an init.d file. Remember you can restart Apache with the following statement?

/etc/init.d/apache2 restart That’s a lot better than killing. So you should be able to control your own daemon like this as well:

/etc/init.d/logparser stop /etc/init.d/logparser start Well with System_Daemon you can write autostartup files using the writeAutoRun() method, look:

$path = System_Daemon::writeAutoRun();On success, this will return the path to the autostartup file: /etc/init.d/logparser, and you’re good to go!

Run on boot

Surely you want your daemon to run at system boot.. So on Debian & Ubuntu you could type:

update-rc.d logparser defaults Done your daemon now starts every time your server boots. Cancel it with:

update-rc.d -f logparser remove

Logrotate

Igor Feghali shares with us a logrotate config file to keep your log files from growing too large. Just place a file in your /etc/logrotate.d/.

/var/log/mydaemon.log { rotate 15 compress missingok notifempty sharedscripts size 5M create 644 mydaemon_user mydaemon_group postrotate /bin/kill -HUP `cat /var/run/mydaemon/mydaemond.pid 2>/dev/null` 2> /dev/null || true endscript } Obviously, replace the mydaemon occurances with values corresponding to your environment. Thanks Igor!

Troubleshooting

Here are some issues you may encounter down the road.

  • Don’t use echo() **Echo writes to the STDOUT of your current session. If you logout, that will cause fatal errors and the daemon to die. Use System_Daemon::log() instead.
  • Connect to MySQL after you start() the daemon. Otherwise only the parent process will have a MySQL connection, and since that dies.. It’s lost and you will get a ‘MySQL has gone away’ error.
  • Error handling Good error handling is imperative. Daemons are often mission critical applications and you don’t want an uncatched error to bring it to it’s knees.
    • Reconnect to MySQL A connection may be interrupted. Think about network downtime or lock-ups when your database server makes backups. Whatever the cause: You don’t want your daemon to die for this, let it try again later.
    • PHP error handler As of 0.6.3, System_Daemon forwards all PHP errors to the log() method, so keep an eye on your logfile. This behavior can be controlled using the logPhpErrors (true||false) option.
  • Monit Monit is a standalone program that can kickstart any daemon, based on your parameters. Should your daemon fail, monit will mail you and try to restart it.
  • Watch that memory Some classes keep a history of executed commands, sent mails, queries, whatever. They were designed without knowing they would ever be used in a daemonized environment. Cause daemons run indefinitely this ‘history’ will expand indefinitely. Since unfortunately your server’s RAM is not infinite, you will run into problems at some point. This makes it’s very important to address these memory ‘leaks’ when building daemons.
  • Statcache will corrupt your data If you do a file_exists(), PHP remembers the results to ease on your disk until the process end. That’s ok but since the Daemon process does not end, PHP will not be able to give you up to date information. As of 0.8.0 you should call System_Daemon::iterate(2) instead of e.g. sleep(2), this will sleep & clear the cache and give you fresh & valid data.

I know I’m saying MySQL a lot, but you can obviously replace that with Oracle, MSSQL, PostgreSQL, etc.

  • Comments Off

run php script on startup

Suse appears to use init scripts to launch apps at start up and you will need to write a custom init script to launch your socket.php script.

At the bare minimum, you could create an executable script in /etc/rc2.d named S99socket containing

#!/bin/sh
/path/to/php /path/to/socket.php &

  • Comments Off

Installing !Openmeetings on debian etch

First variant (works with lenny as well):

Download the following debian package: http://www.expressaas.com/distrib/release/red5-openmeetings_1.0.2760.noarch.deb

And install it using sudo dpkg -i red5-openmeetings_1.0.2760.noarch.deb command. All additional utilities, such as Openoffice, Ghostscript, Imagemagick and Swftools should be installed as described below.

Second variant (outdated):

this sample is rather outdated

the installation procedure (if you forget of all 3th party requirements) is as simple as the following:

donwload openmeetings-package (you can download it into your home-directory)
unzip it
cd /openmeetings-package/webapps/openmeetings/conf and configure the hibernate.cfg.xml
cd up again to /openmeetings-package/ run the red5.sh

that is all!

no copy of any dirs, no /etc/init.d/, ^^ In doubt see what is written down in here:http://code.google.com/p/openmeetings/wiki/InstallationOpenMeetings There is no mention of any init.d-script or other copy actions.


In this how-to I’m going to descript way to install OpenMeetings on debian GNU/Linux Etch (4.0), Steps are following way:

  • What we need!
  • Install MySQL
  • Install xvfb and OpenOffice.org
  • Install ImageMagic & !Ghostscript
  • Install SwfTools
  • Install Java and red5
  • Download openlazslo
  • Install OpenMeetings
  • Installing must new version?
  • Configure OpenMeetings and place files
  • Start every thing
  • !Troobleshooting
  • Author

What We Need

In this article I will use aptitude to install packages, if you don’t have apptitude please install it before going forward :

$su
#apt-get update
#apt-get install aptitude

After aptitude we need Debian GNU/Linux, I use version 4.0 (code name Etch), befor installing any thing else I recommend you to create a directory and manage every thing from there:

#su
#mkdir /root/tmpOpenMeetings/
#cd  /root/tmpOpenMeetings/

Install !MySQL

OpenMeetings can work with wide range of databases, I will install OpenMeetings with MySQL, to install !MySQL server:

aptitude install mysql-server

Add/edit the following lines to /etc/mysql/my.conf to enable localization:

[mysqld]
default-character-set=utf8
character-set-server=utf8

Install xvfb and OpenOffice

If you would like exchange Presentation and Office documentation in OpenMeetings, you will nedd xvfb and OpenOffice.org

#aptitude install xvfb  openoffice.org

Then edit Setup.xcu:

#vim  /usr/lib/openoffice/share/registry/data/org/openoffice/Setup.xcu

You should insert following lines after: <node oor:name=”Office”>:

    <prop oor:name=“ooSetupConnectionURL” oor:type=“xs:string”>
        <value>socket,host=localhost,port=8100;urp</value>
    </prop>

Install ImageMagick and Ghostscript

ImageMagick is a software suite for image manipulation and display, supporting close to 100 image formats. It is mainly used to perform various transformation and conversion operations on images and Ghostscript is a suite of software based on an interpreter for Adobe Systems’ PostScript and Portable Document Format (PDF) page description languages.

To install this tools run:

 #aptitude install imagemagick  gs-gpl

Install SWFTools

SWFTools s a collection of SWF manipulation and creation utilities written by Rainer Böhme and Matthias Kramm. It is released under the GPL.

#aptitude install swftools

If you get this message: “Couldn’t find any package whose name or description matched “swftools” ” please download swftools directly from web with running:

#wget   http://ftp.it.debian.org/debian/pool/main/s/swftools/swftools_0.8.1-1_i386.deb

befor installing this ackage should install “libart-2.0-2 ” so run:

#aptitude install libart-2.0-2

and now install SWFTools:

#dpkg -i swftools_0.8.1-1_i386.deb

Install Java and Red5

red5 is a Open Source Flash Server that OpenMeetings based on, so you should install it, and befor installing red5 should install Java Runtime Environment and Java development Kit run:

#aptitude install sun-java5-bin
#aptitude install  sun-java5-demo
#

If aptitude gives you any error, please download all file with wget and then install

#wget http://ftp.tr.debian.org/debian/pool/non-free/s/sun-java5/sun-java5-demo_1.5.0-13-1_i386.deb
#wget http://ftp.de.debian.org/debian/pool/non-free/s/sun-java5/sun-java5-jdk_1.5.0-14-1etch1_i386.deb
# wget http://ftp.de.debian.org/debian/pool/non-free/s/sun-java5/sun-java5-bin_1.5.0-15-1_i386.deb
#dpkg -i sun-java5-demo_1.5.0-13-1_i386.deb sun-java5-jdk_1.5.0-14-1etch1_i386.deb sun-java5-bin_1.5.0-15-1_i386.deb 

Now download red5 for Debian GNU/Linux and install it:

#wget http://dl.fancycode.com/red5/0.6.3/debian/red5_0.6.3-1_all.deb
#dpkg -i red5_0.6.3-1_all.deb

openlazslo

OpenLaszlo is an open source platform for the development and delivery of rich Internet applications. to installing it, run:

#wget http://download.openlaszlo.org/4.0.6/openlaszlo-4.0.6-unix.tar.gz
#tar -xvf openlaszlo-4.0.6-unix.tar.gz
#mv lps-4.0.6/ /opt/

Note: there is no need to install OpenLaszlo if you only use the application but don’t want to modify it.

Note: you might would like to have a look at this shell script to start/stop/restart/status, if yes you can use this how-to.

Installing OpenMeetings

Huraaa, making infrastructure is finished, now we are going to download latest OpenMeeting release and instaling it:

#wget http://openmeetings.googlecode.com/files/openmeetings051.zip
#unzip openmeetings051.zip

To installing OpenMeetings you should tell OM where is your DataBase server and as I use MySQL as my Server, steps are like this:

#cp openmeetings/conf/mysql_hibernate.cfg.xml openmeetings/conf/hibernate.cfg.xml

Now edit file and config your database:

#vim openmeetings/conf/hibernate.cfg.xml

Now change :

            <property name=“connection.username”><DB_USER></property>
            <property name=“connection.password”><DB_PASSWORD></property>
            <property name=“connection.url”>jdbc:mysql://<DB_HOST>/<DB_NAME></property>

For example my config look likes:

 <!– User  / Password –>
                <property name=“connection.username”>root</property>
                <property name=“connection.password”>dj76shwrsh16xsvak1</property>

                <!– Database Settings –>
                <property name=“connection.driver_class”>com.mysql.jdbc.Driver</property>
                <property name=“dialect”>org.hibernate.dialect.MySQLInnoDBDialect</property>
                <property name=“connection.url”>jdbc:mysql://localhost/openmeetings?useUnicode=true&amp;createDatabaseIfNotExist=true&amp;characterEncoding=utf-8</property>

Installing Must new Version?

If you would like get must new version, I mean the version is under development, you should get a Snapshot from current source code, to do this follow this steps, if you don’t like to have any thing more than OpenMeetings latest version or don’t know what’s snapshot, skip this step.

#aptitude install subversion

Get (checkout) OpenMeetings latest snapshot:

#svn checkout http://openmeetings.googlecode.com/svn/branches/dev/

I will rename dev to !OpenMeetingsFromSVN and then replace what updated in snapshot (from subversion) with what should be out of date in orginal openmeetings file downloaded from OpenMeetings and OpnLazslo:

# mv dev/ OpenMeetingsFromSVN
#cp -r OpenMeetingsFromSVN/laszlo/client/xmlcrm/videoconference/ /opt/lps-4.0.6/Server/lps-4.0.6/ 

Configure OpenMeetings

Now, first I update my language files:

#cp OpenMeetingsFromSVN/xmlcrm/java/webapp/openmeetings/languages/*  openmeetings/languages/.

Ok, It’s time to place my OpenMeting in red5 document root to serving:

#cp -r openmeetings/ /usr/lib/red5/webapps/

Start every thing

Now time to start every thing we installed, I will start OpenOffice.org at first and then OpenLazslo and will start red5 server:

#xvfb-run –server-args=’-screen 0 800×600x16′ -a /usr/lib/openoffice/program/soffice -headless -nologo -norestore & 
#export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun
#/opt/lps-4.0.6/Server/tomcat-5.0.24/bin/startup.sh
#/etc/init.d/red5 start

Instead of using a virtual frame buffer you may install and use a /etc/init.d/ooomeetings service.

The last part of instalation is web based, with your web browser (Firefox, Opera, IE, …) and servers IP address and port 5080 (default):

http://$YOUR_IP:5080/openmeetings/Install

For example: http://127.0.0.1:5080/openmeetings/Install

after putting information in forms, OpenMeetings will initialize a DataBase (based on information that we gived to him) and now you can access OpenMeetings first page at:

http://$YOUR_IP:8080/lps-4.0.6/videoconference/

For example: http://127.0.0.1:5080/openmeetings/

Congratulation, OpenMeetings is ready to use :)

Touble Shooting

If you get any message about locales or fonts, you can use :

#dpkg-reconfigure locales
#aptitude install xfonts-base

If you would like to change rtmp host, you can use:

vim  /opt/lps-4.0.6/Server/lps-4.0.6/videoconference/config.xml 
  • Comments Off

PG Map

  • Comments Off

Netcall Setup

TOT Netcall for Nokia Phone

  • Comments Off

Time

Mp3

Msn status

  • manon2029@hotmail.com is

Chat with Meeh

Donate

    If you find an article useful, then please make a donation.

หมวดหมู่

UserOnline

Counter

  • Visitors today: 16
  • Visitors yesterday: 60
  • Visitors per day: 49,753
  • Max. visitors per day: 579
  • Total page views: 598,581
  • Page views of this page: 49,753
  • Currently online: 2
  • Max. online: 192
  • Total visitors: 128,804
  • counterStatistics