package MyApp::Controller::System; use Mojo::Base 'Mojolicious::Controller'; sub restart { my $c = shift; return $c->redirect_to('/noperm') unless $c->is_admin; my $pid = fork(); my $base_path = $c->app->home; if ($pid == 0) { my $cmd = "cd $base_path && hypnotoad -s mojo.pl && hypnotoad mojo.pl"; exec('sh', '-c', $cmd) or die "Failed to execute shell command: $!"; } elsif ($pid > 0) { $c->render(text => 'Service restart command initiated.'); } else { $c->render(text => 'Failed to initiate restart command.', status => 500); } } 1;