类似Nginx程序一样,使用service来设置启动和关闭
1. 创建一个服务文件
在目录 "/etc/systemd/system/" 下创建 myapp.service 文件
2. 将myapp.service写入如下内容
[Unit]
Description=My Custom Application
[Service]
ExecStart=/path/to/your/application # 替换为你的应用程序路径
WorkingDirectory=/path/to/your/working/directory # 替换为应用程序的工作目录
User=youruser # 替换为运行应用程序的用户
Restart=on-failure
[Install]
WantedBy=multi-user.target
3. 重新加载systemd管理器
systemctl daemon-reload
4. 设置开机启动并启动
systemctl enable myapp.service
systemctl start myapp.service