Install code-server on debian: Difference between revisions

From Daxtech
(Created page with ",")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
,
==== Management script ====
<syntaxhighlight lang="bash">
nano /usr/local/bin/code-serverctl
</syntaxhighlight><syntaxhighlight lang="bash" line="1">
#!/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
 
</syntaxhighlight><syntaxhighlight lang="bash">
chmod +x /usr/local/bin/code-serverctl
 
</syntaxhighlight>
 
==== Install code-server by download .deb ====
<syntaxhighlight>
./code-serverctl upgrade
</syntaxhighlight>
 
==== Create systemd config ====
<syntaxhighlight>
nano /etc/systemd/system/code-server-01.service
</syntaxhighlight><syntaxhighlight lang="bash">
[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
 
</syntaxhighlight>
 
==== Create config file for 01 instance ====
<syntaxhighlight lang="bash">
mkdir /etc/code-server
nano /etc/code-server/code-server-ide01.yaml
</syntaxhighlight><syntaxhighlight line="1">
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
 
 
</syntaxhighlight>

Latest revision as of 09:37, 12 January 2024

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