Install code-server on debian

From Daxtech

Management script

nano /usr/local/bin/code-serverctl
#!/bin/bash

# Daniele Callari

function status() {
        echo 'code-server-01 is' $(systemctl is-active code-server-01)
}

function start() {
        systemctl start code-server-01
}

function stop() {
        systemctl stop code-server-01
}

function upgrade() {
        VERSION="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/coder/code-server/releases/latest | sed 's:.*/::')"
        VERSION=${VERSION#?}
#             https://github.com/coder/code-server/releases/download/v4.7.1/code-server-4.7.1-amd64.rpm
        wget "https://github.com/coder/code-server/releases/download/v$VERSION/code-server_${VERSION}_amd64.deb"

        dpkg -i code-server_${VERSION}_amd64.deb
        rm code-server_${VERSION}_amd64.deb
}

case "$1" in
    start)   start ;;
    stop)    stop ;;
    status)  status;;
    restart) stop; start ;;
    upgrade) upgrade; stop; start;;
    *) printf "code-server controller\n\nusage: \n$0 start|stop|restart|upgrade|status\n\n" >&2
       exit 1
       ;;
esac
chmod +x /usr/local/bin/code-serverctl

Install code-server by download .deb

./code-serverctl upgrade

Create systemd config

nano /etc/systemd/system/code-server-01.service
[Unit]
Description=Web IDE 4 developers - instance #1 - https://github.com/coder/code-server
After=network.target
StartLimitIntervalSec=10
[Service]
Type=simple
Restart=always
RestartSec=5
User=www-data

ExecStart=/usr/bin/code-server --proxy-domain node01.wime.it --disable-telemetry --config /etc/code-server/code-server-ide01.yaml


[Install]
WantedBy=multi-user.target

Create config file for 01 instance

mkdir /etc/code-server
nano /etc/code-server/code-server-ide01.yaml
bind-addr: 0.0.0.0:9001
auth: password
password: THEPASSWORD
cert: /var/www/vhosts/certs/domain.dev/fullchain.pem
cert-key: /var/www/vhosts/certs/domain.dev/privkey.pem
cert-host: domain.dev
user-data-dir: /var/www/.code-server/userspace01