running update_daemon2.php as a daemon with systemd (Fedora)

Support requests, bug reports, etc. go here. Dedicated servers / VDS hosting only
netllama
Bear Rating Trainee
Bear Rating Trainee
Posts: 47
Joined: 27 Sep 2009, 19:31

running update_daemon2.php as a daemon with systemd (Fedora)

Postby netllama » 22 Sep 2012, 09:38

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. As 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:

Code: Select all

[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/ttrss/update_daemon2.php &
ExecStop=/usr/bin/pkill -u apache php
User=apache

[Install]
WantedBy=multi-user.target



Note that you'll need to update the following in the above:
    * 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)
    * the ExecStart= line to reflect the actual location of where you installed update_daemon2.php on your system
    * the ExecStop= line to replace apache if you're not running your webserver as the apache user

Then add a symlink:

Code: Select all

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:

Code: Select all

systemctl --system daemon-reload


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

Code: Select all

systemctl start ttrss-update.service


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

Code: Select all

ps auxww | grep update_daemon2 | grep -v grep



Things to improve:
    * 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)
    * get log rotation working, so that you don't end up with one huge log

Feedback, questions and comments welcome. I'd also be happy to update the wiki page ( http://tt-rss.org/redmine/projects/tt-r ... atingFeeds ) with the above info if someone thinks it would be beneficial.

spinlock
Bear Rating Trainee
Bear Rating Trainee
Posts: 1
Joined: 21 Mar 2013, 07:18

Re: running update_daemon2.php as a daemon with systemd (Fed

Postby spinlock » 21 Mar 2013, 07:29

Here is the version I came up with. Note that I am using MySQL instead of Postgresql.

/usr/lib/systemd/system/tt-rss.service

Code: Select all

[Unit]
Description=Tiny Tiny RSS feed updater
Requires=syslog.target network.target remote-fs.target nss-lookup.target mysqld.service


[Service]
PIDFile=/var/run/httpd/tt-rss.pid
WorkingDirectory=/usr/share/webapps/tiny-tiny-rss
ExecStart=/usr/share/webapps/tiny-tiny-rss/update.php -daemon
KillMode=process
User=http
Group=http
StandardOutput=null

[Install]
WantedBy=multi-user.target


/usr/lib/tmpfiles.d/tt-rss.conf

Code: Select all

d /var/run/tt-rss 0700 http http -

miceliux
Bear Rating Trainee
Bear Rating Trainee
Posts: 4
Joined: 15 Mar 2013, 15:41

Re: running update_daemon2.php as a daemon with systemd (Fed

Postby miceliux » 22 Mar 2013, 14:37

netllama wrote:Then add a symlink:

Code: Select all

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



For enabling the service, just use:

Code: Select all

systemctl enable ttrss-update.service


I paste my service file here for reference:

Code: Select all

[Unit]
Description=Tiny Tiny RSS update daemon
After=network.target mysqld.service
Requires=mysqld.service

[Service]
User=apache
Group=apache
WorkingDirectory=/var/www/ttrss
Type=simple
StandardOutput=null
StandardError=syslog
ExecStart=/usr/bin/php ./update_daemon2.php
PrivateTmp=true
InaccessibleDirectories=/home /root /boot /opt /mnt /media
ReadOnlyDirectories=/etc /usr

[Install]
WantedBy=multi-user.target

etu
Bear Rating Trainee
Bear Rating Trainee
Posts: 4
Joined: 15 Jun 2015, 14:59

Re: running update_daemon2.php as a daemon with systemd (Fed

Postby etu » 16 Jun 2015, 12:40

I've came up with this one.

Only way it's probably make any notable changes from the others in this thread is the restart line, to restart the process if it happens to die.

Then I don't see the point of fiddling around with KillProcess stuff, or forking, systemd doesn't like forking processes, it's better if it just runs up front, then systemd knows the pid and kan kill it properly.

Code: Select all

[Unit]
Description=ttrss update deamon
After=syslog.target network.target postgresql-9.4.service

[Service]
User=ttrss
Group=ttrss
Type=simple
ExecStart=/usr/bin/php /srv/http/ttrss/update_daemon2.php
WorkingDirectory=/srv/http/ttrss/
Restart=on-failure
PrivateTmp=true
InaccessibleDirectories=/home /root /boot /opt /mnt /media

[Install]
WantedBy=multi-user.target

miceliux
Bear Rating Trainee
Bear Rating Trainee
Posts: 4
Joined: 15 Mar 2013, 15:41

Re: running update_daemon2.php as a daemon with systemd (Fed

Postby miceliux » 17 Jun 2015, 14:52

Here is my service unit for Fedora 22:

Code: Select all

[Unit]
Description=Tiny Tiny RSS Update daemon
After=network-online.target
After=mariadb.service
Requires=network-online.target
Requires=mariadb.service

[Service]
Type=simple
User=apache
Group=apache
WorkingDirectory=/var/www/ttrss
ExecStart=/usr/bin/php /var/www/ttrss/update_daemon2.php
ProtectSystem=full
ProtectHome=true
Nice=19
StandardOutput=null
StandardError=journal
PrivateTmp=true
PrivateDevices=true
NoNewPrivileges=true
Restart=always

[Install]
WantedBy=multi-user.target


Return to “Support”

Who is online

Users browsing this forum: No registered users and 5 guests