Failed to start systemd timer and service

If you want to run commands under your user, you should use the user instance of systemd.

If you want to run commands as root, then it’s better to move the script to /usr/local/bin for example and to make sure the SELinux labels are correct everywhere:

$ restorecon -RFv \
    /usr/local/bin/myscript \
    /etc/systemd/system/myunit.service \
    etc.

I moved but keep receiving same message no matter where i put the files.

Failed to start git-auto.timer: Unit git-auto.timer not found.

looks like some problem with Unit

im on silverblue btw

To help diagnose this issues, we need more information and more precise error messages.

Where are you files? Where did you place your units? Which commands did you run? What full error messages do you get?

Something like:

$ cat /etc/systemd/system
...
$ systemctl daemon-reload
...
$ Checking for error message in the journal after reload
...
etc.

I posted above, i can put the files anywhere, now as you said i tried in /usr/local/bin
systemctl enable /usr/local/bin/git-auto.timer

Created symlink /etc/systemd/system/git-auto.timer → /usr/local/bin/git-auto.timer.
Created symlink /etc/systemd/system/timers.target.wants/git-auto.timer → /usr/local/bin/git-auto.timer.

systemctl start /usr/local/bin/git-auto.timer

Failed to start usr-local-bin-git\x2dauto.timer.mount: Unit usr-local-bin-git\x2dauto.timer.mount not found.

Idk why im having trouble trying to make something that should be so easily , i also dont know if is some perks of silverblue, but didnt find anything on net about this

please be more specific on the commands that i should run, im not tech savy enough
and thanks for your support

You must put the files in /etc/systemd/system folder.
Avoid symlinks until you have the basics working.

ls /etc/systemd/system | cat
basic.target.wants
bluetooth.target.wants
ctrl-alt-del.target
dbus-org.bluez.service
dbus-org.fedoraproject.FirewallD1.service
dbus-org.freedesktop.Avahi.service
dbus-org.freedesktop.home1.service
dbus-org.freedesktop.ModemManager1.service
dbus-org.freedesktop.nm-dispatcher.service
dbus-org.freedesktop.oom1.service
dbus-org.freedesktop.resolve1.service
dbus-org.freedesktop.thermald.service
dbus.service
default.target
dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants
display-manager.service
getty.target.wants
git-auto.timer
graphical.target.wants
local-fs.target.wants
multi-user.target.wants
network-online.target.wants
remote-fs.target.wants
sockets.target.wants
sysinit.target.wants
systemd-homed.service.wants
systemd-journald.service.wants
timers.target.wants
user@.service.wants
vmtoolsd.service.requires

done, but same problem persist

idk bro, i tried this before and didnt work, move to another place, but now move back again to this folder , did the same commands then before, and know works

but even in this folder i got symlink:
Removed “/etc/systemd/system/timers.target.wants/git-auto.timer”.
Created symlink /etc/systemd/system/timers.target.wants/git-auto.timer → /etc/systemd/system/git-auto.timer.

when i ran systemctl enable git-auto.timer

thanks all !

The symlinks into the .wants folders are not a problem.

What does systemctl start git-auto.timer do?

The enable only sets symlink, it does not start anything working unless you reboot.

thanks.
Another question. Do you guys backup /etc/systemd/system folder ?
I usually just backup HOME, but i may have other timers in the future, just wondering the best approach

I backup /etc and /home personally.

bro, i realize that today the script was not trigger by the timer.
So i run:
systemctl --failed

  UNIT                       LOAD   ACTIVE SUB    DESCRIPTION                         
● git-auto.service           loaded failed failed Rodar git-auto-timer
● logrotate.service          loaded failed failed Rotate log files
● rpm-ostree-countme.service loaded failed failed Weekly rpm-ostree Count Me reporting

systemctl list-timers

NEXT                            LEFT LAST                              PASSED UNIT               >
Tue 2023-12-19 15:17:28 -03 5h 58min Sun 2023-12-17 20:44:17 -03      18h ago systemd-tmpfiles-cl>
Tue 2023-12-19 18:00:00 -03       8h Tue 2023-12-19 09:00:12 -03    18min ago git-auto.timer     >
Wed 2023-12-20 00:00:00 -03      14h Tue 2023-12-19 08:26:59 -03    51min ago logrotate.timer    >
Wed 2023-12-20 00:00:00 -03      14h Tue 2023-12-19 08:26:59 -03    51min ago unbound-anchor.time>
Wed 2023-12-20 06:37:29 -03      21h Tue 2023-12-19 08:26:59 -03    51min ago plocate-updatedb.ti>
Thu 2023-12-21 20:09:55 -03   2 days Sat 2023-12-16 13:40:35 -03 1 day 3h ago rpm-ostree-countme.>
Sun 2023-12-24 01:00:00 -03   4 days Sun 2023-12-17 16:43:27 -03      21h ago raid-check.timer   >
Mon 2023-12-25 00:07:19 -03   5 days Mon 2023-12-18 00:08:21 -03      14h ago fstrim.timer  

you see that git-auto.timer is listed, but git-auto.service failed

systemctl status git-auto.timer

● git-auto.timer - Run git-auto script
     Loaded: loaded (/etc/systemd/system/git-auto.timer; enabled; preset: disabled)
     Active: active (waiting) since Mon 2023-12-18 14:52:32 -03; 18h ago
    Trigger: Tue 2023-12-19 18:00:00 -03; 8h left
   Triggers: ● git-auto.service

systemctl status git-auto.service

× git-auto.service - Rodar git-auto-timer
     Loaded: loaded (/etc/systemd/system/git-auto.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/system/service.d
             └─10-timeout-abort.conf
     Active: failed (Result: exit-code) since Tue 2023-12-19 09:36:59 -03; 2s ago
   Duration: 1ms
TriggeredBy: ● git-auto.timer
    Process: 1021785 ExecStart=/usr/local/bin/git-auto.sh (code=exited, status=203/EXEC)
   Main PID: 1021785 (code=exited, status=203/EXEC)
        CPU: 1ms

dez 19 09:36:59 fedora systemd[1]: Started git-auto.service - Rodar git-auto-timer.
dez 19 09:36:59 fedora (-auto.sh)[1021785]: git-auto.service: Failed to execute /usr/local/bin/git-auto.sh: Exec format error
dez 19 09:36:59 fedora (-auto.sh)[1021785]: git-auto.service: Failed at step EXEC spawning /usr/local/bin/git-auto.sh: Exec format error
dez 19 09:36:59 fedora systemd[1]: git-auto.service: Main process exited, code=exited, status=203/EXEC
dez 19 09:36:59 fedora systemd[1]: git-auto.service: Failed with result 'exit-code'.

my script is in /usr/local/bin
im getting Exec format error in git-auto.service

Apparently it tries to run the script from /usr/local/bin/git-auto.sh and fails

Yes, my script is in there, the path is correct(writed the wrong path on the previous post sorry), do you know any possible reason to the execution failed ?

Missing the #!/bin/sh line perhaps. Or it could have CRLF line endings.

I should put that on the first line of .service and the .timer file also ?

#!/bin/sh

That would be on the first line of the script, not in the systemd files.

thanks i got past the exec error, now i get another erro, but looks like is something in the script
dez 19 10:49:13 fedora git-auto.sh[1034341]: To add an exception for this directory, call:
dez 19 10:49:13 fedora git-auto.sh[1034341]: git config --global --add safe.directory …
dez 19 10:49:13 fedora git-auto.sh[1034343]: fatal: detected dubious ownership in repository at …

I already ran that command with sudo and without sudo and same error appears
sudo git config --global --add safe.directory (my directory)

which is strange, since if i run this script it works , but if i start it from service it wont

It is probably time to display your script so we can see what it is supposed to be doing.