设置开机自动运行 live-server

1查看本机live-server安装目录

root@tzktzk1-Lenovo-Gaming:/media# which live-server
/usr/local/bin/live-server
root@tzktzk1-Lenovo-Gaming:/media# node -v
v20.9.0
root@tzktzk1-Lenovo-Gaming:/media# npm -v
10.7.0

2.创建服务文件

sudo nano /etc/systemd/system/live-server-other.service

内容为:

[Unit]
Description=Live Server for /media/other

[Service]
ExecStart=/usr/local/bin/live-server /media/other --port=5500
WorkingDirectory=/media/other
Restart=always
User=tzktzk1
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

tzktzk1为登录用户的用户名

3.重新加载系统服务、启动服务

sudo systemctl daemon-reload
sudo systemctl start live-server-other

4.设置开机自启

sudo systemctl enable live-server-other

5.检查服务状态

sudo systemctl status live-server-other

6.如果遇到问题,可以查看服务的日志以获取更多信息:

journalctl -u live-server-other.service
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容