Table of Contents

Application

I wanted to have a web application through which I can access my sockets through a computer or iPad. The following components make this possible:

Custom PHP code

SQLite3 library

Daemon

First, develop and trouble shoot the daemon binary.

Check the daemon

Start the daemon, then find it's process id (pid):

$ ps -ax | grep <daemon>

Find all open files:

# lsof -p <pid>

Create the init script

On Debian systems, copy the skeleton file and modify to your needs. This is quite simple and straight forward.

# cp /etc/init.d/skeleton ~/scripts/<daemon>
# vim <daemon>

Install the daemon

Copy the binary file:

# cp ~/binaries/<daemon> /usr/sbin

Copy the script:

# cp ~/scripts/<daemon> /etc/init.d

Add the daemon to the different run-levels:

# update-rc.d <daemon> defaults

Remove the daemon from the different run-levels:

# update-rc.d -f <daemon> remove

See Daemon and LSBInitScripts for more details.

Cron

Run

 crontab -e

and enter the following lines:

*/5 * * * * wget http://localhost/path/to/web/code/state-machine.php
* 14 * * * wget http://localhost/path/to/web/code/randomize.php

The first line will run the state machine every 5 minutes. The second line will randomize your on / off pattern every day at 14:00.