# 系统条件
| systemd: Ubuntu >= 16, CentOS >= 7, Arch, Debian >= 7 | |
| upstart: Ubuntu <= 14 | |
| launchd: Darwin, MacOSx | |
| openrc: Gentoo Linux, Arch Linux | |
| rcd: FreeBSD | |
| systemv: Centos 6, Amazon Linux | |
| PM2 > 2.2.x | 
创建开机启动脚本文件
| pm2 startup | 
或者指定系统平台
| pm2 startup [ubuntu | ubuntu14 | ubuntu12 | centos | centos6 | arch | oracle | amazon | macos | darwin | freesd | systemd | systemv | upstart | launchd | rcd | openrc] | 
保持当前进程
| pm2 save | 
禁止开机启动
| pm2 unstartup | 
或者指定系统平台
| pm2 unstartup [ubuntu | ubuntu14 | ubuntu12 | centos | centos6 | arch | oracle | amazon | macos | darwin | freesd | systemd | systemv | upstart | launchd | rcd | openrc] | 
用户权限的开机启动
| pm2 startup ubuntu -u www --hp /home/ubuntu | 
更新开机启动脚本文件
| pm2 unstartup | |
| pm2 startup | |
| 默认-u 是root用户 | 
我们这里用到的命令是:
| pm2 startup systemd -u apache --hp /var/www | 
参数含义解释:
| - systemd是用daemon的方式启动,systemd是Linux 系统工具,用来启动守护进程,已成为大多数发行版的标准配置。 | |
| -u 指定pm2服务是用户apache启动的 | |
| --hp home path 路径 ,/var/www这是apache用户的家目录 | |
| /etc/passwd中的apache行: | |
| apache:x:48:48:Apache:/var/www:/sbin/nologin | 
