LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-10-2019, 12:39 AM   #1
masavini
Member
 
Registered: Jun 2008
Posts: 285

Rep: Reputation: 6
run a command before server reboots after a kernel update...


hi,
i have an ubuntu 18.04 server which reboots periodically to apply kernel upgrades.
i'd like to set it up so that a script run just before the machine shuts down.
how can i do that?
thanks!

Last edited by masavini; 07-10-2019 at 02:08 AM.
 
Old 07-10-2019, 12:44 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Possible solution: https://unix.stackexchange.com/quest...efore-shutdown
 
Old 07-11-2019, 12:49 PM   #3
masavini
Member
 
Registered: Jun 2008
Posts: 285

Original Poster
Rep: Reputation: 6
wow, that looks pretty much complicated!

let me explain my case...

i have a home server where /tmp is mounted as a tmpfs and i use it to save the lastpass-client cache.
it contains very sensitive data, so i think this is a good way to protect it if someone comes in and steals the pc: if that happens, the pc will be shut down and the cache directory in /tmp would be deleted (and, as far as i know, unrecoverable).


this way, however, the cache is lost when the system reboots after an upgrade, as well.
just before those reboots, therefore, i would move the /tmp/lpass_cache directory to $HOME, and then move it again to /tmp just after the reboot.


this is the command i'd like to run before the pc powers off:
Code:
[[ -d /tmp/lpass_cache ]] && mv /tmp/lpass_cache /home/user/

and then i would set a cron job like this:
Code:
@reboot [[ -d /home/user/lpass_cache ]] && mv /home/user/lpass_cache /tmp/

what do you think about?

i read some systemd service files documentation but i still haven't found how to run a command before the shutdown of a REBOOT sequence only...

Last edited by masavini; 07-11-2019 at 12:50 PM.
 
Old 07-11-2019, 02:28 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
I don't believe there is a difference in the "shutdown" process between reboot and physical shutdown. The difference is what happens after all the processes have ended. That is, either the 'puter is booted or switched off.

So, what you're proposing would seem to defeat the purpose for which you're using /tmp if you automated it. Your last-pass cache would always get backed up to $HOME and would therefore be available in the event of a theft of the hardware.

Perhaps all you need to do is script the backup and restore processes and run them manually when needed.

Last edited by scasey; 07-11-2019 at 02:29 PM.
 
  


Reply

Tags
reboot, server, ubuntu 18.04



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kexec kernel automatically reboots before copying entire vmcore file saurin Linux - Kernel 1 04-22-2018 12:00 AM
FreeBSD: reboots before installation begins... Basslord1124 *BSD 3 04-03-2006 03:35 AM
Gentoo Installer Reboots Before Any Commands Typed In sdexp Linux - Software 1 03-01-2006 07:30 AM
Installing RedHat 8.0 on Win98 Intel system reboots computer before copying files. livatlantis Linux - Newbie 10 08-15-2004 02:25 PM
RH Linux 9 reboots before log in screen, goes on continuously homerson Linux - Software 1 05-03-2004 08:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration