setDescription("生成框架的 systemd 配置文件");
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$path = $this->generate();
$output->writeln("成功生成 systemd 文件,位置:".$path."");
$output->writeln("有关如何使用 systemd 配置文件,请访问 `https://github.com/zhamao-robot/zhamao-framework/issues/36`");
return 0;
}
private function generate() {
$s = "[Unit]\nDescription=zhamao-framework Daemon\nAfter=rc-local.service\n\n[Service]\nType=simple";
$s .= "\nUser=" . exec("whoami");
$s .= "\nGroup=" . exec("groups | awk '{print $1}'");
$s .= "\nWorkingDirectory=" . getcwd();
global $argv;
$s .= "\nExecStart=".PHP_BINARY." {$argv[0]} server";
$s .= "\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\n";
@mkdir(getcwd() . "/resources/");
file_put_contents(getcwd() . "/resources/zhamao.service", $s);
return getcwd() . "/resources/zhamao.service";
}
}