+class base_process_service : public ServiceRecord
+{
+ friend class ServiceChildWatcher;
+ friend class ServiceIoWatcher;
+
+ protected:
+ ServiceChildWatcher child_listener;
+ ServiceIoWatcher child_status_listener;
+
+ // start the process, return true on success
+ virtual bool start_ps_process() noexcept;
+ bool start_ps_process(const std::vector<const char *> &args, bool on_console) noexcept;
+
+ virtual void all_deps_stopped() noexcept;
+ virtual void handle_exit_status(int exit_status) noexcept = 0;
+
+ public:
+ base_process_service(ServiceSet *sset, string name, ServiceType service_type, string &&command,
+ std::list<std::pair<unsigned,unsigned>> &command_offsets,
+ sr_list * pdepends_on, sr_list * pdepends_soft)
+ : ServiceRecord(sset, name, service_type, std::move(command), command_offsets,
+ pdepends_on, pdepends_soft), child_listener(this), child_status_listener(this)
+ {
+ }
+
+ ~base_process_service() noexcept
+ {
+ }
+};
+
+class process_service : public base_process_service
+{
+ // called when the process exits. The exit_status is the status value yielded by
+ // the "wait" system call.
+ virtual void handle_exit_status(int exit_status) noexcept override;
+
+ public:
+ process_service(ServiceSet *sset, string name, string &&command,
+ std::list<std::pair<unsigned,unsigned>> &command_offsets,
+ sr_list * pdepends_on, sr_list * pdepends_soft)
+ : base_process_service(sset, name, ServiceType::PROCESS, std::move(command), command_offsets,
+ pdepends_on, pdepends_soft)
+ {
+ }
+
+ ~process_service() noexcept
+ {
+ }
+};
+
+class bgproc_service : public base_process_service
+{
+ virtual void handle_exit_status(int exit_status) noexcept override;
+
+ bool doing_recovery : 1; // if we are currently recovering a BGPROCESS (restarting process, while
+ // holding STARTED service state)
+
+ // Read the pid-file, return false on failure
+ bool read_pid_file() noexcept;
+
+ public:
+ bgproc_service(ServiceSet *sset, string name, string &&command,
+ std::list<std::pair<unsigned,unsigned>> &command_offsets,
+ sr_list * pdepends_on, sr_list * pdepends_soft)
+ : base_process_service(sset, name, ServiceType::BGPROCESS, std::move(command), command_offsets,
+ pdepends_on, pdepends_soft)
+ {
+ doing_recovery = false;
+ }
+
+ ~bgproc_service() noexcept
+ {
+ }
+};
+
+class scripted_service : public base_process_service
+{
+ virtual void all_deps_stopped() noexcept override;
+ virtual void handle_exit_status(int exit_status) noexcept override;
+
+ public:
+ scripted_service(ServiceSet *sset, string name, string &&command,
+ std::list<std::pair<unsigned,unsigned>> &command_offsets,
+ sr_list * pdepends_on, sr_list * pdepends_soft)
+ : base_process_service(sset, name, ServiceType::SCRIPTED, std::move(command), command_offsets,
+ pdepends_on, pdepends_soft)
+ {
+ }
+
+ ~scripted_service() noexcept
+ {
+ }
+};
+
+