Skip to content

Instantly share code, notes, and snippets.

@mariodian
Last active December 5, 2016 10:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mariodian/bf42adc0f374ddfdc9c1979da72211bb to your computer and use it in GitHub Desktop.
Save mariodian/bf42adc0f374ddfdc9c1979da72211bb to your computer and use it in GitHub Desktop.
OpenBazaar sysv service
#! /bin/bash
### BEGIN INIT INFO
# Provides: openbazaar
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop openbazaar server
# Description: Start the openbazaar server as a specified user
### END INIT INFO
# Copy this script to /etc/init.d
# "chmod 755 openbazaar" so you can run it as an ordinary user
# Usage: "sudo service openbazaar start/stop"
# Edit these
USER=ubuntu
DIR=/home/$USER/OpenBazaar-Server
IP='0.0.0.0'
. /lib/lsb/init-functions
is_running () {
ps aux | grep -v grep | grep -v $0 | grep -v service | grep openbazaar | wc -m
}
do_start () {
if [ "$(is_running)" -eq 0 ]; then
# Run as specified user
# cd to $DIR because OB has a bug while running with absolute path
su - $USER -s /bin/sh -c "cd $DIR && python openbazaard.py start -da $IP"
else
log_action_msg "OpenBazaar Server is already running..."
fi
}
do_stop () {
if [ "$(is_running)" -eq 0 ]; then
log_action_msg "OpenBazaar Server is not running..."
else
su - $USER -s /bin/sh -c "cd $DIR && python openbazaard.py stop"
fi
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment