constexpr static int DINIT_CP_STARTSERVICE = 3;
constexpr static int DINIT_CP_STOPSERVICE = 4;
-// Roll-back all services:
-constexpr static int DINIT_CP_ROLLBACKALL = 5;
+// Shutdown:
+constexpr static int DINIT_CP_SHUTDOWN = 5;
+ // followed by 1-byte shutdown type
processStartStop(pktType);
return;
}
- else if (pktType == DINIT_CP_ROLLBACKALL) {
- // Roll-back all services
- if (service_set->setRollbackHandler(this)) {
- service_set->stop_all_services();
- log_to_console = true;
- char ackBuf[] = { DINIT_RP_ACK };
- if (! queuePacket(ackBuf, 1)) return;
- }
- else {
- char nakBuf[] = { DINIT_RP_NAK };
- if (! queuePacket(nakBuf, 1)) return;
+ else if (pktType == DINIT_CP_SHUTDOWN) {
+ // Shutdown/reboot
+ if (rbuf.get_length() < 2) {
+ chklen = 2;
+ return;
}
+ auto sd_type = static_cast<ShutdownType>(rbuf[1]);
+
+ service_set->stop_all_services(sd_type);
+ log_to_console = true;
+ char ackBuf[] = { DINIT_RP_ACK };
+ if (! queuePacket(ackBuf, 1)) return;
+
// Clear the packet from the buffer
- rbuf.consume(1);
+ rbuf.consume(2);
chklen = 0;
return;
}
p.first->removeListener(this);
}
- service_set->clearRollbackHandler(this);
active_control_conns--;
}
void ServiceSet::service_inactive(ServiceRecord *sr) noexcept
{
active_services--;
- if (active_services == 0 && rollback_handler != nullptr) {
- rollback_handler->rollbackComplete();
- }
}
std::list<ServiceRecord *> records;
const char *service_dir; // directory containing service descriptions
bool restart_enabled; // whether automatic restart is enabled (allowed)
- ControlConn *rollback_handler; // recieves notification when all services stopped
ShutdownType shutdown_type = ShutdownType::CONTINUE; // Shutdown type, if stopping
{
return shutdown_type;
}
-
- // Set the rollback handler, which will be notified when all services have stopped.
- // There can be only one rollback handler; attempts to set it when already set will
- // fail. Returns true if successful.
- bool setRollbackHandler(ControlConn *conn) noexcept
- {
- if (rollback_handler == nullptr) {
- rollback_handler = conn;
- return true;
- }
- else {
- return false;
- }
- }
-
- void clearRollbackHandler(ControlConn *conn) noexcept
- {
- if (rollback_handler == conn) {
- rollback_handler = nullptr;
- }
- }
};
#endif