0

Im trying to write a systemd unit for autoupdate system every Friday after 18:00. And everything work fine if I start service manually via systemctl start --user autoupd.service.

* autoupd.service - Autoupdate system
     Loaded: loaded (/home/user/.config/systemd/user/autoupd.service; static; vendor preset: enabled)
     Active: inactive (dead) since Sat 2020-0704 17:26:52 MSK; 3s ago
TriggeredBy: * autoupd.timer
    Process: 930 ExecStart=/user/bin/mate-terminal -e /home/user/.local/bin/update (code=exited, status=0/SUCCESS)
   Main PID: 930 (code=exited, status=0/SUCCESS)

Jul 04 17:26:52 localhost systemd[372]: Started Autoupdate system.
Jul 04 17:26:52 localhost systemd[372]: autoupd.service: Succeeded.

But if service started by autoupd.timer it fails with a weird error, which I don't properly understand.

* autoupd.service - Autoupdate system
        Loaded: loaded (/home/user/.config/systemd/user/autoupd.service; static; vendor preset: enabled)
        Active: failed (Result: exit-code) since Sat 2020-0704 17:23:54 MSK; 1min 27s ago
   TriggeredBy: * autoupd.timer
       Process: 378 ExecStart=/usr/bin/mate-terminal -e /home/user/.local/bin/update (code=exited, status=1/FAILURE)
      Main PID: 378 (code=exited, status=1/FAILURE)

Jul 04 17:23:53 localhost systemd[372]: Started Autoupdate system.
Jul 04 17:23:54 localhost mate-terminal[378]: Failed to parse arguments: Cannot open display:
Jul 04 17:23:54 localhost systemd[372]: ^[[0;1;39m^[[0;1;39mautoupdate.service: Main process exited, code=exiited, status=1/FAILURE
Jul 04 17:23:54 localhost systemd[372]: ^[[0;1;38;5;185m^[[0;1;39m^[[0;1;38;5;185mautoupdate.service: Failed with result `exit-code' 

Anyone know why this is happening and how to fix this? There is my sources:

/home/user/.config/systemd/user/autoupd.timer

[Unit]
Description=Autoupdate timer

[Timer]
OnCalendar=Sat 17:23
Persistent=true
Unit=autoupd.service

[Install]
WantedBy=timers.target

/home/user/.config/systemd/user/autoupd.service

[Unit]
Description=Autoupdate system

[Service]
Type=simple
ExecStart=mate-terminal -e "/home/user/.local/bin/update"

/home/user/.local/bin/update

#!/bin/sh
sudo pacman -Syu
echo ""
echo "Press Enter to exit..."
read

output of DISPLAY="" /home/user/.local/bin/update

 user@localhost ~ DISPLAY="" /home/user/.local/bin/update
:: Synchronizing package databases...
 core is up to date
 extra                1676.8 KiB  9.63 MiB/s 00:00 [######################] 100%
 community               5.0 MiB  8.87 MiB/s 00:01 [######################] 100%
 multilib              163.6 KiB  9.40 MiB/s 00:00 [######################] 100%
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...

Packages (7) exempi-2.5.2-1  inkscape-1.0-5  libmagick6-6.9.11.23-1
             libmpdclient-2.19-1  libvorbis-1.3.7-2  poppler-0.90.0-1
             poppler-glib-0.90.0-1

Total Download Size:    22.69 MiB
Total Installed Size:  174.59 MiB
Net Upgrade Size:        0.12 MiB

:: Proceed with installation? [Y/n] n

Press Enter to exit...
4
  • 1
    You have something that you want to run automatically, but it appears to expect user interaction? Jul 5, 2020 at 15:38
  • Yes, I want to read ArchLinux rss news feed before confirming update.
    – MadEvil
    Jul 5, 2020 at 15:44
  • 1
    Then I know of no good way to do what you're trying to do. Maybe someone else will have a better idea. Jul 5, 2020 at 15:51
  • 1
    @AndyDalton, Оk, I read the Internet briefly and it seems to not possible interact with GUI via systemd. Maybe I just write own script for this :-)
    – MadEvil
    Jul 5, 2020 at 15:58

1 Answer 1

0

So, I'm not one to give these "you're doing it wrong" answers often but you probably should not want to do this. Really pacman should only be called manually.

Some healthier alternatives:

  • If you want to update the database files you could go for pacman -Syy; checkupdates shows a list of packages to be updated, so you could script something together yourself if you so please.

  • If you want something to update you when updates are available you can try something like Discover, or more lightweight alternatives such as aarchup, or archupdate-indicator.

  • For your RSS reading needs I suggest using informant; it includes Pre-Install pacman hooks that abort any pacman install operations if you have not marked some news as read.

However, if you are truly determined to go about it this way you will have to use the dreaded --noconfirm flag.

This will bypass any "Are you sure?" messages. If you install informant pacman will still abort if some new news is released, but this is still considered 'living on the edge' so be warned.

You must log in to answer this question.

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