14:05 Sunday, September 09 2012

running ttrss's update_daemon2.php as a daemon with systemd

I'm not sure if this will be useful to anyone else, but I just spent (or wasted) about 30 minutes figuring this out, and figured it might be useful to others. I use Tiny Tiny RSS(ttrss) to aggregate the (roughly) two dozen RSS feeds that I follow. ttrss is pretty damn awesome (it even has an android client). However, one of the long standing rough edges was the lack of a good means of invoking its update daemon. The current 'UpdatingFeeds' wiki page still recommends using start-stop-daemon (on Debian, which doesn't exist for RH/Fedora) or running inside screen (which is quite the ugly hack), I figured this would be a vast improvement. It should work on any Linux distro that uses systemd for managing services (Fedora, and I think SUSE). I'm not going to pretend like this is the most ideal way to set it up, but it works fine on my Fedora16 system (I had previously been running "update.php --feeds" via cron).

All of the following needs to be done as the root user. First, create /lib/systemd/system/ttrss-update.service with the following content:

[Unit] Description=ttrss update deamon After=syslog.target network.target remote-fs.target nss-lookup.target postgresql.service

[Service]
Type=simple
ExecStart=/usr/bin/php /var/www/html/tt-rss/update_daemon2.php &
ExecStop=/usr/bin/pkill -u apache php
User=apache

[Install]
WantedBy=multi-user.target
</code>

Note that you'll need to update the following in the above:

<li>

* the After= line to replace postgresql.service for the database with whatever you're using for the database (to mysql.service, or whatever its called on Fedora)

</li>
<li>

* the ExecStart= line to reflect the actual location of where you installed update_daemon2.php on your system

</li>
<li>

* the ExecStop= line to replace apache if you're not running your webserver as the apache user

</li>

Then add a symlink:

ln -s /lib/systemd/system/ttrss-update.service /etc/systemd/system/multi-user.target.wants/ttrss-update.service

Finally reload the daemon to pick up all the changes:

systemctl --system daemon-reload

Once all of that is done, you can start the daemon by running:

systemctl start ttrss-update.service

If everything went well, you should see at least two processes returned in the output from the following command:

ps auxww | grep update_daemon2 | grep -v grep

Things to improve:

<p>
<li>

* figure out how to make the daemon log its output somewhere (its ridiculously verbose, and all the output is getting dropped in /var/log/messages which is non-ideal)

</li>
<li>

* get log rotation working, so that you don't end up with one huge log

</li>
</p>