Auto Shutdown VM when app is closed

Disposable VMs shut down after their application is closed, is there a way to make a regular VM have the same behavior?

Basically after i’ve closed an app in a regular VM i want that VM to shut down automatically. I suspect i can insert code used in disposable VMs into my regular VM? But which code and where do i put it?

1 Like

@fsflover
thanks. installed

sudo apt install qubes-app-shutdown-idle

15 minutes was too long to wait so i edited

/usr/lib/python3.9/site-packages/qubesidle/idleness_monitor.py
TIMEOUT_SECONDS = 1 * 6

Qube now shutsdown after 6 seconds. Thanks.

4 Likes

Thanks for this.

In my case, customization path is

/usr/lib/python3/dist-packages/qubesidle/idleness_monitor.py

I tried that in whonix-ws-16 template but the checkbox remains unusable (grayed out) in its AppVMs.

How to make this work?

A totally different method.

Generally there’s ONE app in my qube, that when I’m done with it, I’m done with the qube. I don’t want it shutting down just because I opened and closed an Xterm on that qube. (I suspect I’d hate having things disappear after an idle time…because what if I’m in the middle of using an App and then have to take a bathroom break and get distracted after that? Boom! Work is toast. I have totally disabled idle time shutdowns.)

I write a bash script to run that app, then shutdown the Qube.

I then create a desktop file to run that script, basically a copy of the one for that app but I change the name of the executable to be the script, and that’s what I put in my menus (it will be named, say, gimp-shutdown, as opposed to just gimp).

1 Like

I use my qubes virtually the same way, with files in rc.local and .config/autostart running the app on Start Qube; could you share your script for shutdown? I’d be interested in having the qube shutdown after I close the app; the idle package would certainly result in lost work.

I think you and @SteveC are under a misapprehension.
A qube wont shut down just because you “open and close an Xterm”, or
after a period of inactivity. app-shutdown-idle will trigger if there is
no open window or no network activity (other options also available).

So if you are working in an app, open an Xterm in the same qube and
close it, nothing will happen.
If you are working in an app, and get distracted, nothing will happen.
If you are working in an app and close all windows in that qube then
it will trigger. But since you have closed all windows presumably you
have finished with the qube for the moment.

I advocate use of app-shutdown-idle and the only cases of lost work
are where users close a document and fail to save their work. Your
scripting is not going to fix that.

I never presume to speak for the Qubes team. When I comment in the Forum or in the mailing lists I speak for myself.
1 Like

No, it certainly won’t!

For that matter it also won’t fix you shutting down the qube via qui-domains or the manager. I don’t know how hard it would be to have a popup warning you that you have apps open in a qube before shutting down. Fortunately I have the desktop switcher to warn me that something somewhere is still open so I can at least check.

Thanks for the clarification on how it works! I may decide to start using it to cover cases where what I’m already doing fails for some reason.

(I wasn’t thinking opening and closing an xterm could do it under normal circumstances; as far as I know even with a disp1234 it’s the original app which the qube was stdarted for, that must be closed. However, using my suggested method if xterm is called from a script that shuts down, it will! I generally only do that with the “main” app in a named disposable (i.e., the one that I created the named disposable for). However even there I have a “regular” (non-shutdown) entry for the app in my menu, even if I don’t put a shortcut on my desktop for it. This is how I simulate the behavior of a disp1234 disposable and I’ve even done it with some (regular) AppVMs.)

Can anyone please kindly answer my question (post #5)?
I can’t find info anywhere.

The canonical way is given:
sudo apt install qubes-app-shutdown-idle

You say that you have done that and the checkbox remains greyed out in a
Whonix template.
I don’t use Whonix so can only advise that you take your question to the
Whonix forums. (This is the request from the Whonix devs for
Qubes-Whonix problems.)

I never presume to speak for the Qubes team. When I comment in the Forum or in the mailing lists I speak for myself.

@unman

Is qubes-app-shutdown-idle developed by Whonix or by Qubes team?

qubes-app-shutdown-idle is developed by Qubes team.
https://github.com/QubesOS/qubes-app-shutdown-idle

Whonix template is developed by Whonix team.
https://github.com/Qubes-Community/Contents/blob/master/docs/privacy/whonix.md

Is another user have this issue ?
If you got that problem, you probably not the only one.

qubes-app-shutdown-idle works on fedora and debian.
The issue (if any) most probably lie on the Whonix template.
Did you check the Whonix forum search (and/or ask on their forum) ??

It’s an other way of saying what Unman said …

related (?):
https://github.com/QubesOS/qubes-issues/issues/7528
https://github.com/QubesOS/qubes-issues/issues/7979

It’s maybe a bug in the Qube Manager GUI.
I guess you do have restarted Qube Manager after installing qubes-app-shutdown-idle.
Everything is up to date, etc.

some idea, from the above links:

I tried to manually launch qubes-idle-watcher

in a dom0 terminal, try sudo qvm-features whonix-ws-16 service.shutdown-idle 1 command.
If the whonix-ws-16 VM was running, restart it.

You should have started a new thread, as its not the same issue as the OP.
And the fact that the thread have a solution mark, doesn’t help for the visibily of your question.

Even if the whonix forum is more appropriated, it’s maybe a Qubes bug.
(The Whonix devs would thanks you to open a thread on their forum, so they can know about a potential bug)
Does it work for Debian/Fedora appqubes ?

It is developed by Qubes.
The Whonix devs have asked that Qubes-Whonix issues ( and this is
obviously one) should be raised at the Whonix forum rather than here,
because they are more likely to get coverage.

I never presume to speak for the Qubes team. When I comment in the Forum or in the mailing lists I speak for myself.

I don’t know why but today it is not grayed out. Maybe an update fixed it, maybe a reboot, no idea. Anyway, the problem seems solved for the moment. Now I have to try how it works.

Thank you.

Where can I read how “idle” is defined, i.e. what exactly is considered activity and lack of it?

@qubist I may be wrong, but I believe that since templates need to be shut down before the new packages can be used, the same might be true for the presence of the package to be acknowledged by the Qube Manager?

@unman posted a list of scenarios earlier in this thread, is that what you’re looking for @qubist?

@gonzalo-bulnes

@unman posted a list of scenarios earlier in this thread, is that what you’re looking for @qubist?

I respect @unman’s helpful replies in every thread he joins. However, they always come with his nice disclaimer, which is an excellent reminder that forums are not a replacement for documentation.

IOW, I hope for some kind of documentation or other evidence (even if that is a pointer to lines of readable code) of how this actually works.

And he’s right. A lot of questions can be answered by reading the doc or the github repository …
A lot of user just don’t.

I already provided the link.

In https://github.com/QubesOS/qubes-app-shutdown-idle/blob/main/setup.py you can see:

        entry_points={
            'console_scripts': [
                'qubes-idle-watcher = qubesidle.idleness_monitor:main'
            ],
            'qubes_idle_watcher': [
                'x-window-monitor = qubesidle.idle_watcher_window:IdleWatcher',
                'network-watcher = qubesidle.network_watcher:NetworkWatcher'
            ]
        }

By reading the other files you will see exactly what the script do.
https://github.com/QubesOS/qubes-app-shutdown-idle/tree/main/qubesidle

2 Likes