Systemd, Debian and former cron jobs

Discussion in 'Hosting Talk & Reviews' started by drmike, May 1, 2015.

  1. drmike

    drmike 100% Tier-1 Gogent

    8,573
    2,717
    May 13, 2013
    So I am late to the systemd circus. 

    Updated a Debian box today with cronjobs that need to fire.

    This new systemd appears to make cronjobs no longer run.  Been depreciated and such should be in systemd mess.

    Can someone point me to some how-tos or  simple instruction on where stuff formerly we poked in crontab should now go?

    Noticed a slew of scheduled jobs didn't run today and need to fix those and clean up backlog.
     
  2. InertiaNetworks-Ryan

    InertiaNetworks-Ryan New Member Verified Provider

    28
    18
    Dec 17, 2013
    Last edited by a moderator: May 1, 2015
    drmike likes this.
  3. Amitz

    Amitz New Member

    427
    179
    May 15, 2013
    This is just another of many reasons why systemd is such a pain and utter mistake... :-(
     
    k0nsl likes this.
  4. drmike

    drmike 100% Tier-1 Gogent

    8,573
    2,717
    May 13, 2013
    I read the Arch doc earlier and still am going huh big picture.

    Going to be a lot of normal folks who when they upgrade run into this problem and determine it after the fact.

    We need a better doc for humans to take their nice and straightforward crontab entries and get them converted into Systemd version.

    PS: I am not anti-change - systemd has benefits surely.  But complicating cron like this and in upgrade process not addressing scheduled jobs for folks was a BIG MISTAKE by Debian devs.
     
    Last edited by a moderator: May 1, 2015
  5. InertiaNetworks-Ryan

    InertiaNetworks-Ryan New Member Verified Provider

    28
    18
    Dec 17, 2013
    I see Buffa. I run Arch Linux on my desktop full time so I'm use to systemd. I like how in systemd's timer mechanism everything is just written out in plain english and it just works. With cron that was a different story depending on the program or script interpreter. I also didn't like the @reboot hack in cron since a service can be made if its really important for a process to run on startup and die at reboot/shutdown.

    If you want you can PM/Skype me your crontab config and I'll convert it for ya.
     
    drmike likes this.
  6. drmike

    drmike 100% Tier-1 Gogent

    8,573
    2,717
    May 13, 2013
    Much appreciated.   This is Debian so likely different paths and all that fun.

    Maybe we should do some samples for benefit of everyone else out there.  Legit pain for a lot of folks with no tech tolerance or ability to Google the solution (results to queries in Google even Debian specific are Arch results :) ) === BAD.

    Let's take example of just a standard crontab scheduled job.  This is a recorder for a gardening show.


    0 6 * * 7 /home/recorder http://gcnplayer.gcnlive.com:80/channel3-hi.mp3 paulparent /home/recorder/ 14400

    Runs on Sunday morning at 6AM a script called recorder that is just fronting streamripper in this instance and records the show for 14400 seconds.

    How does one take that literal cron entry and get that converted into Systemd's timers --- emphasis on Debian?

    PS: Arch keeps taunting me.  Have ArchBang on my shortlist -  long time fan of CrunchBang which went to no more dev.
     
    splitice likes this.
  7. InertiaNetworks-Ryan

    InertiaNetworks-Ryan New Member Verified Provider

    28
    18
    Dec 17, 2013
    NOTE... This will make this cronjob/systemd service run as root. If you want it to run as a specified user, you must change the service file name to the following "[email protected](user).service", (user) meaning your account name. You must also update the timer file to reflect the new file name.

     

    Make a filed called /etc/systemd/system/cron-radiorecorder.service



    [Unit]
    Description=Buffas Radio Recorder Service
    # The name of the timer that's going to call this service file.
    Wants=cron-radiorecorder.timer

    [Service]
    # Comment out the line below if you want to run it as root.
    User=%I
    # KISS (Keep It Simple Stupid)
    Type=simple
    # The actual command that must be called.
    ExecStart=/home/recorder http://gcnplayer.gcnlive.com:80/channel3-hi.mp3 paulparent /home/recorder/ 14400

    [Install]
    WantedBy=basic.target


     


    Next make the file called /etc/systemd/system/cron-radiorecorder.timer


    [Unit]
    Description=Buffas Radio Recorder Job

    [Timer]
    # To add a time of your choosing here, please refer to systemd.time manual page for the correct format
    OnCalendar=Sun *-*-* 06:00:00
    # Persistence=true since this script is going to be called every week for life.
    Persistent=true
    # The name of the actual service must be specified since it contains the command to be run.
    Unit=cron-radiorecorder.service

    [Install]
    WantedBy=basic.target


    Now to install and enable it...



    # Refresh the daemons that systemd can see.
    systemctl daemon-reload
    # Enable the cron-radiorecorder timer
    systemctl enable cron-radiorecorder.timer
    # Enable the cron-radiorecorder service
    systemctl enable cron-radiorecorder.service
    # Start the cron-radiorecorder timer
    systemctl start cron-radiorecorder.timer



    And that's all folks!

    Since the service is created in systemd, the service can be started or stopped at any time by using "systemctl (start/stop) cron-radiorecorder.service". The cronjob/timer can be enabled/disabled and start/stopped doing "systemctl (enable/disable/start/stop) cron-radiorecorder.timer".

    Hopefully this will be able to help you.
     
    Last edited by a moderator: May 2, 2015
    souen, drmike and telephone like this.
  8. drmike

    drmike 100% Tier-1 Gogent

    8,573
    2,717
    May 13, 2013
    I'm grateful for the time and effort Mr. Ryan.  Quite a bunch of additional effort for what use to be a very simple cronjob.

    I'll give systemd a try on local workstation.  I already purged it from remote VPS instance and went back to cron and none systemd.  Since I had broken stuff...  and not thrilled.
     
  9. drmike

    drmike 100% Tier-1 Gogent

    8,573
    2,717
    May 13, 2013
  10. raindog308

    raindog308 vpsBoard Premium Member Moderator

    877
    675
    May 16, 2013
    Name one.

    I didn't know cron was "deprecated".  Works fine in CentOS 7 out of the box and RHEL/CentOS is the home/breeding ground of systemd.
     
    drmike and Amitz like this.