Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto shutdown/startup script #92

Open
Zefty opened this issue Dec 25, 2021 · 2 comments
Open

Auto shutdown/startup script #92

Zefty opened this issue Dec 25, 2021 · 2 comments

Comments

@Zefty
Copy link

Zefty commented Dec 25, 2021

Not really an issue with LWSM as I am able to run the commands fine. I'm having some trouble getting an auto shutdown/startup script going. Would appreciate it if anyone has any solutions, cheers!

Your Environment

  • Version used: lwsm 4.0.5
  • Operating System and version: Fedora 35
  • Desktop Environment: Gnome
  • Node version: v16.13.0
  • List of Applications that are open (lwsm save) or should be opened (lwsm restore): Chrome, Files

Expected Behavior

No errors

Current Behavior

Dec 26 11:30:40 wuxhua systemd[1]: Starting Linux Window Session Manager Pre-Shutdown Processes...
░░ Subject: A start job for unit save_session.service has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit save_session.service has begun execution.
░░
░░ The job identifier is 6022.
Dec 26 11:30:40 wuxhua bash[7100]: lwsm: no config file present or it contains invalid json. Creating new one...
Dec 26 11:30:40 wuxhua bash[7100]: /usr/local/lib/node_modules/linux-window-session-manager/dist/index.js:84
Dec 26 11:30:40 wuxhua bash[7100]: throw err;
Dec 26 11:30:40 wuxhua bash[7100]: ^
Dec 26 11:30:40 wuxhua bash[7100]: Error: ENOENT: no such file or directory, mkdir 'undefined/.config/lwsm'
Dec 26 11:30:40 wuxhua bash[7100]: at Object.mkdirSync (node:fs:1334:3)
Dec 26 11:30:40 wuxhua bash[7100]: at mkdirSync (/usr/local/lib/node_modules/linux-window-session-manager/dist/index.js:80:12)
Dec 26 11:30:40 wuxhua bash[7100]: at Object. (/usr/local/lib/node_modules/linux-window-session-manager/dist/index.js:229:5)
Dec 26 11:30:40 wuxhua bash[7100]: at Module._compile (node:internal/modules/cjs/loader:1101:14)
Dec 26 11:30:40 wuxhua bash[7100]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
Dec 26 11:30:40 wuxhua bash[7100]: at Module.load (node:internal/modules/cjs/loader:981:32)
Dec 26 11:30:40 wuxhua bash[7100]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
Dec 26 11:30:40 wuxhua bash[7100]: at Module.require (node:internal/modules/cjs/loader:1005:19)
Dec 26 11:30:40 wuxhua bash[7100]: at require (node:internal/modules/cjs/helpers:102:18)
Dec 26 11:30:40 wuxhua bash[7100]: at Object. (/usr/local/lib/node_modules/linux-window-session-manager/cmd.js:3:14) {
Dec 26 11:30:40 wuxhua bash[7100]: errno: -2,
Dec 26 11:30:40 wuxhua bash[7100]: syscall: 'mkdir',
Dec 26 11:30:40 wuxhua bash[7100]: code: 'ENOENT',
Dec 26 11:30:40 wuxhua bash[7100]: path: 'undefined/.config/lwsm'
Dec 26 11:30:40 wuxhua bash[7100]: }
Dec 26 11:30:40 wuxhua systemd[1]: save_session.service: Main process exited, code=exited, status=1/FAILURE

Steps to Reproduce (for bugs)

Script stored in home/wuxhua/Scripts/save_session.sh

/usr/local/bin/lwsm list

Servicemd Service

`[Unit]
Description=Linux Window Session Manager Pre-Shutdown Processes
DefaultDependencies=no
After=final.target

[Service]
Type=oneshot
ExecStart=bash /home/wuxhua/Scripts/save_session.sh

[Install]
WantedBy=final.target`

@dlannan-fmad
Copy link

dlannan-fmad commented Mar 9, 2022

Im not very familiar with this application, but it seems that it is user based. If you are running this in a service, it is likely not running as the required user.

I think you would need a startup app (added to your session startup) and one for logout which I'm not sure how that would work. It would probably be easy enough to have a cron job running for the user to regularly save the session?

Im trying some of this out at the moment. Will let you know how I go.

[ Update ]
I dont think this will work as I expect. The program doesnt restore apps to correct positions or sizes and virtual screens. Much easier to have a manual hibernate. Im kind of puzzled why linux doesnt have a "snapshot" mechanism built into the system - essentially restoring the current memory layout for a session. Maybe I'll write one :)

@cocoonkid
Copy link

cocoonkid commented Jun 25, 2022

I am also having issues creating a systemd service that saves the layout when suspending and restores it when resuming.

I am getting errors. Presumably because systemd does not have the environment variables set that my user has.

If somebody can make this work I'd be so happy :)

The zsh scripts themselves work from cli.

/etc/systemd/system/save-layout.service
──────────────────────────────────────────────────────────────────────────────
[Unit]
Description=Save window layout to json
Before=sleep.target

[Service]
User=cocoonkid
Environment=DISPLAY=:0
ExecStart=bash /home/cocoonkid/save-lwsm.sh
ExecStartPost=bash /home/cocoonkid/restore-lwsm.sh

[Install]
WantedBy=sleep.target
save-lwsm.sh
──────────────────────────────────────────────────────────────────────────────
#! /usr/bin/zsh

zsh -i -c "lwsm save default"
restore-lwsm.sh
──────────────────────────────────────────────────────────────────────────────
#! /usr/bin/zsh

zsh -i -c "lwsm restore default"

@cocoonkid cocoonkid mentioned this issue Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants