1.现在本地添加代码
在本地添加代码。新建了ApiController。
image.png
内容如下:
import Vapor
struct ApiController: RouteCollection {
func boot(routes: RoutesBuilder) throws {
let api = routes.grouped("api", "menu")
api.get(use: queryAll)
api.post(use: add)
api.delete(":id", use: delete)
api.put(use: update)
}
func queryAll(_ req: Request) -> String {
return "查询所有数据"
}
func update(_ req: Request) -> String {
return "更新数据"
}
func add(_ req: Request) -> String {
return "添加数据"
}
func delete(_ req: Request) -> String {
return "删除数据"
}
}
在routes.swift中,修改成如下内容
import Vapor
func routes(_ app: Application) throws {
let api = ApiController()
try app.register(collection: api)
}
修改好代码后,提交代码到GitHub。
2.服务端拉取最新代码
使用git拉取最新代码
yuhua@sweet-story-2:~/SampleCode$ git pull
remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 8 (delta 1), reused 8 (delta 1), pack-reused 0
Unpacking objects: 100% (8/8), done.
From https://github.com/flywo/SampleCode
46dd7a2..542ec70 master -> origin/master
Updating 46dd7a2..542ec70
error: The following untracked working tree files would be overwritten by merge:
Package.resolved
Please move or remove them before you merge.
Aborting
提示Package.resolved有冲突,这个文件不重要,直接删除掉服务器上的该文件,然后重新拉取:
yuhua@sweet-story-2:~/SampleCode$ rm -rf Package.resolved
yuhua@sweet-story-2:~/SampleCode$ git pull
Updating 46dd7a2..542ec70
Fast-forward
Package.resolved | 176 ++++++++++++++++++++++++++++
Sources/App/Controllers/ApiController.swift | 34 ++++++
Sources/App/routes.swift | 5 +-
3 files changed, 212 insertions(+), 3 deletions(-)
create mode 100644 Package.resolved
create mode 100644 Sources/App/Controllers/ApiController.swift
接下来重新构建。
swift build -c release
3. supervisor重新加载配置文件
重新加载supervisor配置文件
sudo supervisorctl update
4.使用postman查看是否成功
image.pngimage.png
image.png
image.png
5.更多supervisor命令
1.更新配置
sudo supervisorctl update
2.查看进程状态
sudo supervisorctl status
3.启动某个进程
sudo supervisorctl start xxx
4.停止某个进程
sudo supervisorctl stop xxx
5.停止所有进程
sudo supervisorctl stop all
6.重启某个进程
sudo supervisorctl restart xxx
7.重新读取配置文件
sudo supervisorctl reread
8.添加配置文件
sudo supervisorctl add xxx
9.启动supervisorctl
sudo supervisorctl -c /etc/supervisor/supervisord.conf
10.关闭supervisorctl
sudo supervisorctl shutdown
11.重启supervisorctl
sudo supervisorctl reload
12.如果报错:No such file or directory: file: /usr/lib/python2.7/socket.,输入下面命令即可
sudo supervisord -c /etc/supervisor/supervisord.conf
sudo supervisorctl -c /etc/supervisor/supervisord.conf
网友评论