0

I've below cron file

    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

    LOG_DIR=/var/log/myapp-services-cron
    MYAPP_SERVICES_DIR=/opt/myorg/apps/myapp-services

    * * * * * myappcron node $MYAPP_SERVICES_DIR/scripts/processor.js &>> $LOG_DIR/processor.log 2>&1

This is created by below rpm.spec file

    Summary: Utility for testing RPM creation
    Name: utils
    Version: 1.0.0
    Release: 1
    License: GPL
    URL: http://www.both.org
    Group: System
    Packager: Rajkumar Natarajan
    Requires: bash
    Requires: nodejs >= 8.1.2
    BuildRoot: ~/rpmbuild/

    %description
    A collection of utility scripts for testing RPM creation.


    %prep
    ################################################################################
    # Create the build tree and copy the files from the development directories    #
    # into the build tree.                                                         #
    ################################################################################
    echo "BUILDROOT = $RPM_BUILD_ROOT"


    %pre

    %build

    %install
    sudo mkdir -p /etc/cron.d
    sudo mkdir -p /var/log/myapp-services-cron
    sudo mkdir -p /var/lock/myapp-services-cron
    sudo mkdir -p /opt/myorg/apps/myapp-services
    sudo cp -r /home/vagrant/cron-demo %{buildroot}/
    sudo cp -r  %{buildroot}/cron-demo/crontab /etc/cron.d/myapp-services-cron-scripts
    sudo cp -r %{buildroot}/cron-demo/scripts /opt/myorg/apps/myapp-services/


    %post

    %files
    /cron-demo/

    %postun

    %clean
    sudo rm -rf %{buildroot}/

    %changelog

The cron file is invoking a nodejs script every single minute. But somehow the cron is not trigged.

OS details are -

$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.5.1804 (Core)
Release:    7.5.1804
Codename:   Core

I've user myappcron created. Nodejs and scripts/processor are also in correct location.

Any idea why the cron is not trigged?

1 Answer 1

3

You are confused about the meaning of the %install section.

The sections

  • %prep
  • %build
  • %install
  • %check

run on the machine where you build the rpm package, not on the machine where the rpm is installed. You should never use sudo inside your spec file. Probably you want something like this (I have only written the part concerning your cron.d file, you can extrapolate for the other files you need):

%install
mkdir -p %{buildroot}/etc/cron.d
cp -r /cron-demo/crontab %{buildroot}/etc/cron.d/myapp-services-cron-scripts

%files
/etc/cron.d/myapp-services-cron-scripts

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .