Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Daily portage update via vixie-cron
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
ShiroiKuma
n00b
n00b


Joined: 09 Nov 2012
Posts: 38
Location: Japan

PostPosted: Sun Feb 17, 2013 2:24 pm    Post subject: [SOLVED] Daily portage update via vixie-cron Reply with quote

I'm currently trying to work out vixie-cron on my system and a little confused by it, I have Gentoo sitting in a small VM on my desktop, and I'd like it to update portage once a day, preferably just after booting up. (Following on from that, the rest of my network can sync against this local portage).

I've added a new file to /etc/cron.daily that is executable (chmod +x) called portage. It looks like
Code:
#! /bin/sh
# Portage Tree Update
exec /usr/bin/nice /usr/bin/emerge --sync
echo "$(date)" > /portage


And if I run it manually, it syncs my tree and timestamps the file /portage.

However vixie-cron doesn't appear to be calling it. It's been over 2 days now, and still doesn't run. I have to run this file manually myself.

My /etc/crontab looks like
Code:
# for vixie cron
#
# $Header: /var/cvsroot/gentoo-x86/sys-process/vixie-cron/files/crontab-3.0.1-r4,v 1.3 2011/09/20 15:13:51 idl0r Exp $
#
#

# Global variables
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# check scripts in cron.hourly, cron.daily, cron.weekly and cron.monthly
59 *  * * *     root    rm -f /var/spool/cron/lastrun/cron.hourly
30 9  * * *     root    rm -f /var/spool/cron/lastrun/cron.daily
19 4  * * 6     root    rm -f /var/spool/cron/lastrun/cron.weekly
29 5  1 * *     root    rm -f /var/spool/cron/lastrun/cron.monthly
*/10  *  * * *  root    test -x /usr/sbin/run-crons && /usr/sbin/run-crons


I assumed that after vixie-cron starts up (it's added to default runlevel), that it either 1) if started before 9:30am, it'll wait until 9:30am and then run it and 2) if started after 9:30am and the lastrun is over 24hrs ago, it'll run immediately.

I've checked /var/log/cron.log and no errors are reported, my ~/dead.letters file is empty. The timestamp on the file /var/spool/cron/lastrun/cron.daily is current 50hrs or so ago.

Based on the documentation I've read, this should be working as I expect it to work, but clearly I've misunderstood something somewhere (or read the wrong document, that's always a possibility).

Is there a way to check when cron.daily 1) last ran, and 2) will next run?


Last edited by ShiroiKuma on Mon Feb 18, 2013 12:56 pm; edited 1 time in total
Back to top
View user's profile Send private message
lexflex
Apprentice
Apprentice


Joined: 05 Mar 2006
Posts: 256
Location: the Netherlands

PostPosted: Sun Feb 17, 2013 6:32 pm    Post subject: Re: Daily portage update via vixie-cron Reply with quote

Hi,


ShiroiKuma wrote:

I assumed that after vixie-cron starts up (it's added to default runlevel),

You can check if a service is actually started ( and has not crashed ) using:
Code:
 /etc/init.d/vixie-cron status


You post the entries of /etc/crontab. but what does the actual entry that refers to your scripts looks like?
Usually the actual entries are eddited using :
Code:
crontab -e
Back to top
View user's profile Send private message
ShiroiKuma
n00b
n00b


Joined: 09 Nov 2012
Posts: 38
Location: Japan

PostPosted: Mon Feb 18, 2013 1:12 am    Post subject: Reply with quote

When using
Code:
crontab -e
as root, I get a completely blank nano session opening up looking at /tmp/crontab.XXXXNgDggo

If I look in /etc/cron.daily/ I saw (on a default install with mlocate emerged too) 2 files
Quote:

/etc/cron.daily/makewhatis
/etc/cron.daily/mlocate


Which based on Chapter 4 of the Cron Guide http://www.gentoo.org/doc/en/cron-guide.xml#doc_chap4 is expected and is also a reliable way to do this.

Quote:

    */15 * * * * test -x /usr/sbin/run-crons && /usr/sbin/run-crons
    0 * * * * rm -f /var/spool/cron/lastrun/cron.hourly
    0 3 * * * rm -f /var/spool/cron/lastrun/cron.daily
    15 4 * * 6 rm -f /var/spool/cron/lastrun/cron.weekly
    30 5 1 * * rm -f /var/spool/cron/lastrun/cron.monthly


To avoid going into much detail, we can just assume that these commands will effectively run your hourly, daily, weekly and monthly scripts. This method of scheduling cron-jobs has some important advantages:

* They will run even if your computer was off when they were scheduled to run
* It is easy for package maintainers to place scripts in those well defined places
* You know exactly where your cron-jobs and your crontab are stored, making it easy for you to backup and restore this part of your system


That's where I got the idea from that I can put a script into the cron.daily folder. I'm now even more confused, are these system installed ones even running at all then?

EDIT I think this might be due to vixie-cron, as that is designed for continuously running systems apparently. So fcron may be a better choice for a VM/Desktop/Laptop etc
Quote:
Designed to work on systems that are not continuously running, i.e. it can run a job after restarting if it was missed
Back to top
View user's profile Send private message
BillWho
Veteran
Veteran


Joined: 03 Mar 2012
Posts: 1600
Location: US

PostPosted: Mon Feb 18, 2013 5:00 am    Post subject: Reply with quote

ShiroiKuma wrote:
I have Gentoo sitting in a small VM on my desktop, and I'd like it to update portage once a day, preferably just after booting up

An alternative to a cron job would be to place your script in /etc/local.d to run at boot time. You would just have to have the suffix .start as part of the script name.

Also, you might want to add a sleep time, say 60 seconds or so at the start of the script.
_________________
Good luck :wink:

Since installing gentoo, my life has become one long emerge :)
Back to top
View user's profile Send private message
lexflex
Apprentice
Apprentice


Joined: 05 Mar 2006
Posts: 256
Location: the Netherlands

PostPosted: Mon Feb 18, 2013 8:55 am    Post subject: Reply with quote

ShiroiKuma wrote:
When using
Code:
crontab -e
as root, I get a completely blank nano session
That's where I got the idea from that I can put a script into the cron.daily folder. I'm now even more confused, are these system installed ones even running at all then?


The "regular"way to add a job is to use crontab -e...

Quote:

EDIT I think this might be due to vixie-cron, as that is designed for continuously running systems apparently. So fcron may be a better choice for a VM/Desktop/Laptop etc
Quote:
Designed to work on systems that are not continuously running, i.e. it can run a job after restarting if it was missed


Indeed, the system should be running at the time the job is supposed to run...

Maybe do as Bill says, and add it to the startup-script when booting.
BillWho wrote:
An alternative to a cron job would be to place your script in /etc/local.d to run at boot time. You would just have to have the suffix .start as part of the script name..


(however, since you use a VM, you might not actually reboot the VM every time you start it....)

Alex.
Back to top
View user's profile Send private message
ShiroiKuma
n00b
n00b


Joined: 09 Nov 2012
Posts: 38
Location: Japan

PostPosted: Mon Feb 18, 2013 10:39 am    Post subject: Reply with quote

Thanks for the answers so far, I would like to get a cron system working, it'd be good to learn and handy for the future too.

I removed vixie-cron and emerge fcron. I then used fcrontab -e to create a quick script to write to /fcrontest every minute. However this doesn't appear to be working either.

Looking at /var/log/cron.log I can see several ENTRYPOINT errors which leads me to believe my issue is actually down to using an SELinux kernel.

Code:
Feb 18 19:32:29 gan fcrontab[2525]: fcrontab : editing root's fcrontab
Feb 18 19:32:34 gan fcron[2208]: updating configuration from /var/spool/fcron
Feb 18 19:32:34 gan fcron[2208]: adding new file root
Feb 18 19:32:34 gan fcron[2208]: ENTRYPOINT FAILED for user "root" (CONTEXT root:sysadm_r:sysadm_t) for file CONTEXT root:object_r:user_cron_spool_t
Feb 18 19:32:34 gan fcron[2208]: adding new file systab
Feb 18 19:32:34 gan fcron[2208]: ENTRYPOINT FAILED for user "systab" (CONTEXT system_u:system_r:netutils_t) for file CONTEXT system_u:object_r:system_cron_spool_t


EDIT Yup definitely SELinux... my avc.log (grep fcron) shows lots of denies (the time diff is because I restarted the service)

Code:
Feb 18 19:32:29 gan kernel: [  113.319565] type=1400 audit(1361183549.903:215): avc:  denied  { lock } for  pid=2525 comm="fcrontab" path="/run/utmp" dev="tmpfs" ino=614 scontext=root:sysadm_r:admin_crontab_t tcontext=system_u:object_r:file_t tclass=file
Feb 18 19:32:34 gan kernel: [  117.477818] type=1400 audit(1361183554.063:216): avc:  denied  { fsetid } for  pid=2525 comm="fcrontab" capability=4  scontext=root:sysadm_r:admin_crontab_t tcontext=root:sysadm_r:admin_crontab_t tclass=capability
Feb 18 19:32:34 gan kernel: [  117.480438] type=1400 audit(1361183554.066:217): avc:  denied  { setfscreate } for  pid=2525 comm="fcrontab" scontext=root:sysadm_r:admin_crontab_t tcontext=root:sysadm_r:admin_crontab_t tclass=process
Feb 18 19:32:34 gan kernel: [  117.508115] type=1400 audit(1361183554.093:218): avc:  denied  { getattr } for  pid=2528 comm="fcronsighup" path="/run/fcron.pid" dev="tmpfs" ino=5932 scontext=root:sysadm_r:admin_crontab_t tcontext=system_u:object_r:file_t tclass=file
Feb 18 19:32:34 gan kernel: [  117.508303] type=1400 audit(1361183554.093:219): avc:  denied  { signal } for  pid=2528 comm="fcronsighup" scontext=root:sysadm_r:admin_crontab_t tcontext=system_u:system_r:initrc_t tclass=process
Feb 18 19:32:34 gan kernel: [  117.508640] type=1400 audit(1361183554.093:220): avc:  denied  { read } for  pid=2208 comm="fcron" name="new.root" dev="sda3" ino=131590 scontext=system_u:system_r:initrc_t tcontext=root:object_r:user_cron_spool_t tclass=file
Feb 18 19:40:41 gan kernel: [  604.948697] type=1400 audit(1361184041.676:280): avc:  denied  { create } for  pid=2598 comm="rc" name="fcron" scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:file_t tclass=lnk_file
Feb 18 19:40:41 gan kernel: [  605.076773] type=1400 audit(1361184041.803:281): avc:  denied  { create } for  pid=2617 comm="rc" name="fcron" scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:file_t tclass=dir
Feb 18 19:40:41 gan kernel: [  605.076807] type=1400 audit(1361184041.803:282): avc:  denied  { create } for  pid=2619 comm="fcron" name="fcron.fifo" scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:file_t tclass=sock_file
Feb 18 19:40:41 gan kernel: [  605.076818] type=1400 audit(1361184041.803:283): avc:  denied  { setattr } for  pid=2619 comm="fcron" name="fcron.fifo" dev="tmpfs" ino=2895 scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:file_t tclass=sock_file
Feb 18 19:40:41 gan kernel: [  605.076953] type=1400 audit(1361184041.803:284): avc:  denied  { read } for  pid=2619 comm="fcron" name="new.root" dev="sda3" ino=131590 scontext=system_u:system_r:initrc_t tcontext=root:object_r:user_cron_spool_t tclass=file
Feb 18 19:40:41 gan kernel: [  605.076965] type=1400 audit(1361184041.803:285): avc:  denied  { open } for  pid=2619 comm="fcron" path="/var/spool/fcron/new.root" dev="sda3" ino=131590 scontext=system_u:system_r:initrc_t tcontext=root:object_r:user_cron_spool_t tclass=file
Feb 18 19:40:41 gan kernel: [  605.077051] type=1400 audit(1361184041.803:286): avc:  denied  { write } for  pid=2619 comm="fcron" name="user" dev="selinuxfs" ino=9 scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:security_t tclass=file
Feb 18 19:40:41 gan kernel: [  605.077075] type=1400 audit(1361184041.803:287): avc:  denied  { compute_user } for  pid=2619 comm="fcron" scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:security_t tclass=security
Feb 18 19:40:41 gan kernel: [  605.078114] type=1400 audit(1361184041.806:288): avc:  denied  { check_context } for  pid=2619 comm="fcron" scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:security_t tclass=security
Feb 18 19:40:41 gan kernel: [  605.078133] type=1400 audit(1361184041.806:289): avc:  denied  { compute_av } for  pid=2619 comm="fcron" scontext=system_u:system_r:initrc_t tcontext=system_u:object_r:security_t tclass=security


EDIT: Thanks to @SwiftT's help in #gentoo I was able to fix the problem by setting the following
Code:
setsebool fcron_crond 1
setsebool cron_userdomain_transition 1


Atleast, this works for root, still an error for systab but probably something similar to fix.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum