-1

我在我的在线(非本地)服务器上创建了一个 app.js,然后在终端中进行了 ssh:

$ node app.js

这使我的应用程序上线。现在我想通过上传新版本的 app.js 来更新我的代码,但我不能再修改替换它,因为它正在被节点使用(550 /public_html/foo/app.js:权限被拒绝)......怎么办我停止节点?pkill 节点不起作用,如另一个线程中所示。基本上我在安装express后启动了我的应用程序,然后当它运行时我安装了socket.io我不确定现在发生了什么。

- - -更新

[root@vps ~]# ps r
  PID TTY      STAT   TIME COMMAND
19350 pts/0    R+     0:00 ps r
[root@vps ~]# kill 19350 PID
-bash: kill: (19350) - No such process
-bash: kill: PID: arguments must be process or job IDs
[root@vps ~]# ps
  PID TTY          TIME CMD
 8987 pts/0    00:00:00 bash
19505 pts/0    00:00:00 ps
[root@vps ~]# ps aux | grep node
root     19551  0.0  0.0   7216   812 pts/0    S+   15:38   0:00 grep node
[root@vps ~]# kill -2 PID
-bash: kill: PID: arguments must be process or job IDs
[root@vps ~]# kill -0 PID
-bash: kill: PID: arguments must be process or job IDs
[root@vps ~]# kill 0 PID
-bash: kill: PID: arguments must be process or job IDs
[root@vps ~]# kill 19551 PID
-bash: kill: (19551) - No such process
-bash: kill: PID: arguments must be process or job IDs
[root@vps ~]# kill PID
-bash: kill: PID: arguments must be process or job IDs
[root@vps ~]# ps node
ERROR: Unknown user-defined format specifier "de".
********* simple selection *********  ********* selection by list *********
-A all processes                      -C by command name
-N negate selection                   -G by real group ID (supports names)
-a all w/ tty except session leaders  -U by real user ID (supports names)
-d all except session leaders         -g by session OR by effective group name
-e all processes                      -p by process ID
T  all processes on this terminal     -s processes in the sessions given
a  all w/ tty, including other users  -t by tty
g  OBSOLETE -- DO NOT USE             -u by effective user ID (supports names)
r  only running processes             U  processes for specified users
x  processes w/o controlling ttys     t  by tty
*********** output format **********  *********** long options ***********
-o,o user-defined  -f full            --Group --User --pid --cols --ppid
-j,j job control   s  signal          --group --user --sid --rows --info
-O,O preloaded -o  v  virtual memory  --cumulative --format --deselect
-l,l long          u  user-oriented   --sort --tty --forest --version
-F   extra full    X  registers       --heading --no-heading --context
                    ********* misc options *********
-V,V  show version      L  list format codes  f  ASCII art forest
-m,m,-L,-T,H  threads   S  children in sum    -y change -l format
-M,Z  security data     c  true command name  -c scheduling class
-w,w  wide output       n  numeric WCHAN,UID  -H process hierarchy
[root@vps ~]# ps -A
  PID TTY          TIME CMD
    1 ?        00:00:01 init
    2 ?        00:00:00 kthreadd/141
    3 ?        00:00:00 khelper/141
  100 ?        00:00:00 udevd
  477 ?        00:01:13 syslogd
  488 ?        00:00:00 sshd
  496 ?        00:00:00 xinetd
  542 ?        00:00:00 crond
  550 ?        00:00:00 saslauthd
  552 ?        00:00:00 saslauthd
 2348 ?        00:00:00 master
 2351 ?        00:00:00 qmgr
 3170 ?        00:00:00 mailmanctl
 3172 ?        00:00:22 python
 3173 ?        00:00:23 python
 3174 ?        00:00:22 python
 3175 ?        00:00:22 python
 3176 ?        00:00:22 python
 3177 ?        00:00:23 python
 3178 ?        00:00:22 python
 3179 ?        00:00:00 python
 3934 ?        00:00:58 clamd.virtualmi
 4209 ?        00:00:00 mysqld_safe
 4291 ?        00:00:40 mysqld
 4556 ?        00:00:07 perl
 4618 ?        00:00:00 lookup-domain-d
 5017 ?        00:00:02 proftpd
 5309 ?        00:03:48 named
 8985 ?        00:00:00 sshd
 8987 pts/0    00:00:00 bash
12463 ?        00:00:00 httpd
12464 ?        00:00:00 httpd
12909 ?        00:00:00 httpd
14474 ?        00:00:00 httpd
15616 ?        00:00:00 pickup
16609 ?        00:00:00 crond
16612 ?        00:00:00 freshclam-sleep
16615 ?        00:00:00 sleep
19668 ?        00:00:00 proftpd
20226 ?        00:00:00 sshd
20227 ?        00:00:00 sshd
20228 pts/0    00:00:00 ps
31970 ?        00:00:04 httpd
[root@vps ~]# ps r
  PID TTY      STAT   TIME COMMAND
20359 pts/0    R+     0:00 ps r
[root@vps ~]# ps r -C
ERROR: List of command names must follow -C.
[root@vps ~]# ps -H
  PID TTY          TIME CMD
 8987 pts/0    00:00:00 bash
20475 pts/0    00:00:00   ps
[root@vps ~]# kill -20475
-bash: kill: 20475: invalid signal specification
[root@vps ~]# kill 20475
-bash: kill: (20475) - No such process
[root@vps ~]# ps
  PID TTY          TIME CMD
 8987 pts/0    00:00:00 bash
20725 pts/0    00:00:00 ps
[root@vps ~]# ps ~/
ERROR: Garbage option.
    [root@vps ~]# ps
  PID TTY          TIME CMD
 8987 pts/0    00:00:00 bash
20745 pts/0    00:00:00 ps
[root@vps ~]# kill 20745
-bash: kill: (20745) - No such process
[root@vps ~]# ps node
ERROR: Unknown user-defined format specifier "de".
[root@vps ~]# ps aux | grep node
root     20909  0.0  0.0   7216   812 pts/0    S+   15:56   0:00 grep node
[root@vps ~]# kill poo
-bash: kill: poo: arguments must be process or job IDs
[root@vps ~]# kill -2  PID
-bash: kill: PID: arguments must be process or job IDs
[root@vps ~]# ps grep
ERROR: List of process IDs must follow p.
[root@vps ~]# kill grep node
-bash: kill: grep: arguments must be process or job IDs
-bash: kill: node: arguments must be process or job IDs
[root@vps ~]# ps grep node
ERROR: Process ID list syntax error.
[root@vps ~]# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  10372   640 ?        Ss   Apr04   0:01 init [3]      
root         2  0.0  0.0      0     0 ?        S    Apr04   0:00 [kthreadd/141]
root         3  0.0  0.0      0     0 ?        S    Apr04   0:00 [khelper/141]
root       100  0.0  0.0  12640   384 ?        S<s  Apr04   0:00 /sbin/udevd -d
root       477  0.0  0.0   5932   612 ?        Ds   Apr04   1:13 syslogd -m 0
root       488  0.0  0.0  62688   740 ?        Ss   Apr04   0:00 /usr/sbin/sshd
root       496  0.0  0.0  21664   596 ?        Ss   Apr04   0:00 xinetd -stayali
root       542  0.0  0.0  19728  1168 ?        Ss   Apr04   0:00 crond
root       550  0.0  0.0  48860  1276 ?        Ss   Apr04   0:00 /usr/sbin/sasla
root       552  0.0  0.0  48860  1264 ?        S    Apr04   0:00 /usr/sbin/sasla
root      2348  0.0  0.1  60300  2592 ?        Ss   Apr04   0:00 /usr/libexec/po
postfix   2351  0.0  0.1  60432  2512 ?        S    Apr04   0:00 qmgr -l -t fifo
mailman   3170  0.0  0.3  94488  7948 ?        Ss   Apr04   0:00 /usr/bin/python
mailman   3172  0.0  0.5  96664 10544 ?        S    Apr04   0:22 /usr/bin/python
mailman   3173  0.0  0.5  96648 10588 ?        S    Apr04   0:23 /usr/bin/python
mailman   3174  0.0  0.5  96672 10564 ?        S    Apr04   0:22 /usr/bin/python
mailman   3175  0.0  0.5  96668 10540 ?        S    Apr04   0:22 /usr/bin/python
mailman   3176  0.0  0.5  96620 10600 ?        S    Apr04   0:22 /usr/bin/python
mailman   3177  0.0  0.5  96820 10804 ?        S    Apr04   0:24 /usr/bin/python
mailman   3178  0.0  0.5  96668 10692 ?        S    Apr04   0:22 /usr/bin/python
mailman   3179  0.0  0.5  96668 10552 ?        S    Apr04   0:00 /usr/bin/python
nobody    3934  0.0  9.2 251908 194992 ?       Ssl  Apr04   0:58 clamd.virtualmi
root      4209  0.0  0.0  10784  1304 ?        S    Apr04   0:00 /bin/sh /usr/bi
mysql     4291  0.0  4.4 610420 93176 ?        Sl   Apr04   0:40 /usr/libexec/my
root      4556  0.0  2.9 132268 61100 ?        Ss   Apr04   0:07 /usr/bin/perl /
root      4618  0.0  2.4  83428 51644 ?        Ss   Apr04   0:00 /usr/libexec/we
nobody    5017  0.0  0.1  51936  2412 ?        Ss   Apr04   0:02 proftpd: (accep
named     5309  0.0  0.2 154864  4780 ?        Ssl  Apr04   3:48 /usr/sbin/named
root      8985  0.0  0.1  86084  3396 ?        Ss   09:24   0:00 sshd: root@pts/
root      8987  0.0  0.0  12088  1704 pts/0    Ss   09:24   0:00 -bash
apache   12463  0.0  0.5 254352 11248 ?        S    01:29   0:00 /usr/sbin/httpd
apache   12464  0.0  0.7 337608 15328 ?        S    01:29   0:00 /usr/sbin/httpd
apache   12909  0.0  0.7 337596 15652 ?        S    01:47   0:00 /usr/sbin/httpd
apache   14474  0.0  0.7 337592 15344 ?        S    02:57   0:00 /usr/sbin/httpd
postfix  15616  0.0  0.1  60372  2540 ?        S    14:19   0:00 pickup -l -t fi
root     16609  0.0  0.0  44856  1476 ?        S    15:00   0:00 crond
root     16612  0.0  0.0   8688  1172 ?        Ss   15:00   0:00 /bin/bash /usr/
root     16615  0.0  0.0   3812   484 ?        S    15:00   0:00 sleep 9732
root     21104  0.0  0.1  84768  3220 ?        Ss   15:58   0:00 sshd: unknown [
sshd     21105  0.0  0.0  64032  1564 ?        S    15:58   0:00 sshd: unknown [
root     21106  0.0  0.0  10744  1008 pts/0    R+   15:58   0:00 ps aux
root     31970  0.0  1.1 337448 23804 ?        Ss   Apr04   0:04 /usr/sbin/httpd
[root@vps ~]# ps aux node
ERROR: Unknown user-defined format specifier "de".
[root@vps ~]# ps aux | node
[stdin]:1
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND        ^^^
SyntaxError: Unexpected identifier
    at Object.<anonymous> ([stdin]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:532:25)
    at Socket.<anonymous> (node.js:154:11)
    at Socket.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:883:14
    at process._tickCallback (node.js:415:13)
[root@vps ~]# ps aux | g
-bash: g: command not found
[root@vps ~]# ps aux | r
-bash: r: command not found
[root@vps ~]# ps aux | r node
-bash: r: command not found
[root@vps ~]# ps auxr
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       477  0.0  0.0   5932   612 ?        Ds   Apr04   1:13 syslogd -m 0
root     21529  0.0  0.0  10744  1008 pts/0    R+   16:03   0:00 ps auxr
[root@vps ~]# ps aur
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     21755  0.0  0.0  10740   944 pts/0    R+   16:06   0:00 ps aur
[root@vps ~]# ps G
ERROR: Unsupported option (BSD syntax)
[root@vps ~]# ps -G
ERROR: List of real groups must follow -G.
[root@vps ~]# ps -G node
ERROR: Group name does not exist.
[root@vps ~]# kill app
-bash: kill: app: arguments must be process or job IDs
[root@vps ~]# kill app.js
-bash: kill: app.js: arguments must be process or job IDs
[root@vps ~]# ps grep node
ERROR: Process ID list syntax error.
[root@vps ~]# ps | grep node
[root@vps ~]# ps a | grep node
22021 pts/0    S+     0:00 grep node
[root@vps ~]# ps -p | grep node
ERROR: List of process IDs must follow -p.
[root@vps ~]# ps r | grep node
[root@vps ~]# ps t
  PID TTY      STAT   TIME COMMAND
 8987 pts/0    Ss     0:00 -bash
22241 pts/0    R+     0:00 ps t
[root@vps ~]# ps t | grep node
22265 pts/0    S+     0:00 grep node
[root@vps ~]# kill 22265
-bash: kill: (22265) - No such process
[root@vps ~]# kill ps | grep node
-bash: kill: ps: arguments must be process or job IDs
[root@vps ~]# ps l
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0  8987  8985  20   0  12088  1708 wait   Ss   pts/0      0:00 -bash
4     0 22545  8987  20   0   8652   896 -      R+   pts/0      0:00 ps l
[root@vps ~]# ps l | grep node
0     0 22589  8987  20   0   7216   808 pipe_w S+   pts/0      0:00 grep node
[root@vps ~]# kill -22545 PID
-bash: kill: 22545: invalid signal specification
[root@vps ~]# ps r | grep node
[root@vps ~]# ps -r | grep node
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
[root@vps ~]# ps l
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0  8987  8985  20   0  12088  1708 wait   Ss   pts/0      0:00 -bash
4     0 22718  8987  20   0   8652   900 -      R+   pts/0      0:00 ps l
[root@vps ~]# ps l
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0  8987  8985  20   0  12088  1708 wait   Ss   pts/0      0:00 -bash
4     0 22743  8987  20   0   8652   900 -      R+   pts/0      0:00 ps l
[root@vps ~]# kill 8987 PPID
-bash: kill: PPID: arguments must be process or job IDs
[root@vps ~]# ps pl
ERROR: Process ID list syntax error.
[root@vps ~]# ps p
ERROR: List of process IDs must follow p.
[root@vps ~]# ps f
  PID TTY      STAT   TIME COMMAND
 8987 pts/0    Ss     0:00 -bash
22935 pts/0    R+     0:00  \_ ps f
[root@vps ~]# ps j
 PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
 8985  8987  8987  8987 pts/0    23076 Ss       0   0:00 -bash
 8987 23076 23076  8987 pts/0    23076 R+       0   0:00 ps j
[root@vps ~]# 

我不明白 PID 似乎每次都在变化

4

1 回答 1

1

我建议您Upstart为您的节点应用程序创建一个脚本。如果这样做,您可以通过发出start,stoprestart命令来控制应用程序的生命周期。这样,您还可以将应用程序设置为在服务器启动时启动,如果应用程序意外终止,您还可以重新启动应用程序。有很多 nodejs 的 upstart 脚本示例,因此只需调整示例以适应您的环境即可。

于 2013-04-07T16:48:00.413 回答