orztv commited on
Commit
ddbcf92
·
1 Parent(s): 395af2d
Files changed (3) hide show
  1. src/remix.sh +3 -69
  2. src/sshx.tsx +65 -0
  3. src/startup.sh +1 -3
src/remix.sh CHANGED
@@ -11,76 +11,10 @@ cd ${HOMEDIR}/${REMIX_NAME}
11
 
12
  # 安装依赖并构建
13
  pnpm install
 
14
 
15
- # 创建 sshx 路由文件
16
- cat << EOF > app/routes/sshx.tsx
17
- import { useState, useEffect } from 'react';
18
- import { json, ActionFunction } from '@remix-run/node';
19
- import { useLoaderData, Form, useSubmit } from '@remix-run/react';
20
- import { spawn } from 'child_process';
21
-
22
- let sshxProcess: any = null;
23
- let sshxOutput = '';
24
-
25
- export const loader = async () => {
26
- return json({ status: sshxProcess ? 'running' : 'stopped', output: sshxOutput });
27
- };
28
-
29
- export const action: ActionFunction = async ({ request }) => {
30
- const formData = await request.formData();
31
- const action = formData.get('action');
32
-
33
- if (action === 'start' && !sshxProcess) {
34
- sshxProcess = spawn('${HOMEDIR}/sshx/sshx', []);
35
- sshxProcess.stdout.on('data', (data: Buffer) => {
36
- sshxOutput += data.toString();
37
- });
38
- sshxProcess.stderr.on('data', (data: Buffer) => {
39
- sshxOutput += data.toString();
40
- });
41
- return json({ status: 'started' });
42
- } else if (action === 'stop' && sshxProcess) {
43
- sshxProcess.kill();
44
- sshxProcess = null;
45
- return json({ status: 'stopped' });
46
- }
47
-
48
- return json({ error: 'Invalid action' }, { status: 400 });
49
- };
50
-
51
- export default function Sshx() {
52
- const { status, output } = useLoaderData();
53
- const submit = useSubmit();
54
- const [localOutput, setLocalOutput] = useState(output);
55
-
56
- useEffect(() => {
57
- const interval = setInterval(() => {
58
- submit(null, { method: 'get', replace: true });
59
- }, 1000);
60
- return () => clearInterval(interval);
61
- }, [submit]);
62
-
63
- useEffect(() => {
64
- setLocalOutput(output);
65
- }, [output]);
66
-
67
- return (
68
- <div>
69
- <h1>SSHX Control</h1>
70
- <p>Status: {status}</p>
71
- <Form method="post">
72
- <button type="submit" name="action" value="start">Start SSHX</button>
73
- </Form>
74
- <Form method="post">
75
- <button type="submit" name="action" value="stop">Stop SSHX</button>
76
- </Form>
77
- <h2>Output:</h2>
78
- <pre>{localOutput}</pre>
79
- </div>
80
- );
81
- }
82
- EOF
83
-
84
  pnpm run build
85
 
86
  # 返回 HOMEDIR
 
11
 
12
  # 安装依赖并构建
13
  pnpm install
14
+ pnpm add @types/node @types/react @types/react-dom --save-dev
15
 
16
+ # 复制 sshx 路由文件
17
+ cp ${HOMEDIR}/sshx.tsx ${HOMEDIR}/${REMIX_NAME}/app/routes/sshx.tsx
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  pnpm run build
19
 
20
  # 返回 HOMEDIR
src/sshx.tsx ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState, useEffect } from 'react';
2
+ import { json, ActionFunction } from '@remix-run/node';
3
+ import { useLoaderData, Form, useSubmit } from '@remix-run/react';
4
+ import { spawn, ChildProcess } from 'child_process';
5
+
6
+ let sshxProcess: ChildProcess | null = null;
7
+ let sshxOutput = '';
8
+
9
+ export const loader = async () => {
10
+ return json({ status: sshxProcess ? 'running' : 'stopped', output: sshxOutput });
11
+ };
12
+
13
+ export const action: ActionFunction = async ({ request }) => {
14
+ const formData = await request.formData();
15
+ const action = formData.get('action');
16
+
17
+ if (action === 'start' && !sshxProcess) {
18
+ sshxProcess = spawn('/home/pn/sshx/sshx', []);
19
+ sshxProcess.stdout?.on('data', (data: Buffer) => {
20
+ sshxOutput += data.toString();
21
+ });
22
+ sshxProcess.stderr?.on('data', (data: Buffer) => {
23
+ sshxOutput += data.toString();
24
+ });
25
+ return json({ status: 'started' });
26
+ } else if (action === 'stop' && sshxProcess) {
27
+ sshxProcess.kill();
28
+ sshxProcess = null;
29
+ return json({ status: 'stopped' });
30
+ }
31
+
32
+ return json({ error: 'Invalid action' }, { status: 400 });
33
+ };
34
+
35
+ export default function Sshx() {
36
+ const { status, output } = useLoaderData<{ status: string; output: string }>();
37
+ const submit = useSubmit();
38
+ const [localOutput, setLocalOutput] = useState(output);
39
+
40
+ useEffect(() => {
41
+ const interval = setInterval(() => {
42
+ submit(null, { method: 'get', replace: true });
43
+ }, 1000);
44
+ return () => clearInterval(interval);
45
+ }, [submit]);
46
+
47
+ useEffect(() => {
48
+ setLocalOutput(output);
49
+ }, [output]);
50
+
51
+ return (
52
+ <div>
53
+ <h1>SSHX Control</h1>
54
+ <p>Status: {status}</p>
55
+ <Form method="post">
56
+ <button type="submit" name="action" value="start">Start SSHX</button>
57
+ </Form>
58
+ <Form method="post">
59
+ <button type="submit" name="action" value="stop">Stop SSHX</button>
60
+ </Form>
61
+ <h2>Output:</h2>
62
+ <pre>{localOutput}</pre>
63
+ </div>
64
+ );
65
+ }
src/startup.sh CHANGED
@@ -1,10 +1,8 @@
1
  #!/bin/sh
2
 
3
- echo "$HOMEDIR"
4
-
5
  # 使用 PM2 启动 Remix 应用,并传递 PORT 环境变量
6
  cd ${HOMEDIR}/${REMIX_NAME}
7
  PORT=$PORT pm2 start npm --name "remix" -- start
8
- pm2 save
9
 
10
  # PM2 会保持前台运行,无需额外的命令来保持容器运行
 
1
  #!/bin/sh
2
 
 
 
3
  # 使用 PM2 启动 Remix 应用,并传递 PORT 环境变量
4
  cd ${HOMEDIR}/${REMIX_NAME}
5
  PORT=$PORT pm2 start npm --name "remix" -- start
6
+
7
 
8
  # PM2 会保持前台运行,无需额外的命令来保持容器运行