Every time I shutdown or restart my laptop (Ubuntu 14.04), I would like to run a script that checks, whether I pushed my newest code to my remote git repository. If I forgot it, then it opens a terminal, asks the user to enter a commit message and pushes the changes. I already got the script working.
Now I am looking for a way to make this script run automatically when I shutdown or reboot, but before the GUI exits.
My approach so far is with System V Init (yes, I know it's a bit dated):
I copy my init script with LSB header to /etc/init.d:
sudo cp ~/git_checker /etc/init.d/
, change permissions:
sudo chmod a+x /etc/init.d/git_checker
and configure execution scenarios:
sudo update-rc.d /etc/init.d/git_checker defaults
When I test this script with
sudo service git_checker start,
I get the error: "Failed to parse arguments: Cannot open display:"
Reading up on it, I found out, that init scripts should not be used to open terminals (like so:
su user -c 'x-terminal-emulator -e /home/user/git_check.sh'
), because the X server is not guaranteed to be running when init scripts are executed.
So init scripts seem to be the wrong way. Is there another way? Maybe with upstart or systemd?
In the case of running the script at system startup, I can simply put it in startup applications. Does something similar exist, like shutdown applications?