Trigger a script on safe mode

Currently reading
Trigger a script on safe mode

9
1
NAS
DS918+
I have a Unifi cloud key (as part of a UDM), a DS918, and a low end Cyberpower UPS attached via usb to the DS.

The cloud key can have well documented database corruption issues if it loses power abruptly, so I'd like to run a shell script when the synology enters Safe Mode prior, prior to sending the shutdown signal back to the UPS.

(i) The simplest way would be to have a shell script triggered when the synology enters Safe Mode, but the only options for triggering in DSM are for Power On and Shutdown.

- Is there anything I can poll from a script to tell if the DSM is in Safe Mode ?



(ii) Another way I can think of would be to modify DSM's built-in NUT package (which I'm reluctant to do as it will probably be overwritten with DSM updates). However if it's the only option, am I on the right track with:

- modifying the CMDSCRIPT in /usr/syno/bin/synoups

- the 'fsd' case is the correct one to edit (as this is the actual shutdown command issued to the UPS) ?

- add in my command (ie ssh to the cloudkey and issue a poweroff) prior to the command /usr/sbin/upsmon -c fsd (which I believe is the final shutdown command back to the UPS) ?
 
Thinking aloud here… when the DS enters safe mode the disks are in a dismounted state. Can you do anything with that? Just a thought.

Good thought, but I think I need a specific 'safe mode' flag rather than looking for whenever the drives are unmounted. There could be a case when the drives are unmounted (eg a failure unrelated to power) where I don't want the gateway router turned off !
 
I'm not familiar with UniFi Cloud Key but looking on the Web and it seems to be powered by PPoE/PPoE+ and/or USB port.

Is it possible to make the power supply to the unit more resilient, such as add UPS direct power to the USB port maybe even a separate UPS that will last for hours. Or, if the power requirements support it, a USB battery pack that can support connection for charge and discharge ports ... keeping it charged until the power drops and then it will power the Cloud Key.

When my NAS goes on to UPS power I get email alerts, likewise when it is returned. So I think there is a log event that will be recorded.
 
So I think there is a log event that will be recorded.
Good point.

If you go to
/var/log
You’ll find lines like these in messages.

A9F605F7-C1D8-42F6-8780-501720E61584.jpeg


I believe you can search for ‘Safe Shutdown’ too. I don’t have it here because the system didn’t need to go into shutdown. It was me playing with the circuit breaker on that day 😇
 
there is also another possible way:
1. put the Unifi controller from CloudKey into Docker
2. Docker into NAS
3. and you have more useful Controller operation for you (from each possible point of view)
then you don’t need Cloud key feature in your UDM
then you have solved power off/on issue in easy way
for more information you can use Resources in our Forum
Cheers
 
Thanks for the replies; looking for UPS entries in the log file is a good idea

Using another CloudKey (on the NAS) is very clever, but I'm not sure you can adopt the UDM that way ? (I could be wrong); either way it seems to somewhat defeat the purpose of buying a UDM in the first place

It turns out all of this is somewhat moot - using the standard poweroff commands just leads to a reboot rather than actually shutting down, so when I tested my synoups modification, it triggered a reboot instead.

According to this thread, the mongodb corruption issues may have been fixed with the UDM - time will tell !
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Similar threads

I do get them for stopping the container. thijs@DT_Server:~$ sudo docker ps | grep gitea fb74eec91ead...
Replies
4
Views
5,078
I have a very similar script that runs every 15 mins. But I needed it to delay to around 1.5 minutes after...
Replies
3
Views
618
  • Question
OK, I'm now seeing something I recognize. There was no reason to start with the /var/services/...
Replies
5
Views
2,123
  • Question
Yes I also came across that page and it does work! I am now able to start/stop the VPN as I please. I...
Replies
2
Views
2,412
As I said in my first post, I tried running it as me, as admin and as root but there was no difference...
Replies
7
Views
3,320
the original post has been updated about how to shutdown the Client side also :coffee: 1616434288 you...
Replies
12
Views
5,754
That would not work in my case. The share needs to be mounted read/write on 4 Windows computers. It's...
Replies
7
Views
6,475

Welcome to SynoForum.com!

SynoForum.com is an unofficial Synology forum for NAS owners and enthusiasts.

Registration is free, easy and fast!

Back
Top