应用场景
随着人工智能迅速崛起,越来越多便利的开发工具出现了,Cursor作为搭载了gpt-3模型的代码编辑器,有着它一定的优势。在Windows系统下的Cursor安装起来很方便,但是在Linux下我还是决定做一些改动,最主要的原因是如果不做配置,程序运行默认是前台运行而且会打印日志到标准输出,而我希望他在后台运行并将日志输出到指定的文件,方便开发使用。
问题描述
在Cursor官网下载Linux系统的应用是AppImage格式的可执行文件,正常来说这类文件本身就是应用文本体,可以直接执行,下载地址为:
https://dl.todesktop.com/230313mzl4w4u92/linux/appImage/x64
下载完成以后,将AppImage格式的可执行文件放到/usr/local/share/cursor/目录下,运行时可能会显示缺少libfuse.so.2这个库,只需要安装即可。
sudo apt-get install libfuse-dev
安装完成后,直接运行AppImage文件,会在前台运行,看到的是这样的:
就算是加上‘&’让其后台运行,程序也会打印信息到标准输出的终端上,于是我马上想到让程序运行时输出重定向到一个文件中即可。
解决方案
在 /etc/init.d 中新建新建一个文件用于初始化日志保存的文件,然后再让Cursor后台运行并重定向输出到日志文件中。
1. 先再 /etc/init.d 中新建一个文件,赋予权限
:~$ sudo touch /etc/init.d/cursor-edit
:~$ sudo chmod 755 /etc/init.d/cursor-edit
2. 在文件中写入启动脚本
:~$ sudo vi /etc/init.d/cursor-edit
#!/bin/bash
LOG_DIR=/tmp/cursor/logs
APP=/usr/local/share/cursor/Cursor-0.2.7.AppImage # 写上自己的路径
# check if /tmp/cursor/logs exists, create it if not
IFS='/' read -ra dirs <<< "$LOG_DIR"
cur_path=""
for dir in "${dirs[@]}"
do
if [ ! -z "$dir" ]; then
cur_path="$cur_path/$dir"
if [ ! -d "$curpath" ]; then
# Create if it does not exist
mkdir -p $cur_path
fi
fi
done
# check if logs/run.log exists, create it if not
if [ ! -f "/tmp/cursor/logs/run.log" ]; then
touch /tmp/cursor/logs/run.log
fi
# start cursor in background and redirect stdout to run.log
nohup $APP > /tmp/cursor/logs/run.log 2>&1 &
※注意:如果在官网下载到的版本和我版本不一样要更改可执行AppImage文件的名称。
3. 将启动脚本软链接到 /usr/local/bin 目录下
:~$ sudo ln -s /etc/init.d/cursor-edit /usr/local/bin/cursor
这个时候就基本完成了,在终端输出命令cursor就可以直接打开编辑器了!
如果要查看cursor的日志信息可以使用命令
:~$ cat /tmp/cursor/logs/run.log