Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to remove lock files #2457

Closed
RichardLitt opened this issue Mar 10, 2016 · 11 comments
Closed

Add command to remove lock files #2457

RichardLitt opened this issue Mar 10, 2016 · 11 comments
Labels
kind/enhancement A net-new feature or improvement to an existing feature topic/commands Topic commands topic/repo Topic repo

Comments

@RichardLitt
Copy link
Member

We should have a command - ipfs repo repair or ipfs repo fsck - which removes lockfiles. See bug issue here.

@whyrusleeping
Copy link
Member

ipfs repo fsck has been planned. We should do that soon.

@whyrusleeping whyrusleeping added kind/enhancement A net-new feature or improvement to an existing feature topic/commands Topic commands topic/repo Topic repo labels Mar 11, 2016
@TheNain38
Copy link

I think that when starting IPFS, it should try to remove stale lock file, by searching if the a proccessus with the owner's PID exists, if it doesn't, then it should remove the repo.lock file and start normally

pfista added a commit to pfista/go-ipfs that referenced this issue Apr 20, 2016
Fixes ipfs#2457

License: MIT
Signed-off-by: Mike Pfister <pfista@gmail.com>
pfista added a commit to pfista/go-ipfs that referenced this issue Apr 20, 2016
Fixes ipfs#2457

License: MIT
Signed-off-by: Mike Pfister <pfista@gmail.com>
hackergrrl pushed a commit to hackergrrl/go-ipfs that referenced this issue Apr 28, 2016
* Adds repo fsck subcommand

Fixes ipfs#2457

License: MIT
Signed-off-by: Mike Pfister <pfista@gmail.com>

* Checks for error on file deletion

License: MIT
Signed-off-by: Mike Pfister <pfista@gmail.com>

* Checks if node is online

License: MIT
Signed-off-by: Mike Pfister <pfista@gmail.com>

* Update error checking

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* Prevents command from running while daemon is running

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* Add newline to command output message

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* removing superfluous error

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* Adds sharness test for repo fsck command

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* Ignore warning if file doesn't exist

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* Updating message output

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* adding debug statements

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* update and add fsck sharness tests

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* updating comments

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* Use printf in test

Using printf prevents a newline from being printed to the api test file. When
the newline was present, multiaddr threw errors  trying to parse the api address
to an integer since the newline character was present.

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* updating tests

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>

* removing commented code

License: MIT
Signed-off-by: Michael Pfister <pfista@gmail.com>
@scottscheper
Copy link

For the record, it's February 11, 2019 and I just experienced this issue.

Removing BOTH of these files solved it:

  1. ~/.ipfs/repo.lock
  2. ~/.ipfs/datastore/LOCK

@Stebalien
Copy link
Member

You should never need to do this at this point. If you do, something is wrong.

@Kubuxu
Copy link
Member

Kubuxu commented Feb 12, 2019

@sscheper which version of go-ipfs are you using?

@mrusme
Copy link

mrusme commented May 21, 2020

Ran into Error: resource temporarily unavailable inside a self-built Docker container that currently runs 0.5.1. Added rm -rf /data/ipfs/repo.lock /data/ipfs/datastore/LOCK to the very first line of the startup script, so that it always removes the locks that might still exist on the persistent storage from a previously running container. The daemon now starts again. However, if I dial into that container and try to perform an ipfs add -Q -r ./site (while the daemon is running within that container) it still shows Error: resource temporarily unavailable. Not exactly sure what's going on there, maybe someone here can provide further insights?

@Stebalien
Copy link
Member

I really wouldn't do that. It no longer matters if the lockfile exists unless a go-ipfs daemon has the lockfile open and locked. That would mean that the daemon is running.

Your second issue may be that ipfs is running but your IPFS node can't find and/or connect to it. I don't know what your exact setup is so I'm not sure why. If you'd like more help on this, please ask on https://discuss.ipfs.io.

@koxon
Copy link

koxon commented Nov 29, 2022

While running kubo IPFS on containers and network storage. I see that when a container is killed or fails, the lock files remains and prevent a new daemon from starting.

@xueshuai0922
Copy link

While running kubo IPFS on containers and network storage. I see that when a container is killed or fails, the lock files remains and prevent a new daemon from starting.在容器和网络存储上运行 kubo IPFS 时。我看到当容器被杀死或失败时,锁定文件会保留并阻止新的守护程序启动。

yes ,i meet a same problem,should kill lock first?

@koxon
Copy link

koxon commented Jan 1, 2024

How to remove the lock file when using Docker? I try to override the entrypoint in the dockerfile to perform the rm as root but I have no luck so far. Anyone managed to make this work when using Docker?

My repo.lock file is still owned by root which shouldn't be the case.

Also, can't we trap the SIGTERM signal and cleanup the lock file before shutting down?

@koxon
Copy link

koxon commented Jan 2, 2024

I've built my own entrypoint.sh and Dockerfile to deal with the repo.lock files. I also make use of ipfs startup script to deep clean.

I'd love some feedback.

Dockerfile:

FROM ipfs/kubo:latest

COPY 001-config.sh /container-init.d/001-config.sh

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

entrypoint.sh:

#!/bin/sh

trap stop SIGTERM SIGINT SIGQUIT SIGHUP ERR

start(){
    echo "Deleting lock files"
    rm -rf /data/ipfs/repo.lock /data/ipfs/datastore/LOCK /data/ipfs/blocks/.temp

    echo "Starting IPFS daemon as ipfs user"
    tini -- gosu ipfs /usr/local/bin/start_ipfs daemon --migrate=true --agent-version-suffix=docker
}

stop(){
   echo "Shutting down IPFS as ipfs user"
   tini -- gosu ipfs /usr/local/bin/ipfs shutdown

   exit
}

start

001-config.sh:

#!/bin/sh
set -ex

rm -rf /data/ipfs/repo.lock /data/ipfs/datastore/LOCK /data/ipfs/blocks/.temp

The locks files are removed in the entrypoint.sh which runs as root and again in the 001-config_efs.sh script that is executed by the ipfs daemon at startup as the user ipfs and not root. I take no chance!

It appears that my cluster has recovered and the repo.lock file has been removed since I updated my Docker image.

The entrypoint also attempt to shut down ipfs gracefully if it receives a SIGTERM. This is useful if you're running your task on AWS Fargate SPOT where your tasks can be shutdown by AWS with a 2 min warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A net-new feature or improvement to an existing feature topic/commands Topic commands topic/repo Topic repo
Projects
None yet
Development

No branches or pull requests

9 participants