You are not logged in.

#1 2013-05-13 22:08:27

rwd
Member
Registered: 2009-02-08
Posts: 664

[solved] calling script at shutdown, /etc/rc.local.shutdown?

I would like a script to be called when shutting down, running under my user, in my case a script to sync my Firefox profile from a ramdisk. From what I've read ~/.bash_logout is called when logging out from a login session. However when I shutdown xfce from the menu, or just kill xfce and do 'sudo shutdown -jP now'  at the login prompt .bash_logout is not called. I would think shutting down would log out all users. Or should I put this in  /etc/rc.local.shutdown instead?

Last edited by rwd (2013-05-14 22:47:43)

Offline

#2 2013-05-13 22:10:26

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [solved] calling script at shutdown, /etc/rc.local.shutdown?

Do you have an rc.local.shutdown?  This is not something that is included in systemd.  So if you are going to go through the trouble of creating a service for this, you might as well just create  a service for precisely what you want to do.

Just create a script, and call it from a service file and have it WantedBy=shutdown.target.  Then enable that!

Last edited by WonderWoofy (2013-05-13 22:11:58)

Offline

#3 2013-05-13 22:21:40

rwd
Member
Registered: 2009-02-08
Posts: 664

Re: [solved] calling script at shutdown, /etc/rc.local.shutdown?

thanks. I thought of rc.local.shutdown because it is mentioned a lot in the arch wiki. I supposed those pages need to be cleaned up? But shouldn't a shutdown log out all users and run their .bash_logout scripts first? It seems a bit unwieldy to run my user specific script on a system level like '/bin/bash -su myuser /home/myuser/scripts/bla.sh'.

Offline

#4 2013-05-13 23:19:20

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [solved] calling script at shutdown, /etc/rc.local.shutdown?

Your .bash_logout is run when your shell exits.  This has nothing to do with the shutdown of your machine other than that your shell may be exiting when you shut down.  Even then, it may not be called since shutting down X does not gaurantee a clean exit from your shell.

The other option you have is to look into the /usr/lib/systemd/system-shutdown directory.  I think the man page that describes its functionality is systemd-shutdown(8).  This might be entirely suitable for what you need.  I actually use the system-sleep directory (same thing, but for sleep/hibernate) for a couple of things... though offhand, I can't remember what it is I put in there.

Offline

#5 2013-05-13 23:45:53

nagaseiori
Member
Registered: 2012-09-22
Posts: 72

Re: [solved] calling script at shutdown, /etc/rc.local.shutdown?

You could also use profile-sync-daemon: https://wiki.archlinux.org/index.php/Pr … ync-daemon

Offline

#6 2013-05-14 15:52:02

Kilzool
Member
From: Ireland
Registered: 2010-08-04
Posts: 232

Re: [solved] calling script at shutdown, /etc/rc.local.shutdown?

Here's what I use.

#!/bin/bash
#
# /etc/rc.local.shutdown: rc.local.shutdown script.
#
rm -f /home/kilzool/.thumbnails/normal/*
rm -rf /home/kilzool/.adobe/Flash_Player/AssetCache/*

The above file is put in /etc/ as 'rc.local.shutdown'  -- it also has the +x executable flag.

Below in the systemd service file, which I enable.
The file is put in: /usr/lib/systemd/system/rc-local-shutdown.service
(it will work on next reboot)

[Unit]
Description=/etc/rc.local.shutdown Compatibility
ConditionFileIsExecutable=/etc/rc.local.shutdown
DefaultDependencies=no
After=basic.target
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/etc/rc.local.shutdown
StandardInput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Last edited by Kilzool (2013-05-14 15:55:46)

Offline

#7 2013-05-14 17:53:17

rwd
Member
Registered: 2009-02-08
Posts: 664

Re: [solved] calling script at shutdown, /etc/rc.local.shutdown?

Thanks for the tips. I think I'll try a systemd service like the above. And maybe call a script from rc.local.shutdown that either executes ~/.bash_logout for all logged in users or explicitly logs out users.

Last edited by rwd (2013-05-14 17:56:22)

Offline

Board footer

Powered by FluxBB