UbuntuThis forum is for the discussion of Ubuntu Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Does your echo command work just running it from a terminal? It should although the root of the filesystem seems like an odd place to put the shutdown.test file. Running that command from a terminal as a user will get you a permission denied error. Running it as root produces the expected output.
Does your echo command work just running it from a terminal? It should although the root of the filesystem seems like an odd place to put the shutdown.test file. Running that command from a terminal as a user will get you a permission denied error.
I had also tried sending the output to /tmp/shutdown.test, but seeing nothing there I wondered if perhaps the reboot process cleared out /tmp. So I tried /shutdown.test.
I have a /etc/rc.local script, which does run and I can see that in the syslog:
Aug 25 18:07:09 labrat systemd[1]: Starting /etc/rc.local Compatibility...
I created the file below as shown in your initial post, made it executable and moved it to /etc/rc0.d and named it K99shutdown as explained in the link you posted.
I created the file below as shown in your initial post, made it executable and moved it to /etc/rc0.d and named it K99shutdown as explained in the link you posted.
I rebooted and there was a file named 'shutdown.text' in the root of the filesystem with the expected output:
This was done on Ubuntu 14.04.
Well, that's interesting. Mine simply does not work. Not sure what to try next. I have a 14.04 system. I'll try it there. Maybe it's a 16.04 thing.
Quote:
If you want 'Ubuntu experts', I think you will be better off at ubuntuforums or askubuntu.
Sadly, I've posted 6 questions on askubuntu over the past year, including this one, with ZERO responses. In fact, I find much better response on LQ. I'll check out ubuntuforums.
Is it even supposed to work with systemd? Just asking ...
That's what I was wondering. I just tried 2 more tests. I did the same as yancek on 14.04 and it worked with output to /shutdown.test albeit no output to /tmp/shutdown.test -- meaning, I suppose that /tmp is cleaned out on reboot.
On the 16.04 system I put the `echo` line inside the existing /etc/init.d/reboot, linked from /etc/rc6.d/K11reboot. Interestingly, that didn't create my /shutdown.test file either.
So, I think there's something up with these init scripts. Is not systemd new for 15.xx? Maybe I can't simply copy files into these folder (or modify existing files for that matter) with this new systemd mechanism.
14.04 uses upstart whereas 16.04 uses systemd. As far as I know systemd is mostly capable of running a compatible sysvinit script but yours does not conform to the LSB requirements. I don't know if this has changed for 16.04.
14.04 uses upstart whereas 16.04 uses systemd. As far as I know systemd is mostly capable of running a compatible sysvinit script but yours does not conform to the LSB requirements. I don't know if this has changed for 16.04.
Wow! This is wildly complex! I can't imagine why it was felt necessary to change this whole init script thing to systemd. I'm used to the good 'ole rc.d scripts in Slackware which are brain-dead simple for anyone able to write a shell script. Was something so broken with this that it needed to be fixed? Ok, end of gripe. I'll dig into your 2nd post example and see if I can figure out this esoteric systemd stuff.
ondoho: Interesting, though I was attempting to run in a script at shutdown, so I would hope that would be as atual root and not a sudoer. This is apparently an issue with how systemd works as I didn't have a problem doing this on 14.04.
Anyway, some progress, maybe. I monkey-typed the example in michaelk's 2nd link into /etc/systemd/system/localShutdown.service, with a couple of changes:
$ systemctl daemon-reload
$ systemctl start localShutdown.service
$ journalctl -u localShutdown
-- Logs begin at Sat 2016-08-27 00:12:44 EDT, end at Sat 2016-08-27 10:01:25 EDT. --
Aug 27 10:01:25 labrat systemd[1]: Started /etc/rc.local_shutdown Compatibility.
Still not quite working. When I ran the `systemctl start`, it ran immediately and created the /shutdown.test file. When I rebooted, nothing. Clearly I have something wrong with the settings in my unit file.
Now, is there a way to make sure this runs before any other runlevel/shutdown scripts? In the link I posted just before your comment it says,
Quote:
After - Defines the order in which units are started. The unit starts only after the units specified in After are active. Unlike Requires, After does not explicitly activate the specified units. The Before option has the opposite functionality to After.
So I suppose this mean I can have:
[unit]
Before=<something>
Any idea what I can put in <something>? I've not found any examples on the web so far.
For examle, would Before=multi-user.target be correct? It doesn't seem so intuitively.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.