Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 269884 - sys-process/anacron: init.d: add stop function
Summary: sys-process/anacron: init.d: add stop function
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: No maintainer - Look at https://wiki.gentoo.org/wiki/Project:Proxy_Maintainers if you want to take care of it
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-14 21:13 UTC by mephinet
Modified: 2019-03-29 13:06 UTC (History)
2 users (show)

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


Attachments
/etc/init.d/anacron (anacron,567 bytes, text/plain)
2011-12-05 06:49 UTC, Roger
Details
anacron.patch (anacron.patch,500 bytes, text/plain)
2011-12-05 06:51 UTC, Roger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mephinet 2009-05-14 21:13:22 UTC
For quite some time I've been wandering what drains my notebook's battery so fast when I boot without AC. I've installed app-laptop/laptop-mode-tools-1.31 and it's configured to stop (among others) vixie-cron and anacron when not on AC in order to save power. Still, a few minutes after system start, I have emerge sync running, as well as updatedb, and some other IO-hungry cronjobs.

What I now realized is that in the current service start order, the crons are started before laptop-mode is initialized. As soon as laptop-mode is started, it stops all configured services - but /etc/init.d/anacron does not implement a stop function, so it continues to run even when rc-status reports it as stopped.

I therefore request the stop function to be implemented for anacron. I guess that a "pidof anacron && killall anacron" would be the right thing to do here, but you might find a cleaner solution that I currently cannot think of. In an ideal world, I guess anacron should feature some command line switch to request running processes to be stopped...
Comment 1 Richard Li 2009-11-02 12:10:05 UTC
It's not a bug. /etc/init.d/anacron simply runs "anacron -s" at startup. Anacron is not a daemon. It exits very quickly, as soon as it has done its jobs.

(In reply to comment #0)
> For quite some time I've been wandering what drains my notebook's battery so
> fast when I boot without AC. I've installed app-laptop/laptop-mode-tools-1.31
> and it's configured to stop (among others) vixie-cron and anacron when not on
> AC in order to save power. Still, a few minutes after system start, I have
> emerge sync running, as well as updatedb, and some other IO-hungry cronjobs.
> 
> What I now realized is that in the current service start order, the crons are
> started before laptop-mode is initialized. As soon as laptop-mode is started,
> it stops all configured services - but /etc/init.d/anacron does not implement a
> stop function, so it continues to run even when rc-status reports it as
> stopped.
> 
> I therefore request the stop function to be implemented for anacron. I guess
> that a "pidof anacron && killall anacron" would be the right thing to do here,
> but you might find a cleaner solution that I currently cannot think of. In an
> ideal world, I guess anacron should feature some command line switch to request
> running processes to be stopped...
> 

Comment 2 Roger 2011-12-05 06:41:17 UTC
I don't think anacron without rc-service stop is proper at all.

So many times, realizing I had some task to do and required to stop vixie-cron and anacron to prevent running a weekly sync, I've been caught with my pants down after seeing anacron still working in the background and going ahead with the sync even though I stopped vixie-cron & anacron!!!

I believe /etc/init.d/anacron is missing the following:

#start() {
#   ebegin "Running anacron"
#   /usr/sbin/anacron -s >>/var/log/cron.log 2>&1
#   eend $?
#}
  
start() {
    ebegin "Starting ${RC_SVCNAME}"
    start-stop-daemon --start --pidfile ${pid_file} \
        --exec /usr/sbin/anacron \
        -- -s 
    eend ${?}
}
  
stop() {
    ebegin "Stopping ${RC_SVCNAME}"
    start-stop-daemon --stop --quiet --exec /usr/sbin/anacron
    eend ${?}
}

The commented-out section is the original, the rest is new.  I merrily used /etc/init.d/fetchmail as a template, ignoring fetchmail options.

I've tested the above just before my weekly sync today and it works like a charm!  Anacron now stops and removes it's anacron -s process preventing any background scheduled events as one would expect when doing /etc/init.d/anacron stop.
Comment 3 Roger 2011-12-05 06:49:06 UTC
Created attachment 294829 [details]
/etc/init.d/anacron

Modified /etc/init.d/anacron with stop service implemented and successfully tested here.
Comment 4 Roger 2011-12-05 06:51:34 UTC
Created attachment 294831 [details]
anacron.patch

Patches or shows diff between original /etc/init.d/anacron.orig and /etc/init.d/anacron after my changes.

I suggest bumping the -r version so existing users can take advantage of the modifications. (ie. current =sys-process/anacron-2.3-r2, after this modification =sys-process/anacron-2.3-r3)
Comment 5 Roger 2011-12-05 17:32:58 UTC
oops. My patch causing anacron to register to as crashed with openrc-0.9.4

This needs some work, as I merrily quickly hacked something together here that just worked to stop the persistent anacron -s process, as a init.d script should do.
Comment 6 Roger 2011-12-05 17:52:33 UTC
Ah found it.  Right after anacron is started and detects no out-dated cron tasks and exits peacefully, the start-stop-daemon function within my anacron init.d script detects this as a crash -- when in essence anacron is working as expected.

Hence, the reason we likely don't have a stop processes, because start-stop-daemon doesn't play nice with processes exiting?

Anyways, don't have anymore time right now to debug/research as I've got another task running on this box.  If somebody knows the work around, feel free to  post it.
Comment 7 SpanKY gentoo-dev 2015-08-10 08:06:10 UTC
anacron, by design, is a one-shot process.  that is why there is no stop function: the daemon launches, executes what it needs to, and then exits.

adding a stop function to halt the one-time process would be useful in some cases, but it would not be the normal use.  due to openrc's integration with the s-s-d, we can't easily leverage that.  i think what you'd have to do is:
 - launch it via s-s-d to record the pid
 - read the pid and save it into a variable
 - delete the pid
 - use that variable in stop() to kill the daemon (if it's still running), but paired up with s-s-d so as to include the other various sanity checks

when i refer to a variable, see the `save_options` and `get_options` functions that openrc provides.  that's how you can pass state between start/stop.
Comment 8 Roger 2015-08-11 03:27:06 UTC
Since 2011, I've learnt to deal with the grievance of this bug.

Just haven't had enough time since to further research how to optimize any better solutions.  So much Python, ahem bugs, so little time.