Skip to content

Commit

Permalink
Run server command (ordinals#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Mar 21, 2022
1 parent db8d1b2 commit ac35b4b
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 9 deletions.
64 changes: 64 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
autotests = false

[dependencies]
anyhow = "1.0.56"
anyhow = { version = "1.0.56", features = ["backtrace"] }
axum = "0.4.8"
axum-server = "0.3.3"
bitcoin = "0.27.1"
Expand Down
6 changes: 4 additions & 2 deletions deploy/checkout
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

set -euxo pipefail

branch=$1

if [[ ! -d ord ]]; then
git clone https://github.com/casey/ord.git
fi

cd ord

git fetch origin
git checkout -B master
git reset --hard origin/master
git checkout -B $1
git reset --hard origin/$1
./deploy/setup
6 changes: 4 additions & 2 deletions deploy/ord.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ StartLimitIntervalSec=10m

[Service]
WorkingDirectory=/var/lib/ord
Environment="RUST_LOG=info"
Environment=RUST_BACKTRACE=1
Environment=RUST_LOG=info
ExecStart=/usr/local/bin/ord \
--index-size 1TiB \
--rpc-url 127.0.0.1:8332 \
--cookie-file /var/lib/bitcoind/.cookie \
index
server \
--port 8000

# Process management
####################
Expand Down
3 changes: 2 additions & 1 deletion deploy/setup
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ fi
source ~/.cargo/env

cargo build --release
cp target/release/ord /usr/local/bin/ord

id --user bitcoin || useradd --system bitcoin
id --user ord || useradd --system ord
Expand All @@ -31,5 +30,7 @@ setfacl -m ord:r /var/lib/bitcoind/.cookie

cp deploy/ord.service /etc/systemd/system/
systemctl daemon-reload
systemctl stop ord
cp target/release/ord /usr/local/bin/ord
systemctl enable ord
systemctl restart ord
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ watch +args='ltest':
install-dev-deps:
cargo install cargo-criterion

deploy:
deploy branch='master':
ssh [email protected] mkdir -p deploy
rsync -avz deploy/checkout [email protected]:deploy/checkout
ssh [email protected] 'cd deploy && ./checkout'
ssh [email protected] 'cd deploy && ./checkout {{branch}}'

status:
ssh [email protected] systemctl status bitcoind
Expand Down
2 changes: 1 addition & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Index {
let sleep_until = self.sleep_until.get();

if sleep_until > now {
std::thread::sleep(sleep_until - now);
thread::sleep(sleep_until - now);
}

self
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use {
cell::Cell,
cmp::Ordering,
collections::VecDeque,
env,
fmt::{self, Display, Formatter},
io,
net::ToSocketAddrs,
Expand All @@ -33,6 +34,7 @@ use {
atomic::{self, AtomicU64},
Arc, Mutex,
},
thread,
time::{Duration, Instant},
},
tokio::runtime::Runtime,
Expand Down Expand Up @@ -86,6 +88,12 @@ fn main() {

if let Err(error) = Arguments::parse().run() {
eprintln!("error: {}", error);
if env::var_os("RUST_BACKTRACE")
.map(|val| val == "1")
.unwrap_or_default()
{
eprintln!("{}", error.backtrace());
}
process::exit(1);
}
}

0 comments on commit ac35b4b

Please sign in to comment.