# ERROR 400 on kopia server shutdown

**URL:** <https://kopia.discourse.group/t/error-400-on-kopia-server-shutdown/3106>\
**Category:** General Topics\
**Created:** [July 18, 2024, 2:06am UTC](https://kopia.discourse.group/t/error-400-on-kopia-server-shutdown/3106 "2024-07-18T02:06:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![compumatter](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/compumatter/32/1139_2.png) [@compumatter](https://kopia.discourse.group/u/compumatter)\
**Post date:** [July 18, 2024, 2:06am UTC](https://kopia.discourse.group/t/error-400-on-kopia-server-shutdown/3106/1 "2024-07-18T02:06:02Z")

</div>

Hello. I cannot figure out how to use kopia server shutdown gracefully using this command

```auto
/usr/bin/kopia server shutdown --address=http://0.0.0.0:$port --log-file=$log_file --config-file=$config_file -p $password --server-username=toast --server-password=abc123

```

I have attached a video to make clear my problem. I have tried other variations. Just can’t figure out what it’s looking for.

Thanks for weighing in on it. I’m stuck…

[![](https://global.discourse-cdn.com/free1/uploads/kopia/original/2X/2/2a7c922ce6116a7c57dfee556f1cb882add2798d.jpeg "kopia shutdown how") ](https://www.youtube.com/watch?v=hCwhYy2LY5w)

---

<div class="post-metadata">

**Author:** ![compumatter](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/compumatter/32/1139_2.png) [@compumatter](https://kopia.discourse.group/u/compumatter)\
**Post date:** [July 18, 2024, 3:13am UTC](https://kopia.discourse.group/t/error-400-on-kopia-server-shutdown/3106/2 "2024-07-18T03:13:15Z")

</div>

I still do not know the solution to this. However, for now I have used a workaround of creating a systemd service which uses kopia server start… so when I want to stop the service I need only run systemctl stop mykopiaservice to halt it. It would still be of value to have the proper solution for using the shutdown command so I may document it and others may also know it.

---

<div class="post-metadata">

**Author:** ![RipClaw2971](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/ripclaw2971/32/1171_2.png) [@RipClaw2971](https://kopia.discourse.group/u/RipClaw2971)\
**Post date:** [August 6, 2024, 1:59pm UTC](https://kopia.discourse.group/t/error-400-on-kopia-server-shutdown/3106/3 "2024-08-06T13:59:38Z")

</div>

It took me a while to figure it out. You need to use --server-control-username and --server-control-password instead of --server-username and --server-password.

But in order that this works you have to start the server with --disable-csrf-token-checks --server-control-username=username --server-control-password=password

Here is a systemd service file I wrote for kopia:

```auto
[Unit]
After=network.target

[Service]
WorkingDirectory=/root/
EnvironmentFile=/root/.config/kopia/var_file

ExecStart=/usr/bin/kopia server start --address=https://0.0.0.0:51515 --tls-cert-file=/root/kopia.crt --tls-key-file=/root/kopia.key --disable-csrf-token-checks --shutdown-grace-period=5s
ExecStop=/usr/bin/kopia server shutdown --address=https://127.0.0.1:51515 --server-cert-fingerprint=${SERVER_CERT_FINGERPRINT} --server-control-username=${KOPIA_SERVER_CONTROL_USER} --server-control-password=${KOPIA_SERVER_CONTROL_PASSWORD}

[Install]
WantedBy=default.target

```

The file with the environment variables looks like this:

```auto
KOPIA_SERVER_USERNAME=toast
KOPIA_SERVER_PASSWORD=test123

KOPIA_SERVER_CONTROL_USER=server-control
KOPIA_SERVER_CONTROL_PASSWORD=test456

SERVER_CERT_FINGERPRINT=15d48640afbdce495b012a71e4b5f294d6a944f9fc9c59ee485dc84655a6f846

```

---

<div class="post-metadata">

**Author:** ![compumatter](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/compumatter/32/1139_2.png) [@compumatter](https://kopia.discourse.group/u/compumatter)\
**Post date:** [August 8, 2024, 1:22am UTC](https://kopia.discourse.group/t/error-400-on-kopia-server-shutdown/3106/4 "2024-08-08T01:22:12Z")

</div>

Thanks for the reply. I’m being told --disable-csrf-token-checks is a no go so I’ve got to find another method

---

<div class="post-metadata">

**Author:** ![RipClaw2971](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/ripclaw2971/32/1171_2.png) [@RipClaw2971](https://kopia.discourse.group/u/RipClaw2971)\
**Post date:** [August 8, 2024, 6:56am UTC](https://kopia.discourse.group/t/error-400-on-kopia-server-shutdown/3106/5 "2024-08-08T06:56:26Z")

</div>

–disable-csrf-token-checks does not seem to be necessary. I tried it out and it is probably unnecessary. The commands also work without this parameter.

My corrected systemd service file now looks like this:

```auto
[Unit]
After=network.target

[Service]
WorkingDirectory=/root/
EnvironmentFile=/root/.config/kopia/var_file

ExecStart=/usr/bin/kopia server start --address=https://0.0.0.0:51515 --tls-cert-file=/root/kopia.crt --tls-key-file=/root/kopia.key --shutdown-grace-period=5s
ExecStop=/usr/bin/kopia server shutdown --address=https://127.0.0.1:51515 --server-cert-fingerprint=${SERVER_CERT_FINGERPRINT} --server-control-username=${KOPIA_SERVER_CONTROL_USER} --server-control-password=${KOPIA_SERVER_CONTROL_PASSWORD}

[Install]
WantedBy=default.target

```

I have also written two small shell scripts to do status or refresh commands.

```auto
#!/bin/bash

source /root/.config/kopia/var_file

kopia server status --address="https://127.0.0.1:51515" --server-control-username=$KOPIA_SERVER_CONTROL_USER --server-control-password=$KOPIA_SERVER_CONTROL_PASSWORD --server-cert-fingerprint=$SERVER_CERT_FINGERPRINT

```

```auto
#!/bin/bash

source /root/.config/kopia/var_file

kopia server refresh --address="https://127.0.0.1:51515" --server-control-username=$KOPIA_SERVER_CONTROL_USER --server-control-password=$KOPIA_SERVER_CONTROL_PASSWORD --server-cert-fingerprint=$SERVER_CERT_FINGERPRINT

```

I will unify them into a wrapper script when I get round to it.

EDIT: I remember now why I used --disable-csrf-token-checks in my service file. It is required to monitor my backups via Uptime Kuma. With the checks in place Uptime Kuma is not able to access the API.

---

<div class="post-metadata">

**Author:** ![compumatter](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/compumatter/32/1139_2.png) [@compumatter](https://kopia.discourse.group/u/compumatter)\
**Post date:** [August 12, 2024, 7:53pm UTC](https://kopia.discourse.group/t/error-400-on-kopia-server-shutdown/3106/6 "2024-08-12T19:53:26Z")

</div>

Thanks for the reply. Still no success getting refresh to work.

What does this file /root/.config/kopia/var\_file contribute to your script? Is that where your KOPIA\_SERVER\_CONTROL\_USERNAME, KOPIA\_SERVER\_CONTROL\_PASSWORD and SERVER\_CERT\_FINGERPRINT vals are being stored? Otherwise if it is the kopia repository config file which is json formated I would not expect the command “source” to work with the bash script.

Your thoughts.

---

<div class="post-metadata">

**Author:** ![RipClaw2971](https://yyz2.discourse-cdn.com/free1/user_avatar/kopia.discourse.group/ripclaw2971/32/1171_2.png) [@RipClaw2971](https://kopia.discourse.group/u/RipClaw2971)\
**Post date:** [August 15, 2024, 2:15pm UTC](https://kopia.discourse.group/t/error-400-on-kopia-server-shutdown/3106/7 "2024-08-15T14:15:58Z")

</div>

The file /root/.config/kopia/var\_file is indeed the file where the vars are stored. I use this file in in my service file a EnvironmentFile and in my bash script as source for those variables

The problem in your case seems that you mix up HTTP and HTTPS. If you start the server with a certficate it expects all requests via HTTPS.
