美文网首页
Swift Perfect - 使用 systemd 命令服务器

Swift Perfect - 使用 systemd 命令服务器

作者: LeeCen | 来源:发表于2018-07-24 17:06 被阅读87次
image.png

引言

Perfect 是一个完整和强大的工具箱,框架和应用程序服务器为Linux,iOS和MacOS(OS X)。它提供了Swift工程师为开发面向客户端和服务器端应用程序的Swift编程语言开发轻量级,可维护,可扩展的应用程序和其他REST服务所需的一切。
接下来几篇我对 Perfect 框架进行记录。感兴趣的可以看:
Swift Perfect - Ubuntu 服务器部署
Swift Perfect - 七牛上传文件
Swift Perfect - iOS消息推送(APNs)之获取 APNs 授权码
Swift Perfect - 使用 systemd 命令服务器项目后台运行
Ubuntu 环境下 Nginx 的安装部署
Swift Perfect - Nginx 配置 HTTPS 服务器

创建二进制,输出打印就是二进制文件路径

swift build -c release

swift build

image.png image.png
创建服务启动.service配置文件

vi /etc/systemd/system/iRent.service

.service 配置文件

[Unit]
Description=iRent

[Service]
Type=simple
WorkingDirectory=/root/iRent/.build/x86_64-unknown-linux/release/  #上面创建二进制,输出打印就是二进制文件路径
ExecStart=/root/iRent/.build/x86_64-unknown-linux/release/iRent  #上面创建二进制,输出打印就是二进制文件路径
Restart=always
PIDFile=/var/run/iRent.pid

[Install]
WantedBy=multi-user.target

文件保存后请设置该文件权限:

chmod +x /etc/systemd/system/iRent.service
chmod 755 /etc/systemd/system/iRent.service

启用服务

sudo systemctl enable iRent.service

image.png
开始服务

sudo systemctl start iRent.service

image.png
检查服务是否启动成功

netstat -tnlp |grep iRent

image.png
停止服务

sudo systemctl stop iRent.service

禁用服务

sudo systemctl disable iRent.service

学习资料链接

Perfect 中文文档库: Ubuntu 16.04:系统服务安装指南
Linux环境下的Swift WebServer部署
使用 systemd 命令管理服务(英文版)

相关文章

网友评论

      本文标题:Swift Perfect - 使用 systemd 命令服务器

      本文链接:https://www.haomeiwen.com/subject/vidymftx.html