You are not logged in.

#1 2016-11-30 14:32:05

cdysthe
Member
Registered: 2009-11-20
Posts: 62

[Solved] Starting scheduled task from a systemd timer fails.

Hi,

I have two executables in /usr/local/bin, one script which. among other things, runs the other application. I have a working timer/service combo for this but for some reason I can only get it to run if I add a third script which then runs the application/script combo.  So instead of having the timer run A.sh which also starts B I had to add C.sh which runs A.sh and B. All three can be run from the command line without problems. The error I get in the systemd journal is:

Nov 30 06:30:28 thinkpad1 systemd[9533]: btrfs-scrub.service: Failed at step EXEC spawning /usr/local/bin/btrfs-scub: N 

 

I am trying to learn systemd timers so I wonder what the reason may be for needing the third script to run the other two when run by the timer/service?

Update: The problem was a typo in the timer.

Last edited by cdysthe (2016-11-30 17:43:28)

Offline

#2 2016-11-30 14:43:42

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [Solved] Starting scheduled task from a systemd timer fails.

Post the contents of your scripts and timer/service files, we can't help without them.

Last edited by Slithery (2016-11-30 14:44:55)


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2016-11-30 15:13:54

cdysthe
Member
Registered: 2009-11-20
Posts: 62

Re: [Solved] Starting scheduled task from a systemd timer fails.

Hi,

Here's what I've got:

/etc/systemd/system/btrfs-scrub.timer
[Unit]
Description=BTRFS Scrub
[Timer]
OnCalendar=*-*-* 2:40:00
Persistent=true
[Install]
WantedBy=timers.target
/etc/systemd/system/btrfs.scrub.service
[Unit]
Description=BTRFS Scrub
[Service]
ExecStart=/usr/local/bin/scrub.sh
Type=simple
/usr/local/bin scrub.sh
#!/bin/sh
/usr/local/bin/btrfs-scrub
/usr/local/bin/btrfs-scrub
#!/bin/sh

# By Marc MERLIN <marc_soft@merlins.org> 2014/03/20
# License: Apache-2.0

which btrfs >/dev/null || exit 0

export PATH=/usr/local/bin:/sbin:$PATH

# bash shortcut for `basename $0`
PROG=${0##*/}
lock=/var/run/$PROG

# shlock (from inn) does the right thing and grabs a lock for a dead process
# (it checks the PID in the lock file and if it's not there, it
# updates the PID with the value given to -p)
# You can replace this with another lock program if you prefer or even remove
# the lock.
if ! shlock -p $$ -f $lock; then
    echo "$lock held, quitting" >&2
    exit
fi

if which on_ac_power >/dev/null 2>&1; then
    ON_BATTERY=0
    on_ac_power >/dev/null 2>&1 || ON_BATTERY=$?
    if [ "$ON_BATTERY" -eq 1 ]; then
	exit 0
    fi
fi

FILTER='(^Dumping|balancing, usage)'
test -n "$DEVS" || DEVS=$(grep '\<btrfs\>' /proc/mounts | awk '{ print $1 }' | sort -u)
for btrfs in $DEVS
do
    tail -n 0 -f /var/log/scrub.log | grep "BTRFS: " | grep -Ev '(disk space caching is enabled|unlinked .* orphans|turning on discard|device label .* devid .* transid|enabling SSD mode|BTRFS: has skinny extents|BTRFS: device label)' &
    mountpoint="$(grep "$btrfs" /proc/mounts | awk '{ print $2 }' | sort | head -1)"
    logger -s "Quick Metadata and Data Balance of $mountpoint ($btrfs)" >&2
    # Even in 4.3 kernels, you can still get in places where balance
    # won't work (no place left, until you run a -m0 one first)
    btrfs balance start -musage=0 -v $mountpoint 2>&1 | grep -Ev "$FILTER"
    btrfs balance start -musage=20 -v $mountpoint 2>&1 | grep -Ev "$FILTER"
    # After metadata, let's do data:
    btrfs balance start -dusage=0 -v $mountpoint 2>&1 | grep -Ev "$FILTER"
    btrfs balance start -dusage=20 -v $mountpoint 2>&1 | grep -Ev "$FILTER"
    # And now we do scrub. Note that scrub can fail with "no space left
    # on device" if you're very out of balance.
    logger -s "Starting scrub of $mountpoint" >&2
    echo btrfs scrub start -Bd $mountpoint
    ionice -c 3 nice -10 btrfs scrub start -Bd $mountpoint
    pkill -f 'tail -n 0 -f /var/log/scrub.log'
    logger "Ended scrub of $mountpoint" >&2
done

rm $lock
/usr/local/bin/btrfs-scrub

is running the application

/usr/local/bin/shlock (From Inn)

. If I try to run

/usr/local/bin/btrfs-scrub

directly from the timer it fails. If I use

/usr/local/bin/scrub.sh

it runs as it should.

I have used this setup on other distros so I thought I could use it on my new Arch install as well. This is the first time I try to run it with a systemd timer.

Last edited by cdysthe (2016-11-30 15:15:46)

Offline

#4 2016-11-30 16:30:05

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [Solved] Starting scheduled task from a systemd timer fails.

Nov 30 06:30:28 thinkpad1 systemd[9533]: btrfs-scrub.service: Failed at step EXEC spawning /usr/local/bin/btrfs-scub: N 

/usr/local/bin/btrfs-scub? Sounds like you may have typoed  the script name.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#5 2016-11-30 17:12:24

cdysthe
Member
Registered: 2009-11-20
Posts: 62

Re: [Solved] Starting scheduled task from a systemd timer fails.

Eschwartz wrote:
Nov 30 06:30:28 thinkpad1 systemd[9533]: btrfs-scrub.service: Failed at step EXEC spawning /usr/local/bin/btrfs-scub: N 

/usr/local/bin/btrfs-scub? Sounds like you may have typoed  the script name.

I bow my head in shame. Typo! No wonder the script worked. Thanks! smile

Offline

#6 2016-11-30 17:27:53

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [Solved] Starting scheduled task from a systemd timer fails.

Next time, be sure to paste the contents of the timer in the non-working condition, that too can help detect the typo variety of probem. wink

Please edit the first post and mark the thread title as solved.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#7 2016-11-30 18:44:56

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [Solved] Starting scheduled task from a systemd timer fails.

Next time, read (and post) the whole error message -- after the "N" you would have seen "o such file or directory" smile

Offline

Board footer

Powered by FluxBB