1

I'm running Ubuntu 18.04.1 and I'm trying to create a script that shuts down Chromium properly before shutting down the system so that it doesn't give me "restore session" popup after booting. I figured I'll use killall to this and came up with /home/shutdownscript.sh:

#!/bin/bash 
killall -HUP "chromium-browser --enable-pinch"

that seems to do the trick.

However, now I have a problem with actually running this script at shutdown or reboot.

First thing I tried was putting it in /etc/init.d as shutdownscript with chmod +x and then symlinking it to rc0.d and rc6.d as K99shutdownscript and later K01ashutdownscript. However, that didn't work for me.

I thought maybe I should just create a new systemd service, so I created shutdownscript.service in /etc/systemd/system with contents like this:

[Unit]
Description=Saves Chromium session

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/home/istir/shutdownscript.sh

[Install]
WantedBy=multi-user.target

Then I ran systemctl start shutdownscript.service and systemctl enable shutdownscript.service but it still didn't work as intended.

The solution is probably very simple but I returned to Linux after around 6 years of using Windows and macOS so I don't really remember what did I do earlier to make shutdown scripts.

Thanks for any help!

3
  • I would swear it happens by default with Firefox and Chrome in Linux. Aug 7, 2018 at 19:38
  • I guess it should but for me it doesn't even on fresh installation with only Chromium installed. When I close chromium normally and then reboot everything is as it should, but if I leave chromium open and reboot then it tells me to restore session. It's not critical, just kinda pain to do every time.
    – istir
    Aug 7, 2018 at 19:41
  • 1
    Instead of working around it, I suggest you look into the original issue of Chromium not shutting down properly on reboot. (It should!) Maybe start with this question which might have some ideas of what to try already. Otherwise, try to give more details about which desktop environment and/or window manager are you using, where you installed Chromium from, how you're rebooting the machine, etc. to troubleshoot that. I suggest asking a new question (as this one is about other stuff.) Maybe consider asking at AskUbuntu, might get more answers there.
    – filbranden
    Aug 8, 2018 at 2:08

1 Answer 1

0

With reference to this, we might need to run the following after configuring systemctl.

 sudo systemctl daemon-reload

And we should have a header in the script like below.

### BEGIN INIT INFO
# Provides:          scriptname
# Required-Start:    
# Required-Stop:     
# Default-Start:     0 1 6
# Default-Stop:      
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO
5
  • Still no luck, when using systemctl enable it actually gives an error update-rc.d: error: shutdownscript Default-Start contains no runlevels, aborting.
    – istir
    Aug 7, 2018 at 19:47
  • @istir try the header as updated in the answer.
    – Siva
    Aug 7, 2018 at 19:59
  • I succeeded in enabling the script and running it but it still doesn't do what I want it to do. Maybe I should change Default-start to 0 6? IIRC these are numbers for shutdown and reboot. I had to change shutdownscript.service to shutdownscriptnew.service because I couldn't enable it otherwise. However, when running sudo systemctl stop shutdownscriptnew.service it actually does what it should and closes chromium.
    – istir
    Aug 7, 2018 at 20:16
  • yes we should start at run level 0,1 and 6
    – Siva
    Aug 7, 2018 at 20:20
  • Still no luck, I tried changing Default-Start and Default-Stop and even ExecStart and ExecStop - if I run systemctl stop shutdownscriptnew.service it closes chromium, but if I reboot it doesn't do anything and it still terminates it so that I have to restore session.
    – istir
    Aug 7, 2018 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .