Get the most out of your Centmin Mod LEMP stack
Become a Member

Automatic nightly YUM updates with yum-cron for CentOS 7 Only

Discussion in 'System Administration' started by eva2000, Sep 28, 2014.

  1. pamamolf

    pamamolf Premium Member Premium Member

    4,071
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    8:53 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    I mean i configure it at 00:30 to run every hour by editing the /etc/yum/yum-cron-hourly.conf and not set it to run at 00:30 if i confuse you....

    Ok this is what i did just to get a notification for updates on every hour check without downloading/installing anything:


    Code:
    yum -y install yum-cron
    systemctl enable yum-cron.service
    /bin/systemctl start  yum-cron.service
    nano /etc/yum/yum-cron-hourly.conf

    Code:
    update_messages = yes
    download_updates = no
    apply_updates = no
    system_name = Server5
    emit_via = email
    email_to = myemail@gmail.com

    /bin/systemctl restart yum-cron.service

    Yes i think also that is not running :(

    Is there any other way to check that is running ?

    I just test sending mail from ssh to be sure that there is no problem with my vps and is sending fine.
     
    Last edited: Sep 29, 2015
  2. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    4:53 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    tail cron log for cron.hourly
    Code:
     tail -500 /var/log/cron | grep '\/etc\/cron.hourly'
    Sep 28 11:01:01 centos7 CROND[30939]: (root) CMD (run-parts /etc/cron.hourly)
    Sep 28 11:01:01 centos7 run-parts(/etc/cron.hourly)[30939]: starting 0anacron
    Sep 28 11:01:01 centos7 run-parts(/etc/cron.hourly)[30948]: finished 0anacron
    Sep 28 11:01:01 centos7 run-parts(/etc/cron.hourly)[30939]: starting 0yum-hourly.cron
    Sep 28 11:01:23 centos7 run-parts(/etc/cron.hourly)[30982]: finished 0yum-hourly.cron
    then check if finished for 0yum-hourly.cron which is /etc/cron.hourly/0yum-hourly.cron
    Code:
    #!/bin/bash
    
    # Only run if this flag is set. The flag is created by the yum-cron init
    # script when the service is started -- this allows one to use chkconfig and
    # the standard "service stop|start" commands to enable or disable yum-cron.
    if [[ ! -f /var/lock/subsys/yum-cron ]]; then
      exit 0
    fi
    
    # Action!
    exec /usr/sbin/yum-cron /etc/yum/yum-cron-hourly.conf
    
    that runs
    Code:
    exec /usr/sbin/yum-cron /etc/yum/yum-cron-hourly.conf
    of course if you have no updates = no notifications
     
  3. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    4:53 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    check spam/junk folder too
     
  4. pamamolf

    pamamolf Premium Member Premium Member

    4,071
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    8:53 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Code:
    Sep 28 21:01:01 vultr run-parts(/etc/cron.hourly)[27391]: finished 0yum-hourly.cron
    Sep 28 22:01:01 vultr CROND[7125]: (root) CMD (run-parts /etc/cron.hourly)
    Sep 28 22:01:01 vultr run-parts(/etc/cron.hourly)[7125]: starting 0anacron
    Sep 28 22:01:01 vultr run-parts(/etc/cron.hourly)[7134]: finished 0anacron
    Sep 28 22:01:01 vultr run-parts(/etc/cron.hourly)[7125]: starting 0yum-hourly.cron
    Sep 28 22:14:29 vultr run-parts(/etc/cron.hourly)[9760]: finished 0yum-hourly.cron
    [root@vultr ~]# date
    Mon Sep 28 22:28:54 UTC 2015
    spam junk folder empty .....

    I didn't understant what you mean with:

    Copy the codde to .sh file and chmod +x and run it?

    I try to run manually this but nothing:

    Code:
    [root@vultr ~]# exec /usr/sbin/yum-cron /etc/yum/yum-cron-hourly.conf
    
    
    and there are updates:

    Code:
    [root@vultr ~]# yum upgrade
    Loaded plugins: fastestmirror, priorities
    Loading mirror speeds from cached hostfile
    * base: centos.mirror.fr.planethoster.net
    * epel: fedora.cu.be
    * extras: centos.quelquesmots.fr
    * rpmforge: mirror.ate.info
    * updates: centos.mirror.fr.planethoster.net
    153 packages excluded due to repository priority protections
    Resolving Dependencies
    --> Running transaction check
    ---> Package grub2.x86_64 1:2.02-0.17.el7_1.4 will be updated
    ---> Package grub2.x86_64 1:2.02-0.17.0.1.el7.centos.4 will be an update
    ---> Package grub2-tools.x86_64 1:2.02-0.17.el7_1.4 will be updated
    ---> Package grub2-tools.x86_64 1:2.02-0.17.0.1.el7.centos.4 will be an update
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==============================================================================================================================================
    Package                        Arch                      Version                                            Repository                  Size
    ==============================================================================================================================================
    Updating:
    grub2                          x86_64                    1:2.02-0.17.0.1.el7.centos.4                       updates                    1.5 M
    grub2-tools                    x86_64                    1:2.02-0.17.0.1.el7.centos.4                       updates                    3.3 M
    
    Transaction Summary
    ==============================================================================================================================================
    Upgrade  2 Packages
    
    Total download size: 4.7 M
     
  5. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    4:53 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    log tailed shows
    Code:
    Sep 28 22:14:29 vultr run-parts(/etc/cron.hourly)[9760]: finished 0yum-hourly.cron
    means hourly 0yum-hourly.cron finished
     
  6. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    4:53 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    because of random_sleep setting
    Code:
    # Maximum amout of time to randomly sleep, in minutes.  The program
    # will sleep for a random amount of time between 0 and random_sleep
    # minutes before running.  This is useful for e.g. staggering the
    # times that multiple systems will access update servers.  If
    # random_sleep is 0 or negative, the program will run immediately.
    random_sleep = 15
     
  7. pamamolf

    pamamolf Premium Member Premium Member

    4,071
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    8:53 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Ok i think i found the problem let's wait a few minutes to be here 02:00 and see :)

    I will wait also the 15 minutes for random_sleep....
     
    Last edited: Sep 29, 2015
  8. pamamolf

    pamamolf Premium Member Premium Member

    4,071
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    8:53 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    Yup working now as i had a typo on my yum-cron-hourly.conf file :)

    Thanks !!!!!
     
  9. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    4:53 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Great :)
     
  10. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    2:53 AM
    Mainline
    10.2
    Thanks a lot for the sed command, that was so hard :D
     
  11. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    2:53 AM
    Mainline
    10.2
  12. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    4:53 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  13. rdan

    rdan Well-Known Member

    5,439
    1,399
    113
    May 25, 2014
    Ratings:
    +2,188
    Local Time:
    2:53 AM
    Mainline
    10.2
    So to update mine?
    Code:
    sed -i 's|^update_cmd = security|update_cmd = default|' /etc/yum/yum-cron-hourly.conf
    egrep '^update_cmd' /etc/yum/yum-cron-hourly.conf
    service yum-cron restart
     
  14. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    4:53 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    yup
     
  15. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    4:53 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    FYI, just a heads up I am working on my own centmin mod specific yumupdates.sh script based on code from yum-cron to take into account variable 3rd party yum repos centmin mod uses Third Party YUM Repos with Centmin Mod - CentminMod.com LEMP Nginx web stack for CentOS :)

    sample email notification when there's updates
    Code:
    Mon Jan 18 14:28:32 UTC 2016
    New updates available for host domain.com
    Loaded plugins: fastestmirror, priorities, security
    1702 packages excluded due to repository priority protections
    
    remi-release.noarch                     6.6-2.el6.remi                      remi
     
    Last edited: Jan 19, 2016
  16. BobbyWibowo

    BobbyWibowo Active Member

    197
    42
    28
    Jul 30, 2015
    Indonesia
    Ratings:
    +71
    Local Time:
    1:53 AM
    1.17.x
    10.3.x
    Still broken?
     
  17. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    4:53 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    should be
     
  18. BobbyWibowo

    BobbyWibowo Active Member

    197
    42
    28
    Jul 30, 2015
    Indonesia
    Ratings:
    +71
    Local Time:
    1:53 AM
    1.17.x
    10.3.x
    Oh well, I'll just disable the nightly update, and set the hourly update to update anything o_O
     
  19. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    4:53 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  20. pamamolf

    pamamolf Premium Member Premium Member

    4,071
    427
    83
    May 31, 2014
    Ratings:
    +833
    Local Time:
    8:53 PM
    Nginx-1.25.x
    MariaDB 10.3.x
    As an option ?

    Easy to enable/disable ?