@wendongfly/myhi 1.3.25 → 1.3.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/daemon.js CHANGED
@@ -93,7 +93,7 @@ async function doUpgrade() {
93
93
  try {
94
94
  const cmd = process.platform === 'win32'
95
95
  ? 'npm.cmd install -g @wendongfly/myhi@latest'
96
- : 'sudo npm install -g @wendongfly/myhi@latest 2>&1 || npm install -g @wendongfly/myhi@latest 2>&1';
96
+ : 'npm install -g @wendongfly/myhi@latest 2>&1 || sudo npm install -g @wendongfly/myhi@latest 2>&1';
97
97
  const output = execSync(cmd, { timeout: 120000, encoding: 'utf8' });
98
98
  log('升级完成: ' + output.trim().split('\n').pop());
99
99
  } catch (e) {
package/bin/myhi.js CHANGED
@@ -731,6 +731,21 @@ WantedBy=multi-user.target
731
731
  console.log(` Port: ${port}`);
732
732
  console.log(` WorkingDirectory: ${cwd}`);
733
733
  console.log(` ExecStart: ${myhiBin} -d`);
734
+
735
+ // 配置 sudoers 让服务用户可以自升级和重启
736
+ if (user !== 'root') {
737
+ const sudoersFile = `/etc/sudoers.d/myhi-${user}`;
738
+ const npmBin = (() => { try { return ex('which npm', { encoding: 'utf8' }).trim(); } catch { return '/usr/bin/npm'; } })();
739
+ const sudoersContent = `# myhi: allow ${user} to upgrade and restart service\n${user} ALL=(ALL) NOPASSWD: ${npmBin} install -g @wendongfly/myhi*\n${user} ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart myhi.service\n${user} ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop myhi.service\n`;
740
+ try {
741
+ writeFileSync(sudoersFile, sudoersContent, { mode: 0o440 });
742
+ console.log(`[myhi] 已配置 sudoers: ${sudoersFile}`);
743
+ } catch {
744
+ console.log(`[myhi] 提示: 如需 Web 端升级功能,请手动配置 sudoers:`);
745
+ console.log(` echo '${user} ALL=(ALL) NOPASSWD: ${npmBin} install -g @wendongfly/myhi*' | sudo tee ${sudoersFile}`);
746
+ }
747
+ }
748
+
734
749
  console.log('');
735
750
  try {
736
751
  ex('systemctl daemon-reload', { stdio: 'inherit' });
@@ -741,6 +756,7 @@ WantedBy=multi-user.target
741
756
  console.log(' 查看状态: systemctl status myhi.service');
742
757
  console.log(' 查看日志: journalctl -u myhi -f');
743
758
  console.log(' 停止服务: sudo systemctl stop myhi.service');
759
+ console.log(' Web 端升级: 会话页 ⬆ 按钮一键升级');
744
760
  } catch (e) {
745
761
  console.log('[myhi] systemctl 执行失败,请手动运行:');
746
762
  console.log(' sudo systemctl daemon-reload');
@@ -755,6 +771,8 @@ WantedBy=multi-user.target
755
771
  } catch {}
756
772
  try {
757
773
  unlinkSync(serviceFile);
774
+ // 清理 sudoers
775
+ try { unlinkSync(`/etc/sudoers.d/myhi-${user}`); } catch {}
758
776
  ex('systemctl daemon-reload', { stdio: 'pipe' });
759
777
  console.log('[myhi] 已卸载 systemd 服务');
760
778
  } catch (e) {