Re: [systemd-devel] Schedule reboot in *.service file

2019-06-07 Thread Mike Gilbert
On Fri, Jun 7, 2019 at 6:14 AM Jeffrey Walton  wrote:
>
> On Thu, May 16, 2019 at 11:02 AM Mike Gilbert  wrote:
> >
> > On Thu, May 16, 2019 at 4:50 AM Lennart Poettering
> >  wrote:
> > >
> > > On Mi, 15.05.19 15:53, Jeffrey Walton (noloa...@gmail.com) wrote:
> > >
> > > > if [[ "$NEEDS_REBOOT" -eq 1 ]]
> > > > then
> > > > echo "Scheduling reboot in 10 minutes"
> > > > reboot -r 10
> > >
> > > This syntax is not understood by systemd:
> > >
> > > https://www.freedesktop.org/software/systemd/man/reboot.html#
> > >
> > > If you want to schedule some command to be invoked at some future time, 
> > > use:
> > >
> > > systemd-run --on-active=10s echo "Hello World"
> >
> > Another option would be to use "shutdown -r +10", which systemctl does
> > understand. This will schedule a reboot via systemd-logind.
>
> Thanks Mike.
>
> I was missing the +10, doh...
>
> But fixing it resulted in a new issue:
>
> systemd[1]: Starting Update the system once a day without
> system-update[7454]: Updated package list
> systemd[1]: [/etc/systemd/system/system-update.service:7]
> systemd[1]: [/etc/systemd/system/system-update.service:7]
> system-update[7454]: Upgraded system
> system-update[7454]: Purging old packages
> system-update[7454]: Scheduling reboot in 10 minutes
> system-update[7454]: reboot: invalid option -- 'r'

Did you replace "reboot" with "shutdown -r"? They are separate
commands, and only "shutdown -r" supports the "+10" syntax.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

Re: [systemd-devel] Schedule reboot in *.service file

2019-05-16 Thread Mike Gilbert
On Thu, May 16, 2019 at 4:50 AM Lennart Poettering
 wrote:
>
> On Mi, 15.05.19 15:53, Jeffrey Walton (noloa...@gmail.com) wrote:
>
> > if [[ "$NEEDS_REBOOT" -eq 1 ]]
> > then
> > echo "Scheduling reboot in 10 minutes"
> > reboot -r 10
>
> This syntax is not understood by systemd:
>
> https://www.freedesktop.org/software/systemd/man/reboot.html#
>
> If you want to schedule some command to be invoked at some future time, use:
>
> systemd-run --on-active=10s echo "Hello World"

Another option would be to use "shutdown -r +10", which systemctl does
understand. This will schedule a reboot via systemd-logind.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

Re: [systemd-devel] Schedule reboot in *.service file

2019-05-16 Thread Lennart Poettering
On Mi, 15.05.19 15:53, Jeffrey Walton (noloa...@gmail.com) wrote:

> if [[ "$NEEDS_REBOOT" -eq 1 ]]
> then
> echo "Scheduling reboot in 10 minutes"
> reboot -r 10

This syntax is not understood by systemd:

https://www.freedesktop.org/software/systemd/man/reboot.html#

If you want to schedule some command to be invoked at some future time, use:

systemd-run --on-active=10s echo "Hello World"

Lennart

--
Lennart Poettering, Berlin
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[systemd-devel] Schedule reboot in *.service file

2019-05-15 Thread Jeffrey Walton
Hi Everyone,

I have a systemd timer that fires early in the morning. The timer
starts a systemd service, and the service checks for updates using the
package manager. If updates are found then they are applied. The
service runs fine and is shown below.

The tail of the service schedules a reboot of the machine at +10
minutes when updates are applied. The reboot clears a UI widget that
confuses my users and loads the latest components upon reboot.

The reboot is not happening. When I inspected the systemd logs I see
that it was supposed to happen. When I check the user's desktop that
damn useless UI widget is present nagging about installing updates.

How do I schedule a reboot using systemd service file?

Thanks in advance.

=

$ cat /etc/systemd/system/system-update.service
[Unit]
Description=Update the system once a day without user prompts

[Service]
Type=oneshot
ExecStart=/usr/sbin/system-update
Wants=system-update.timer

[Install]
WantedBy=system-update.target

=

$ cat /usr/sbin/system-update
#!/usr/bin/env bash

PATH=/sbin:/usr/sbin:/bin:/usr/bin

# Update the package lists
if apt-get update &>/dev/null
then
echo "Updated package list"
else
echo "Failed to update package list"
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi

# If no packages are upgradeable, then the message is "Listing... Done".
# Otherwise a package name is listed as upgradeable.
COUNT=$(apt list --upgradable 2>/dev/null | grep -v 'Listing' | wc -l)

# Only update and reboot if packages are available
if [[ "$COUNT" -gt 0 ]]
then
if apt-get dist-upgrade -y &>/dev/null
then
echo "Upgraded system"
else
echo "Failed to upgrade system"
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi

echo "Purging old packages"
apt autoremove --purge &>/dev/null

NEEDS_REBOOT=1
fi

if [[ -f /var/run/reboot-required ]]
then
NEEDS_REBOOT=1
fi

if [[ "$NEEDS_REBOOT" -eq 1 ]]
then
echo "Scheduling reboot in 10 minutes"
reboot -r 10
fi

[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 0 || return 0

=

$ systemctl status system-update.service
? system-update.service - Update the system once a day without user prompts
   Loaded: loaded (/etc/systemd/system/system-update.service; enabled; vendor pr
   Active: inactive (dead) since Wed 2019-05-15 05:03:59 EDT; 10h ago
  Process: 17218 ExecStart=/usr/sbin/system-update (code=exited, status=0/SUCCES
 Main PID: 17218 (code=exited, status=0/SUCCESS)

May 15 05:01:28 qotom systemd[1]: Starting Update the system once a day without
May 15 05:01:34 qotom system-update[17218]: Updated package list
May 15 05:03:58 qotom system-update[17218]: Upgraded system
May 15 05:03:58 qotom system-update[17218]: Purging old packages
May 15 05:03:59 qotom system-update[17218]: Scheduling reboot in 10 minutes
May 15 05:03:59 qotom systemd[1]: Started Update the system once a day without u
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel