Console action

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:

<?php
    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:

<?php
    $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
System_Daemon examples (Previous) Troubleshooting (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.