I want to set both dhcp relay and dhcp server on a router. I mean when the remote dhcp server is reachable , the clients get ip from dhcp relay and when the remote server is unreachable, the router itself can provide ip for client with dhcp server configuration.
Is it ppssible?
Perhaps you want to make sure you have 2 “relays” configured ?
And then arrange things on the DHCP-server side. There are various ways to make a solid DHCP-architecture depending on the type of DHCP-server in use.
Alternatively I think could configure some “netwatch” entry on the Mikrotik to “ping” the remote DHCP-server it is “alive”. (but that does not guarantee the correct operation of the DHCP-service itself)
If that goes down you could fire of a routerOS command to enable the local DHCP-server. The problem is that is does not have a clue about what leases have been allocated by your remote DHCP server etc. So you need to think this through, use some scope-splitting or whatever.