forked from ghostchain/ghost-node
make the systemd unit file creation as a last step
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
7591be9d0b
commit
d12ecf15ec
@ -273,55 +273,6 @@ if [[ $MAKE_GLOBAL = true ]]; then
|
|||||||
echo "[+] specification '$SPECIFICATION_NAME.json' copied to '$SPECIFICATION_PATH'"
|
echo "[+] specification '$SPECIFICATION_NAME.json' copied to '$SPECIFICATION_PATH'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $UNIT_FILE = true ]; then
|
|
||||||
cd $SCRIPT_FOLDER
|
|
||||||
read -p "[?] name for the unit file (default: ghost-node.service) " unit_name
|
|
||||||
if [ -z $unit_name ]; then
|
|
||||||
unit_name="ghost-node"
|
|
||||||
fi
|
|
||||||
unit_name=$(echo "$unit_name" | sed -e "s/.service//g")
|
|
||||||
unit_name="$unit_name.service"
|
|
||||||
|
|
||||||
user_name="ghost"
|
|
||||||
if id $user_name > /dev/null 2>&1; then
|
|
||||||
echo "[+] user ghost found, continue for the user ghost"
|
|
||||||
else
|
|
||||||
echo "[!] user ghost not found"
|
|
||||||
if prompt "[?] do you want to create ghost user? (NOT RECOMMENDED: current $(whoami))"; then
|
|
||||||
sudo useradd --system --create-home $user_name
|
|
||||||
else
|
|
||||||
user_name=$(whoami)
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -d $BASE_PATH ]; then
|
|
||||||
echo "[+] create folder for the node at '$BASE_PATH'"
|
|
||||||
sudo mkdir $BASE_PATH
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$(stat -c "%U %G" $BASE_PATH | grep $user_name)" ]; then
|
|
||||||
echo "[+] make $user_name owner of $BASE_PATH"
|
|
||||||
sudo chown -R "$user_name:" $BASE_PATH
|
|
||||||
fi
|
|
||||||
|
|
||||||
cp packaging/template.service /tmp/$unit_name
|
|
||||||
sed -i -e "s/User=ghost/User=$user_name/g" /tmp/$unit_name
|
|
||||||
sed -i -e "s#/ReadWritePaths=/var/lib/ghost#/ReadWritePaths=$BASE_PATH#g" /tmp/$unit_name
|
|
||||||
|
|
||||||
echo "[+] prepare unit file for the $unit_name"
|
|
||||||
sudo cp packaging/template.service /etc/systemd/system/$unit_name
|
|
||||||
echo "[+] reloading systemd because of updated unit file"
|
|
||||||
sudo systemctl daemon-reload
|
|
||||||
|
|
||||||
if prompt "[?] do you want to start the $unit_name?"; then
|
|
||||||
sudo systemctl restart $unit_name
|
|
||||||
fi
|
|
||||||
|
|
||||||
if prompt "[?] do you want to enable the $unit_name?"; then
|
|
||||||
sudo systemctl enable $unit_name
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $ARGUMENTS = true ]]; then
|
if [[ $ARGUMENTS = true ]]; then
|
||||||
echo "[+] setting-up default CLI arguments"
|
echo "[+] setting-up default CLI arguments"
|
||||||
CLI_ARGS=()
|
CLI_ARGS=()
|
||||||
@ -412,3 +363,51 @@ if [ $CHECK_KEYS = true ]; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $UNIT_FILE = true ]; then
|
||||||
|
cd $SCRIPT_FOLDER
|
||||||
|
read -p "[?] name for the unit file (default: ghost-node.service) " unit_name
|
||||||
|
if [ -z $unit_name ]; then
|
||||||
|
unit_name="ghost-node"
|
||||||
|
fi
|
||||||
|
unit_name=$(echo "$unit_name" | sed -e "s/.service//g")
|
||||||
|
unit_name="$unit_name.service"
|
||||||
|
|
||||||
|
user_name="ghost"
|
||||||
|
if id $user_name > /dev/null 2>&1; then
|
||||||
|
echo "[+] user ghost found, continue for the user ghost"
|
||||||
|
else
|
||||||
|
echo "[!] user ghost not found"
|
||||||
|
if prompt "[?] do you want to create ghost user? (NOT RECOMMENDED: current $(whoami))"; then
|
||||||
|
sudo useradd --system --create-home $user_name
|
||||||
|
else
|
||||||
|
user_name=$(whoami)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d $BASE_PATH ]; then
|
||||||
|
echo "[+] create folder for the node at '$BASE_PATH'"
|
||||||
|
sudo mkdir $BASE_PATH
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$(stat -c "%U %G" $BASE_PATH | grep $user_name)" ]; then
|
||||||
|
echo "[+] make $user_name owner of $BASE_PATH"
|
||||||
|
sudo chown -R "$user_name:" $BASE_PATH
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp packaging/template.service /tmp/$unit_name
|
||||||
|
sed -i -e "s/User=ghost/User=$user_name/g" /tmp/$unit_name
|
||||||
|
sed -i -e "s#/ReadWritePaths=/var/lib/ghost#/ReadWritePaths=$BASE_PATH#g" /tmp/$unit_name
|
||||||
|
|
||||||
|
echo "[+] prepare unit file for the $unit_name"
|
||||||
|
sudo cp packaging/template.service /etc/systemd/system/$unit_name
|
||||||
|
echo "[+] reloading systemd because of updated unit file"
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
|
||||||
|
if prompt "[?] do you want to start the $unit_name?"; then
|
||||||
|
sudo systemctl restart $unit_name
|
||||||
|
fi
|
||||||
|
|
||||||
|
if prompt "[?] do you want to enable the $unit_name?"; then
|
||||||
|
sudo systemctl enable $unit_name
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user