基于Web的VSCode----Code Server
基于Web的VSCode----Code Server · Apr 12, 2019 clicks
直接下载(https://github.com/codercom/code-server/releases)了二进制包,然后解压。
首先要生成证书,原因是如果不是https的网站,浏览器会禁用剪切板功能。虽然官方的二进制文件里集成了证书,但也是自签名的,有安全风险。
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ~/certs/MyKey.key -out ~/certs/MyCertificate.crt
然后运行在8248端口,访问密码 gululu
/home/jack/data/code-server -p 8248 -P gululu --cert=/home/jack/certs/MyCertificate.crt --cert-key=/home/jack/certs/MyKey.key /home/jack/myproj
参数说明:
Usage: code-server [options] 项目目录
Options:
-V, --version output the version number
--cert <value>
--cert-key <value>
-e, --extensions-dir <dir> Set the root path for extensions.
-d --user-data-dir <dir> Specifies the directory that user data is kept in, useful when running as root.
--data-dir <value> DEPRECATED: Use '--user-data-dir' instead. Customize where user-data is stored.
-h, --host <value> Customize the hostname. (default: "0.0.0.0")
-o, --open Open in the browser on startup.
-p, --port <number> Port to bind on. (default: 8443)
-N, --no-auth Start without requiring authentication.
-H, --allow-http Allow http connections.
-P, --password <value> Specify a password for authentication.
--bootstrap-fork <name> Used for development. Never set.
--fork <name> Used for development. Never set.
--extra-args <args> Used for development. Never set.
-h, --help output usage information
然后我想让它开机自动启动,而且也必须以指定用户(jack)运行
首先的在 /etc/init.d 下添加脚本,sudo vim /etc/init.d/code-server.sh
#!/bin/sh su -c '/home/jack/data/code-server -p 8248 -P gululu --cert=/home/jack/certs/MyCertificate.crt --cert-key=/home/jack/certs/MyKey.key /home/jack/work/myproj' jack
重点是“su -c '命令' 指定用户”
最后使之生效
cd /etc/init.d sudo udpate-rc.local code-server.sh defaults 100
======================================================
后记:最后发现不work, 改用supervisor了
sudo vim /etc/supervisor/conf.d/vscode.conf
文件内容
[program:vscode] directory=/home/jack command=/home/jack/src/code-server1.696-vsc1.33.0-linux-x64/code-server -p 8248 -P hululu --cert=/home/jack/certs/MyCertificate.crt --cert-key=/home/jack/certs/MyKey.key /home/jack/work/myproj autostart=true autorestart=true startsecs=10 stdout_logfile=/var/log/supervisor/vscode.log stdout_logfile_maxbytes=1MB stdout_logfile_backups=10 stdout_capture_maxbytes=1MB stderr_logfile=/var/log/supervisor/vscode_err.log stderr_logfile_maxbytes=1MB stderr_logfile_backups=10 stderr_capture_maxbytes=1MB user = jack environment = HOME="/home/jack", USER="jack"
然后重载 supervisor
sudo supervisorctl reload