Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 564596 - net-misc/i2pd-0.10.0: logrotate script shouldn't start i2pd if it's stopped
Summary: net-misc/i2pd-0.10.0: logrotate script shouldn't start i2pd if it's stopped
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Francisco Blas Izquierdo Riera
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-01 02:31 UTC by Pavel Goran
Modified: 2016-03-19 16:28 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (emerge-info,7.97 KB, text/plain)
2015-11-01 02:31 UTC, Pavel Goran
Details
updated /etc/conf.d/i2pd (conf.d.i2pd,268 bytes, text/plain)
2016-03-09 13:36 UTC, Alexey Korepanov
Details
updated /etc/init.d/i2pd (init.d.i2pd,736 bytes, text/plain)
2016-03-09 13:37 UTC, Alexey Korepanov
Details
updated i2pd.service (i2pd.service,477 bytes, text/plain)
2016-03-09 13:42 UTC, Alexey Korepanov
Details
updated /etc/conf.d/i2pd (conf.d.i2pd,324 bytes, text/plain)
2016-03-10 13:55 UTC, Alexey Korepanov
Details
updated /etc/logrotate.d/i2pd (logrotate.i2pd,274 bytes, text/plain)
2016-03-10 13:57 UTC, Alexey Korepanov
Details
updated i2pd.service (i2pd.service,531 bytes, text/plain)
2016-03-10 14:15 UTC, Alexey Korepanov
Details
updated /etc/logrotate.d/i2pd (logrotate.i2pd,214 bytes, text/plain)
2016-03-13 10:36 UTC, Alexey Korepanov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Goran 2015-11-01 02:31:00 UTC
Created attachment 415844 [details]
emerge --info

The logrotate script that the package installs has the following in postrotate:

/etc/init.d/i2pd restart >/dev/null

This means that as logrotate processes this script, it (re)starts the i2pd daemon even if the admin didn't mean it to autostart (didn't add it to runlevels). This shouldn't happen; restart should only be done if the daemon is already running.
Comment 1 Alexey Korepanov 2016-03-08 10:35:10 UTC
The way i2pd is handling logrotate has changed in 2.5.0. Now logfile is reopened by SIGHUP, and there is no need to restart the daemon. See
https://github.com/PurpleI2P/i2pd/commit/98d5e0b56d321b72340212564a662aa2e6d6a06e

How should this be implemented properly in gentoo? There should be a PID somewhere to send the signal to, and this should work for both openrc and systemd.
Comment 2 Alexey Korepanov 2016-03-08 17:13:37 UTC
I did some search. It looks like the following should work for the i2pd.logrotate file for version >=2.5.0. This would close this bug, I suppose.

/var/log/i2pd.log {
        rotate 4
        weekly
        missingok
        notifempty
        compress
        delaycompress
        create 640 i2pd i2pd
        postrotate
                /usr/bin/killall -HUP i2pd
        endscript
}

Or maybe it is better to send a signal by PID?
kill -HUP $(cat /var/run/i2pd.pid)
Comment 3 Pavel Goran 2016-03-08 17:16:21 UTC
Sending a signal by PID would be definitely better.
Comment 4 Alexey Korepanov 2016-03-09 11:03:30 UTC
ok, so the logrotate file for version >=2.5.0 should be changed to

/var/log/i2pd.log {
        rotate 4
        weekly
        missingok
        notifempty
        compress
        delaycompress
        create 640 i2pd i2pd
        postrotate
                /bin/kill -HUP $(cat /var/run/i2pd.pid)
        endscript
}

currently both systemd and openrc scripts start i2pd to use /var/log/i2pd.log as a log file and /var/run/i2pd.pid as a PID file, so things look consistent
Comment 5 Anthony Basile gentoo-dev 2016-03-09 11:50:57 UTC
@maintainers, shall i commit?
Comment 6 Anthony Basile gentoo-dev 2016-03-09 11:51:39 UTC
(In reply to Alexey from comment #4)
> ok, so the logrotate file for version >=2.5.0 should be changed to
> 
> /var/log/i2pd.log {
>         rotate 4
>         weekly
>         missingok
>         notifempty
>         compress
>         delaycompress
>         create 640 i2pd i2pd
>         postrotate
>                 /bin/kill -HUP $(cat /var/run/i2pd.pid)
>         endscript
> }
> 
> currently both systemd and openrc scripts start i2pd to use
> /var/log/i2pd.log as a log file and /var/run/i2pd.pid as a PID file, so
> things look consistent

Have you tested this for a week or more?
Comment 7 Alexey Korepanov 2016-03-09 13:36:33 UTC
Created attachment 427808 [details]
updated /etc/conf.d/i2pd
Comment 8 Alexey Korepanov 2016-03-09 13:37:03 UTC
Created attachment 427810 [details]
updated /etc/init.d/i2pd
Comment 9 Alexey Korepanov 2016-03-09 13:38:24 UTC
I tried to test this, and it did not work, because no valid pid file was created. Solution would be change /etc/conf.d/i2pd by adding "--pidfile ${I2PD_PID}" to I2PDOPTIONS:

# cat /etc/conf.d/i2pd 
I2PD_USER="${I2PD_USER:-i2pd}"
I2PD_GROUP="${I2PD_GROUP:-i2pd}"
I2PD_LOG="/var/log/i2pd.log"
I2PD_PID="/var/run/i2pd.pid"
I2PD_CFGDIR="/etc/i2pd/"
# Options to i2pd
I2PDOPTIONS="--conf=${I2PD_CFGDIR}i2pd.conf --tunconf=${I2PD_CFGDIR}tunnels.cfg --pidfile ${I2PD_PID}"

I compared start scripts for i2p and i2pd, and saw that i2p checks if the pid file was created and there is a corresponding process. We could also do the same here (I added two lines starting with "sleep 1"):

# cat /etc/init.d/i2pd 
#!/sbin/runscript
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

description="C++ daemon for accessing the I2P network"

depend() {
	use dns logger netmount
}

start() {
        ebegin "Starting ${SVCNAME}"
        checkpath -f "${I2PD_LOG}" -o "${I2PD_USER}:${I2PD_GROUP}"
        checkpath -f "${I2PD_PID}" -o "${I2PD_USER}:${I2PD_GROUP}"
        start-stop-daemon -S -b -u "${I2PD_USER}:${I2PD_GROUP}" /usr/bin/i2pd -- ${I2PDOPTIONS}
        sleep 1
        [ -e "$I2PD_PID" -a -e /proc/$(cat "$I2PD_PID") ]
        eend $?
}

stop() {
        ebegin "Stopping ${SVCNAME}"
        start-stop-daemon -K -p "${I2PD_PID}" -R SIGTERM/20 SIGKILL/20 -P
        eend $?
}
Comment 10 Alexey Korepanov 2016-03-09 13:42:50 UTC
Created attachment 427812 [details]
updated i2pd.service
Comment 11 Alexey Korepanov 2016-03-09 13:47:40 UTC
So far, to fix the pid file creation problems, I made changes to /etc/init.d/i2pd, /etc/conf.d/i2pd and /usr/lib/systemd/system/i2pd.service. I am testing it currently on openrc. Things seem working, but let us wait a bit to see if any problems come up.

Would be good if somebody tested it on systemd, which I may not be able to do in the near future.
Comment 12 Alexey Korepanov 2016-03-10 13:55:58 UTC
Created attachment 427884 [details]
updated /etc/conf.d/i2pd

Updating again /etc/conf.d/i2pd.

There is another bug in i2pd: "service=1" in the configuration file is ignored, so "--service" has to be given in the command line. This option instructs the daemon to work system folders instead of like /home/user/.i2pd

(see https://github.com/PurpleI2P/i2pd/issues/408 )

I added some more options explicitly in /etc/conf.d/i2pd: daemon, service, log location.

On the original bug in this bug report: I tested logrotate, it rotates well.
Comment 13 Alexey Korepanov 2016-03-10 13:57:16 UTC
Created attachment 427886 [details]
updated /etc/logrotate.d/i2pd

This is /etc/logrotate.d/i2pd, as discussed above.
Comment 14 Alexey Korepanov 2016-03-10 14:15:47 UTC
Created attachment 427888 [details]
updated i2pd.service

this is an updated i2pd.service for systemd. I added explicitly options like in /etc/conf.d/i2pd above.

Tested this with systemd, it starts and seems working.
Comment 15 Anthony Basile gentoo-dev 2016-03-13 00:00:58 UTC
@klondike @tomboy64

comments on the above before i commit?
Comment 16 Alexey Korepanov 2016-03-13 10:36:51 UTC
Created attachment 428124 [details]
updated /etc/logrotate.d/i2pd

I have some minor comments. 

First, I found out by reading man logrotate that options compress, delaycompress and copytruncate in this case are no longer necessary in logrotate.d/i2pd. I removed them and tested for around 4 days, it seems to work just fine. I am replacing the attachment with logrotate.d/i2pd now.

Another thing that would be very helpful, especially for new users: i2pd sources come with a file debian/subscriptions.txt. It provides initial subscriptions to lists of available hosts. It is supposed to be in the data directory (/var/lib/i2pd/), but be user-editable, like files in /etc/i2pd. We don't use it currently. Can we place it in /etc/i2pd/ and add a symlink 
ln -s /etc/i2pd/subscriptions.txt /var/lib/i2pd/ 
? Just in case, I have tested this for a week.

One last thing: there is a release 2.5.1, which is a bugfix for 2.5.0, no significant changes :-)
Comment 17 Alexey Korepanov 2016-03-13 10:46:44 UTC
This bug discussion is getting long. To summarize, all my suggestions are:

* replace the files in attachments
* put debian/subscriptions.txt in /etc/i2pd/ and create a symlink
  ln -s /etc/i2pd/subscriptions.txt /var/lib/i2pd/
* when this is all done, create an identical ebuild for the bugfix version 2.5.1
Comment 18 Anthony Basile gentoo-dev 2016-03-13 12:00:58 UTC
(In reply to Alexey from comment #17)
> This bug discussion is getting long. To summarize, all my suggestions are:
> 
> * replace the files in attachments
> * put debian/subscriptions.txt in /etc/i2pd/ and create a symlink
>   ln -s /etc/i2pd/subscriptions.txt /var/lib/i2pd/
> * when this is all done, create an identical ebuild for the bugfix version
> 2.5.1

too long.  please give me just a commit against the gentoo repo.  break up each issue into a separate commit.
Comment 19 Alexey Korepanov 2016-03-13 20:01:30 UTC
Uh, it will take me some time to figure out how to create commits against gentoo repo. I tried to follow https://wiki.gentoo.org/wiki/Gentoo_git_workflow, but failed to even chekout the current repo. Maybe there is a guide for beginners?

I will describe the changes here once again, in case somebody else can create these commits.

There are three changes:
1) fix the bug in this bugreport:
   replace files /etc/init.d/i2pd, /etc/conf.d/i2pd, i2pd.service,
   /etc/logrotate.d/i2pd as in attachments in this bugreport

2) use supplied suscriptions.txt:
   place debian/subscriptions.txt in /etc/i2pd/ and create a symlink
   ln -s /etc/i2pd/subscriptions.txt /var/lib/i2pd/

3) bump to a bugfix version 2.5.1
   copy the ebuild for 2.5.0
Comment 20 Anthony Basile gentoo-dev 2016-03-13 20:04:22 UTC
(In reply to Alexey from comment #19)
> Uh, it will take me some time to figure out how to create commits against
> gentoo repo. I tried to follow
> https://wiki.gentoo.org/wiki/Gentoo_git_workflow, but failed to even chekout
> the current repo. Maybe there is a guide for beginners?
> 
> I will describe the changes here once again, in case somebody else can
> create these commits.
> 
> There are three changes:
> 1) fix the bug in this bugreport:
>    replace files /etc/init.d/i2pd, /etc/conf.d/i2pd, i2pd.service,
>    /etc/logrotate.d/i2pd as in attachments in this bugreport
> 
> 2) use supplied suscriptions.txt:
>    place debian/subscriptions.txt in /etc/i2pd/ and create a symlink
>    ln -s /etc/i2pd/subscriptions.txt /var/lib/i2pd/
> 
> 3) bump to a bugfix version 2.5.1
>    copy the ebuild for 2.5.0

yes you have too many things going on here for me to follow what you want me to do with the package.
Comment 21 Alexey Korepanov 2016-03-13 20:12:50 UTC
If you could fix issue 1), this would close this bug. This should be very straightforward.

Issues 2) and 3) are not from this bugreport, I could create two more bugs form them. They are also easy to solve.

I am unsure what to do, but I have reported the issues I found, how they are solved, and I tested solutions on my computer.
Comment 22 Alexey Korepanov 2016-03-13 20:52:00 UTC
I created a pull request on github for issue 1)
https://github.com/gentoo/gentoo/pull/1040

Is this OK? I am absolutely new to all this.
Comment 23 Anthony Basile gentoo-dev 2016-03-14 08:52:50 UTC
(In reply to Alexey from comment #22)
> I created a pull request on github for issue 1)
> https://github.com/gentoo/gentoo/pull/1040
> 
> Is this OK? I am absolutely new to all this.

being a n00b is fine :)

1) your commit message must always start with <cat>/<pkg> so I had to change one of the commit messages

2) don't make a separate commit for the manifest

3) use repoman to check your work and do commits, so 

   a) repoman -d full # to check that you didn't break anything
   b) repoman commit "net-misc/i2pd: fix bug #564596"


Take a look at commits

6bcc3054f2f5dcc1c7b09d3961f3b12b8009e2c0
a70d3a9b1bd76537607fb27662190cfbb7629f93
b9adf62fa6ddc431f6c7cd60a6383ad4cabf4959
Comment 24 Anthony Basile gentoo-dev 2016-03-14 09:00:40 UTC
@everyone please test, i'd like to drop

i2pd-0.10.0.ebuild
i2pd-2.4.0-r1.ebuild
i2pd-2.5.0.ebuild
i2pd-2.5.0-r1.ebuild

soon-ish like about 1 week.  can someone ping me back on this bug when they're convince i2pd-2.5.0-r2.ebuild  i2pd-2.5.1.ebuild  work just fine.

also is there a quickstart for i2pd?
Comment 25 Alexey Korepanov 2016-03-14 11:52:11 UTC
Ok, thanks a lot.

I still have to learn how to use repoman. But I will probably get there.

I made a blunder - having switched almost all files to their correct versions I missed the most important one: logrotate.

I created a new pull request:
https://github.com/gentoo/gentoo/pull/1045

There are quickstart guides for i2pd, for example
https://www.reddit.com/r/i2pd/comments/43f8dz/how_to_install_i2pd_tutorial_for_debianubuntu/
but they get obsolete very fast. In gentoo it is enough to start the service and point the browser to proxy on http://localhost:4444 (or whatever port is in the config file) to browse i2pd. And go to http://localhost:7070 for the web interface.
Comment 26 Anthony Basile gentoo-dev 2016-03-14 15:43:03 UTC
(In reply to Alexey Korepanov from comment #25)
> Ok, thanks a lot.
> 
> I still have to learn how to use repoman. But I will probably get there.
> 
> I made a blunder - having switched almost all files to their correct
> versions I missed the most important one: logrotate.
> 
> I created a new pull request:
> https://github.com/gentoo/gentoo/pull/1045
> 
> There are quickstart guides for i2pd, for example
> https://www.reddit.com/r/i2pd/comments/43f8dz/
> how_to_install_i2pd_tutorial_for_debianubuntu/
> but they get obsolete very fast. In gentoo it is enough to start the service
> and point the browser to proxy on http://localhost:4444 (or whatever port is
> in the config file) to browse i2pd. And go to http://localhost:7070 for the
> web interface.

fix committed.  i removed the older botched versions.
Comment 27 Anthony Basile gentoo-dev 2016-03-19 16:28:40 UTC
(In reply to Anthony Basile from comment #26)
> (In reply to Alexey Korepanov from comment #25)
> > Ok, thanks a lot.
> > 
> > I still have to learn how to use repoman. But I will probably get there.
> > 
> > I made a blunder - having switched almost all files to their correct
> > versions I missed the most important one: logrotate.
> > 
> > I created a new pull request:
> > https://github.com/gentoo/gentoo/pull/1045
> > 
> > There are quickstart guides for i2pd, for example
> > https://www.reddit.com/r/i2pd/comments/43f8dz/
> > how_to_install_i2pd_tutorial_for_debianubuntu/
> > but they get obsolete very fast. In gentoo it is enough to start the service
> > and point the browser to proxy on http://localhost:4444 (or whatever port is
> > in the config file) to browse i2pd. And go to http://localhost:7070 for the
> > web interface.
> 
> fix committed.  i removed the older botched versions.

i removed everything but  i2pd-2.5.0-r3  i2pd-2.5.1-r1.  open up a new bug if there's anything else wrong.