You are not logged in.
Hello!
I am trying to log uptime on shutdown and reboot with no success.
I create the file /usr/lib/systemd/system/uptime.service:
[Unit]
Description=/etc/rc.local.shutdown Compatibility
ConditionFileIsExecutable=/etc/rc.local.shutdown
DefaultDependencies=no
After=rc-local.service basic.target
Before=shutdown.target
[Service]
Type=oneshot
ExecStart=/etc/rc.local.shutdown
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
/etc/rc.local.shutdown:
[jribeiro@arkosta ~]$ ls -l /etc/rc.local.shutdown
-rwxr-xr-x 1 root root 107 Out 24 12:42 /etc/rc.local.shutdown
[jribeiro@arkosta ~]$ cat /etc/rc.local.shutdown
echo "$(date) - $(/usr/bin/uptime | sed 's/.*up \([^,]*\), .*/\1/')" >> /home/jribeiro/registo_de_uptime
Any ideas?
Last edited by joseribeiro (2014-10-25 19:57:59)
Offline
May i suggest using the package community/uptimed ?
Offline
Thanks but I want to know what i'm doing wrong.
Offline
Have you enabled your service ?
It may be better to keep your own services under /etc/systemd/system instead of /usr/lib/...
Maybe a dependency issue e.g.
After=rc-local.service basic.target
?
Personal website: reboot.li
GitHub: github.com/rebootl
Offline
Yes, the service is enabled.
Offline
Is the service called at all?
What does
journalctl -u uptime
say?
Also, try to strip everything from your unit file that is not absolutely necessary for your service to work. You might try:
[Unit]
Description=/etc/rc.local.shutdown Compatibility
Before=shutdown.target
[Service]
ExecStart=/etc/rc.local.shutdown
[Install]
WantedBy=shutdown.target
Further, try a simple script that only creates a file in your home folder as target.
EDIT: What solved the issue on my machine: Add
#!/bin/bash
to the script. See [SOLVED]Starup sript not getting executed in systemd
Last edited by MK13 (2014-10-24 19:36:32)
Offline
journalctl -u uptime says:
[jribeiro@arkosta ~]$ journalctl -u uptime
-- Logs begin at Sex 2014-10-24 22:02:15 WEST, end at Sex 2014-10-24 22:10:39 WEST. --
sudo journalctl -u uptime says:
[jribeiro@arkosta ~]$ sudo journalctl -u uptime
-- Logs begin at Sex 2014-10-24 22:02:03 WEST, end at Sex 2014-10-24 22:12:07 WEST. --
/usr/lib/systemd/system/uptime.service:
[jribeiro@arkosta ~]$ sudo cat /usr/lib/systemd/system/uptime.service
[Unit]
Description=/etc/rc.local.shutdown Compatibility
Before=shutdown.target
[Service]
ExecStart=/etc/rc.local.shutdown
[Install]
WantedBy=shutdown.target
Still no success...
Last edited by joseribeiro (2014-10-24 21:17:30)
Offline
Did you add the shebang in the rc.local.shutdown script?
Could you please
systemctl start uptime
systemctl -l status uptime
Offline
Sure I can:
[jribeiro@arkosta ~]$ sudo systemctl -l status uptime
● uptime.service - /etc/rc.local.shutdown Compatibility
Loaded: loaded (/usr/lib/systemd/system/uptime.service; enabled)
Active: inactive (dead) since Sex 2014-10-24 22:39:28 WEST; 10s ago
Process: 6220 ExecStart=/etc/rc.local.shutdown (code=exited, status=0/SUCCESS)
Main PID: 6220 (code=exited, status=0/SUCCESS)
Offline
Dumb question: Did you check for the 'registo_de_uptime' file in your home folder after starting the service manually?
On my machine, with the stripped unit file and the script with the shebang, everything works fine. Lets double check that before moving on:
Replace the content of the rc.local.shutdown script with
#!/bin/bash
echo "$(date)" >> /home/jribeiro/uptime
and try to start the service again via
systemctl start uptime
and check whether a file called 'uptime' is present in your home folder.
The status query of the uptime service shows that the service run without errors so it should work...
Last edited by MK13 (2014-10-24 22:14:44)
Offline
Before starting the service the 'registo_de_uptime' file was empty.
After starting the service the 'registo_de_uptime' is modified:
[jribeiro@arkosta ~]$ cat /home/jribeiro/registo_de_uptime
Sáb Out 25 13:36:29 WEST 2014 - 4 min
Then I rebooted my system and I checked the 'registo_de_uptime' file:
[jribeiro@arkosta ~]$ cat /home/jribeiro/registo_de_uptime
Sáb Out 25 13:36:29 WEST 2014 - 4 min
No changes...
P.S.: I tried same thing with "echo "$(date)" >> /home/jribeiro/uptime" and the result is equal. The file changes manually but don't changes automatically.
Last edited by joseribeiro (2014-10-25 12:55:37)
Offline
Could you post output of
sudo journalctl -b -0 -u uptime
Try altering your unit file to
[Unit]
Description=/etc/rc.local.shutdown Compatibility
Before=shutdown.target
[Service]
ExecStart=/bin/true
ExecStop=/etc/rc.local.shutdown
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
Then starting the service manually and shutdown afterwards.
Offline
I altered the uptime unit file:
[jribeiro@arkosta ~]$ cat /usr/lib/systemd/system/uptime.service
[Unit]
Description=/etc/rc.local.shutdown Compatibility
Before=shutdown.target
[Service]
ExecStart=/bin/true
ExecStop=/etc/rc.local.shutdown
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
Then I started the uptime service manually:
[jribeiro@arkosta ~]$ sudo systemctl start uptime
I checked the 'registo_de_uptime' file:
[jribeiro@arkosta ~]$ cat /home/jribeiro/registo_de_uptime
Sáb Out 25 19:43:31 WEST 2014 - 2 min
After that I rebooted my system.
I checked the 'registo_de_uptime' file, again:
[jribeiro@arkosta ~]$ cat /home/jribeiro/registo_de_uptime
Sáb Out 25 19:43:31 WEST 2014 - 2 min
Sáb Out 25 19:44:27 WEST 2014 - 3 min
Everything seems to be alright. I wanted to make the ultimate test.
With that in mind I rebooted the system.
I checked the 'registo_de_uptime' file, once more:
[jribeiro@arkosta ~]$ cat /home/jribeiro/registo_de_uptime
Sáb Out 25 19:43:31 WEST 2014 - 2 min
Sáb Out 25 19:44:27 WEST 2014 - 3 min
No success...
It works when I start the service manually and in the right next reboot, after that it won't work.
Here is the journal's ouput:
[jribeiro@arkosta ~]$ sudo journalctl -b -0 -u uptime
-- Logs begin at Sex 2014-10-24 22:02:03 WEST, end at Sáb 2014-10-25 20:05:29 WEST. --
By the way:
[jribeiro@arkosta ~]$ sudo systemctl status uptime
● uptime.service - /etc/rc.local.shutdown Compatibility
Loaded: loaded (/usr/lib/systemd/system/uptime.service; enabled)
Active: inactive (dead)
Last edited by joseribeiro (2014-10-25 19:07:32)
Offline
Could you post output of
systemctl status uptime
after starting the service manually and
journalctl -b -u uptime
Last edited by MK13 (2014-10-25 19:38:35)
Offline
I don't give up.
So, I altered the Install section and I changed 'shutdown.target' for 'multi-user.target'.
Here it is the uptime.service's final version:
[Unit]
Description=/etc/rc.local.shutdown Compatibility
Before=shutdown.target
[Service]
ExecStart=/bin/true
ExecStop=/etc/rc.local.shutdown
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Now, it works!
Many thanks to MK13
Last edited by joseribeiro (2014-10-25 19:43:43)
Offline
You're welcome, glad to hear it's working now
Don't forget to mark the topic as solved.
Last edited by MK13 (2014-10-25 19:48:00)
Offline
I will do that.
Thanks again!!!
Last edited by joseribeiro (2014-10-25 19:56:45)
Offline