Failing to get systemd --user working

I have been attempting to get systemd running as my USERID via the --user parameter to systemctl. The objective is to convert my personal crontab to systemd.

So far it has been a failure. Searching online, I have found and read numerous posts without success. I am trying to get a simple script running on a calendar basis to provide a base for further development. I hope sharing my experience will get me pointed in the right direction.

SCRIPT RAUhellouser (in USERID/.local/share/systemd/user/)

#!/bin/bash

PRGNAM=$(basename -- "$0")
echo "$PRGNAM - $(date) - Hello User - $(id -nu)" >> /tmp/RAUhello_user.log
00echolines >> /tmp/RAUhello_user.log  # A USER/bin script that produces eye-catcher boundaries
echo "$PRGNAM - PATH - $PATH " >> /tmp/RAUhello_user.log
echo "$PRGNAM - Current Working Directory: $(pwd)" >> /tmp/RAUhello_user.log

exit 0

=================================================
SERVICE RAUhellouser.service (in USERID/.config/systemd/user/)

[Unit]
Description="Hello User Service"

[Service]
Type=oneshot
ExecStart=RAUhellouser

[Install]
WantedBy=default.target

=================================================
TIMER RAUhellouser.timer (in USERID/.config/systemd/user/)

[Unit]
Description=Run Hello User Script

[Timer]
OnCalendar=*-*-* *:*:00

[Install]
WantedBy=basic.target

=================================================
CURRENT STATUS

USERID@localhost.heavy1] ~ $ systemctl --user daemon-reload
USERID@localhost.heavy1] ~ $ systemctl --user start RAUhellouser.timer
USERID@localhost.heavy1] ~ $ systemctl --user status RAUhellouser.timer
● RAUhellouser.timer - Run Hello User Script
     Loaded: loaded (/home/USERID/.config/systemd/user/RAUhellouser.timer; disabled; preset: disabled)
     Active: active (waiting) since Fri 2025-05-09 16:24:51 MST; 21s ago
    Trigger: Fri 2025-05-09 16:26:00 MST; 46s left
   Triggers: ● RAUhellouser.service

May 09 16:24:51 localhost.heavy1 systemd[19430]: Started Run Hello User Script.
USERID@localhost.heavy1] ~ $ systemctl --user status RAUhellouser.service
Γ— RAUhellouser.service - "Hello User Service"
     Loaded: loaded (/home/USERID/.config/systemd/user/RAUhellouser.service; disabled; preset: disabled)
     Active: failed (Result: exit-code) since Fri 2025-05-09 16:27:08 MST; 512ms ago
   Duration: 2ms
TriggeredBy: ● RAUhellouser.timer
    Process: 11295 ExecStart=RAUhellouser (code=exited, status=203/EXEC)
   Main PID: 11295 (code=exited, status=203/EXEC)
        CPU: 2ms

May 09 16:27:08 localhost.heavy1 systemd[19430]: Starting "Hello User Service"...
May 09 16:27:08 localhost.heavy1 (ellouser)[11295]: RAUhellouser.service: Failed to locate executable RAUhellouser: No such file or directory
May 09 16:27:08 localhost.heavy1 (ellouser)[11295]: RAUhellouser.service: Failed at step EXEC spawning RAUhellouser: No such file or directory
May 09 16:27:08 localhost.heavy1 systemd[19430]: RAUhellouser.service: Main process exited, code=exited, status=203/EXEC
May 09 16:27:08 localhost.heavy1 systemd[19430]: RAUhellouser.service: Failed with result 'exit-code'.
May 09 16:27:08 localhost.heavy1 systemd[19430]: Failed to start "Hello User Service".
USERID@localhost.heavy1] ~ $

=================================================
JOURNAL EXTRACT
journalctl --output=short-full --since 16:27:00 -xe --user --unit=RAUhellouser*

Fri 2025-05-09 16:27:08 MST localhost.heavy1 systemd[19430]: Starting "Hello User Service"...
β–‘β–‘ Subject: A start job for unit UNIT has begun execution
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ A start job for unit UNIT has begun execution.
β–‘β–‘
β–‘β–‘ The job identifier is 631387.
Fri 2025-05-09 16:27:08 MST localhost.heavy1 (ellouser)[11295]: RAUhellouser.service: Failed to locate executable RAUhellouser: No such file or directory
β–‘β–‘ Subject: Process RAUhellouser could not be executed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ The process RAUhellouser could not be executed and failed.
β–‘β–‘
β–‘β–‘ The error number returned by this process is 2.
Fri 2025-05-09 16:27:08 MST localhost.heavy1 (ellouser)[11295]: RAUhellouser.service: Failed at step EXEC spawning RAUhellouser: No such file or directory
β–‘β–‘ Subject: Process RAUhellouser could not be executed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ The process RAUhellouser could not be executed and failed.
β–‘β–‘
β–‘β–‘ The error number returned by this process is 2.
Fri 2025-05-09 16:27:08 MST localhost.heavy1 systemd[19430]: RAUhellouser.service: Main process exited, code=exited, status=203/EXEC
β–‘β–‘ Subject: Unit process exited
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ An ExecStart= process belonging to unit UNIT has exited.
β–‘β–‘
β–‘β–‘ The process' exit code is 'exited' and its exit status is 203.
Fri 2025-05-09 16:27:08 MST localhost.heavy1 systemd[19430]: RAUhellouser.service: Failed with result 'exit-code'.
β–‘β–‘ Subject: Unit failed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ The unit UNIT has entered the 'failed' state with result 'exit-code'.
Fri 2025-05-09 16:27:08 MST localhost.heavy1 systemd[19430]: Failed to start "Hello User Service".
β–‘β–‘ Subject: A start job for unit UNIT has failed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ A start job for unit UNIT has finished with a failure.
β–‘β–‘
β–‘β–‘ The job identifier is 631387 and the job result is failed.

================Redacted===================

β–‘β–‘ The job identifier is 633555 and the job result is failed.
Fri 2025-05-09 16:51:03 MST localhost.heavy1 systemd[19430]: Starting "Hello User Service"...
β–‘β–‘ Subject: A start job for unit UNIT has begun execution
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ A start job for unit UNIT has begun execution.
β–‘β–‘
β–‘β–‘ The job identifier is 633651.
Fri 2025-05-09 16:51:03 MST localhost.heavy1 (ellouser)[12277]: RAUhellouser.service: Failed to locate executable RAUhellouser: No such file or directory
β–‘β–‘ Subject: Process RAUhellouser could not be executed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ The process RAUhellouser could not be executed and failed.
β–‘β–‘
β–‘β–‘ The error number returned by this process is 2.
Fri 2025-05-09 16:51:03 MST localhost.heavy1 (ellouser)[12277]: RAUhellouser.service: Failed at step EXEC spawning RAUhellouser: No such file or directory
β–‘β–‘ Subject: Process RAUhellouser could not be executed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ The process RAUhellouser could not be executed and failed.
β–‘β–‘
β–‘β–‘ The error number returned by this process is 2.
Fri 2025-05-09 16:51:03 MST localhost.heavy1 systemd[19430]: RAUhellouser.service: Main process exited, code=exited, status=203/EXEC
β–‘β–‘ Subject: Unit process exited
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ An ExecStart= process belonging to unit UNIT has exited.
β–‘β–‘
β–‘β–‘ The process' exit code is 'exited' and its exit status is 203.
Fri 2025-05-09 16:51:03 MST localhost.heavy1 systemd[19430]: RAUhellouser.service: Failed with result 'exit-code'.
β–‘β–‘ Subject: Unit failed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ The unit UNIT has entered the 'failed' state with result 'exit-code'.
Fri 2025-05-09 16:51:03 MST localhost.heavy1 systemd[19430]: Failed to start "Hello User Service".
β–‘β–‘ Subject: A start job for unit UNIT has failed
β–‘β–‘ Defined-By: systemd
β–‘β–‘ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
β–‘β–‘
β–‘β–‘ A start job for unit UNIT has finished with a failure.
β–‘β–‘
β–‘β–‘ The job identifier is 633651 and the job result is failed.
=================================================

Read man systemd.service what is the default command search path.

What made you think systemd was going to find your script in this location?

# more /etc/systemd/system/fooBackup.service 
[Unit]
Description=Backup for user foo
After=network-online.target
Wants=network-online.target

[Service]
User=foo
Group=users
Type=oneshot
ExecStart=/usr/local/bin/createSnapshotHourly.sh
TimeoutStartSec=3100

# ls -alh /etc/systemd/system/fooBackup.service
-rw-r--r-- 1 root root 229 21. Apr 21:22 /etc/systemd/system/fooBackup.service

# ls -alh /etc/systemd/system/fooBackup.timer
-rw-r--r-- 1 root root 157 21. Apr 21:22 /etc/systemd/system/fooBackup.timer

# more /etc/systemd/system/fooBackup.timer 
[Unit]
Description=Backup for user foo

[Timer]
OnCalendar=hourly
Persistent=true
RandomizedDelaySec=2700

[Install]
WantedBy=timers.target

# systemctl enable fooBackup.timer
# systemctl start fooBackup.timer
# systemctl list-timers -all
# journalctl -u fooBackup.service

This from here.

Similar to system units, user units are located in the following directories (ordered by ascending precedence):

  • /usr/lib/systemd/user/ where units provided by installed packages belong.
  • ~/.local/share/systemd/user/ where units of packages that have been installed in the home directory belong.
  • /etc/systemd/user/ where system-wide user units are placed by the system administrator.
  • ~/.config/systemd/user/ where the user puts their own units.

When a systemd user instance starts, it brings up the per user target default.target. Other units can be controlled manually with systemctl --user.

User unit is not the same as script invoked by this unit.

1 Like

From Understanding and Administering systemd:

ExecStart

The command to run to start the service. This includes the full path to the command and arguments to modify the service. The resulting [Service] section looks like this:

[Service]
Type=simple
ExecStart=/usr/bin/sleep infinity

Some example:

karl@erlangen:~> systemctl --user cat save-jalbum-settings.service 
# /home/karl/.config/systemd/user/save-jalbum-settings.service

[Unit]
Description=Save jAlbum Project Files

[Service]
ExecStart=/home/karl/bin/save-jalbum-settings.sh

[Install]
WantedBy=default.target
karl@erlangen:~> 

Thanks to all who contributed. I think I now have a stable example to work from so I am marking this thread solved and will open a new thread if/when I have my next problem.

You misunderstand what β€œSolution” mark is intended for. We expect this to indicate the description of the solution so that others having the same problem could try to apply it. Marking post with zero useful content as β€œSolution” does not help anyone.

Good reminder arvidjaar. I will show progress to today.

This is one line out of my crontab converted to systemd. I still have some work to do on results handling but so far so good.

SCRIPT CRON05-00-00 (in USERID/.config/systemd/user/)

#!/bin/bash

PRGNAM=$(basename -- "$0")
WHERE=/tmp/$PRGNAM.log

00echolines                  > $WHERE
echo $PRGNAM - $(date)      >> $WHERE
echo -e "RAID Array Status" >> $WHERE
raidstatus                  >> $WHERE
echo "Temps & Fans "        >> $WHERE
system.temps                >> $WHERE

cat $WHERE | mutt -s "Results From $PRGNAM" -- USERID@AtHome.Home

exit 0

=================================================
SERVICE CRON05-00-00.service (in USERID/.config/systemd/user/)

[Unit]
Description="Crontab 05:00:00"

[Service]
Type=oneshot
ExecStart=/home/USERID/.config/systemd/user/CRON05-00-00

[Install]
WantedBy=default.target

=================================================
TIMER CRON05-00-00.timer (in USERID/.config/systemd/user/)

[Unit]
Description=Run CRON05-00-00 Script

[Timer]
OnCalendar=*-*-* 05:00:00

[Install]
WantedBy=basic.target

=================================================
CURRENT STATUS

USERID@localhost.heavy1] ~ $ systemctl --user daemon-reload
USERID@localhost.heavy1] ~ $ systemctl --user start CRON05-00-00.timer
USERID@localhost.heavy1] ~ $ systemctl status  --user CRON05-00-00.timer
● CRON05-00-00.timer - Run CRON05-00-00 Script
     Loaded: loaded (/home/USERID/.config/systemd/user/CRON05-00-00.timer; disabled; preset: disabled)
     Active: active (waiting) since Sun 2025-05-11 21:12:23 MST; 12h ago
    Trigger: Tue 2025-05-13 05:00:00 MST; 18h left
   Triggers: ● CRON05-00-00.service

May 11 21:12:23 localhost.heavy1 systemd[19430]: Started Run CRON05-00-00 Script.
USERID@localhost.heavy1] ~ $ systemctl status  --user CRON05-00-00.service
β—‹ CRON05-00-00.service - "Crontab 05:00:00"
     Loaded: loaded (/home/USERID/.config/systemd/user/CRON05-00-00.service; disabled; preset: disable>
     Active: inactive (dead) since Mon 2025-05-12 05:00:13 MST; 5h 1min ago
TriggeredBy: ● CRON05-00-00.timer
    Process: 6061 ExecStart=/home/USERID/.config/systemd/user/CRON05-00-00 (code=exited, status=0/SUCC>
   Main PID: 6061 (code=exited, status=0/SUCCESS)
        CPU: 36ms

May 12 05:00:13 localhost.heavy1 systemd[19430]: Starting "Crontab 05:00:00"...
May 12 05:00:13 localhost.heavy1 systemd[19430]: Finished "Crontab 05:00:00".
USERID@localhost.heavy1] ~ $ 

=================================================
RESULT MAIL

Message  1:
From USERID@AtHome.Home  Mon May 12 10:04:52 2025
X-Original-To: USERID@athome.home
Delivered-To: USERID@athome.home
Date: Mon, 12 May 2025 10:04:51 -0700
From: Fred Wright <USERID@localhost.heavy1>
To: USERID@athome.home
Subject: Results From CRON05-00-00
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

================================================================
CRON05-00-00 - Mon 12 May 09:46:13 MST 2025
RAID Array Status
md126: [UU]
md127: [UU]
Temps & Fans 
f71868a-isa-0290
fan1:        1242 RPM
fan2:         925 RPM
temp1:       +111.2Β°F  (high = +185.0Β°F, hyst = +177.8Β°F)
temp2:       +107.6Β°F  (high = +185.0Β°F, hyst = +177.8Β°F)
temp3:       +102.2Β°F  (high = +158.0Β°F, hyst = +154.4Β°F)
radeon-pci-0008
temp1:        +48.2Β°F  (crit = +248.0Β°F, hyst = +194.0Β°F)
k10temp-pci-00c3
temp1:        +54.5Β°F  (high = +158.0Β°F)

lines 1-30/30 (END)

=================================================