public function start($id) { if (!($workflow = Workflow::find((int) $id))) { return redirect('workflows')->with('status_error', "Workflow not found."); } if (empty($workflow->path)) { return redirect('workflows')->with('status_error', "Workflow not found."); } if (!empty($workflow->pid)) { return redirect('workflows')->with('status_error', "Workflow already started."); } if ($anotherStarted = Workflow::where('id', '!=', $id)->where('pid', '!=', '')->first()) { return redirect('workflows')->with('status_error', "Another workflow is already running. Please stop any other workflow first."); } if (!($settings = Settings::first())) { return redirect('workflows')->with('status_error', "Please fill in all the required settings."); } if (empty($settings->home_path)) { return redirect('workflows')->with('status_error', "Please fill in your home path."); } if (empty($settings->c9_path)) { return redirect('workflows')->with('status_error', "Please specify Cloud9 IDE path in settings."); } $command = "/usr/bin/nohup {$settings->nodejs_path} {$settings->c9_path} -w {$workflow->path} {$workflow->args} {$settings->default_args} > /dev/null & echo \$!"; putenv("HOME={$settings->home_path}"); $return = shell_exec($command); $pid = (int) $return; if (!$pid) { return redirect('workflows')->with('status_error', "Error while starting the server ({$return})."); } $workflow->pid = $pid; $workflow->save(); return redirect('workflows')->with('status_success', "Workflow started. PID #{$pid}"); }