Skip to content

Commit

Permalink
Refs: skycoin#171 Improving the handling of the /etc/default/skywire …
Browse files Browse the repository at this point in the history
…file and start up scripts
  • Loading branch information
stdevPavelmc committed Nov 25, 2018
1 parent 21745b6 commit 343b392
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 17 deletions.
12 changes: 11 additions & 1 deletion static/script/manager_start
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

### SkyWire Start script, manager & node

# local vars
SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script

# check for the env vars
if [ ! -f /etc/default/skywire ] ; then
# does not exist, link it
ln -s /usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/skywire.defaults /etc/default/skywire
ln -s ${SKYWIRE_UNIX_SCRIPTS}/skywire.defaults /etc/default/skywire
else
# check it, if a file remove and link
if [ ! -h /etc/default/skywire ] ; then
# not a link, remove it and link
rm /etc/default/skywire
ln -s ${SKYWIRE_UNIX_SCRIPTS}/skywire.defaults /etc/default/skywire
fi
fi

# now load it
Expand Down
12 changes: 11 additions & 1 deletion static/script/node_start
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

### SkyWire Start script, only node

# local vars
SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script

# check for the env vars
if [ ! -f /etc/default/skywire ] ; then
# does not exist, link it
ln -s /usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/skywire.defaults /etc/default/skywire
ln -s ${SKYWIRE_UNIX_SCRIPTS}/skywire.defaults /etc/default/skywire
else
# check it, if a file remove and link
if [ ! -h /etc/default/skywire ] ; then
# not a link, remove it and link
rm /etc/default/skywire
ln -s ${SKYWIRE_UNIX_SCRIPTS}/skywire.defaults /etc/default/skywire
fi
fi

# now load it
Expand Down
23 changes: 14 additions & 9 deletions static/script/start
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static
if [ ! -f /etc/default/skywire ] ; then
# does not exist, link it
ln -s ${SKYWIRE_UNIX_SCRIPTS}/skywire.defaults /etc/default/skywire
fi
else
# check it, if not a link remove and link
if [ ! -h /etc/default/skywire ] ; then
# not a link, remove it and link
rm /etc/default/skywire
ln -s ${SKYWIRE_UNIX_SCRIPTS}/skywire.defaults /etc/default/skywire
fi
fi

# now load it
. /etc/default/skywire
Expand All @@ -19,21 +26,19 @@ fi
# vary in the future (dhcp|static_interface|static-interface.d/*)
function get_mode() {
# get the IP
local IP=`ifconfig eth0 | grep "inet " | awk '{ print $2 }'`
# extract the last digit
local last=`echo $IP | rev | cut -d "." -f1 | rev`
local IP=`hostname -I | awk '{ print $1 }'`

# output the needed argument
if [ "$last" == "2" ] ; then
# we are in a manager miner
# check if we are on a manager or a node
if [ "$IP" == "$MANAGER_IP" ] ; then
# we are in a manager
echo "manager"
else
# we are in a miner
# we are in a node
echo "node"
fi
}

# now we call it.
RUN_MODE=$(get_mode)
echo "Starting node in '$RUN_MODE' mode"
echo "Starting skywire in '$RUN_MODE' mode"
${SKYWIRE_UNIX_SCRIPTS}/${RUN_MODE}_start
29 changes: 27 additions & 2 deletions static/script/stop
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static
if [ ! -f /etc/default/skywire ] ; then
# does not exist, link it
ln -s ${SKYWIRE_UNIX_SCRIPTS}/skywire.defaults /etc/default/skywire
else
# check it, if not a link remove and link
if [ ! -h /etc/default/skywire ] ; then
# not a link, remove it and link
rm /etc/default/skywire
ln -s ${SKYWIRE_UNIX_SCRIPTS}/skywire.defaults /etc/default/skywire
fi
fi

# now load it
Expand All @@ -18,14 +25,32 @@ fi
# kill manager
if [ -f "$Manager_Pid_FILE" ] ; then
pkill -F "$Manager_Pid_FILE"
echo "Manager killed"
pid=`cat $Manager_Pid_FILE`
echo "Manager runnig, pid $pid, killing it"
rm "$Manager_Pid_FILE"
fi

# kill node
if [ -f "$Node_Pid_FILE" ] ; then
pkill -F "$Node_Pid_FILE"
echo "Node killed"
pid=`cat $Node_Pid_FILE`
echo "Node runnig, pid $pid, killing it"
rm "$Node_Pid_FILE"
fi

# try harder if the service was not started by the default way
# find manager
PID=`ps aux | grep manager | grep -v grep | grep 'web-dir' | awk '{print $2}'`
if [ "$PID" != "" ] ; then
echo "Manager runnig, pid $PID, killing it"
`which kill` -9 $PID
fi

# find manager
PID=`ps aux | grep node | grep -v grep | grep 'connect-manager' | awk '{print $2}'`
if [ "$PID" != "" ] ; then
echo "Node runnig, pid $PID, killing it"
`which kill` -9 $PID
fi


27 changes: 23 additions & 4 deletions static/script/update
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

# Script to update the skywire apps, beware it will stop and start them.

# local vars
SKYWIRE_UNIX_SCRIPTS=/usr/local/skywire/go/src/github.com/skycoin/skywire/static/script

# check for the env vars
if [ ! -f /etc/default/skywire ] ; then
# does not exist, link it
ln -s /usr/local/skywire/go/src/github.com/skycoin/skywire/static/script/skywire.defaults /etc/default/skywire
ln -s ${SKYWIRE_UNIX_SCRIPTS}/skywire.defaults /etc/default/skywire
else
# check it, if not a link remove and link
if [ ! -h /etc/default/skywire ] ; then
# not a link, remove it and link
rm /etc/default/skywire
ln -s ${SKYWIRE_UNIX_SCRIPTS}/skywire.defaults /etc/default/skywire
fi
fi

# now load it
Expand Down Expand Up @@ -39,7 +49,7 @@ else
# reset any local change
git reset --hard

# extra cleanning: remove any untrackef files or folders
# extra cleanning: remove any un-traced files or folders
git clean -f -d

# getting the changes
Expand All @@ -51,8 +61,17 @@ else
echo "[${DATE}] Build and install from a github update." >> ${INSTALL_LOG}
go install -v ./... >> ${INSTALL_LOG}

# restarting services
${SKYWIRE_START_CMD}
# start service depending of the IP and declared manager ip
MYIP=`hostname -I | awk '{ print $1 }'`
if [ "$MYIP" == "$MANAGER_IP"] ; then
# we are on a manger
echo "Starting skywire manager service..."
$SKYWIRE_DIR/static/script/manager_start
else
# we are on a node
echo "Starting skywire node service..."
$SKYWIRE_DIR/static/script/node_start
fi

# user feedback
echo "Done, SkyWire updated and runnig."
Expand Down

0 comments on commit 343b392

Please sign in to comment.