From d1b08e4e0c32962c1c9828e715289353a4cf29db Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 24 Jan 2017 18:29:16 +0100 Subject: [PATCH] Managing service #1 --- clone/clone | 38 +++++++++++++++++++++++------------- clone/utility/booting_script | 15 ++++++++++++++ clone/utility/service_unit | 11 +++++++++++ 3 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 clone/utility/booting_script create mode 100644 clone/utility/service_unit diff --git a/clone/clone b/clone/clone index 980d88f..fbda072 100755 --- a/clone/clone +++ b/clone/clone @@ -66,8 +66,6 @@ step2(){ test $confirm_format != "y" && echo "<<< aborting" && exit; # (2) Init gpt entry # - # echo " ))) replace by real code ((("; - echo -e "g\nw" | sudo fdisk $DEV 2> /dev/null > /dev/null; echo "<<< done"; @@ -125,12 +123,12 @@ step5(){ # (1) Removing pi entry # - echo " (.) Remove pi entry" + echo " (.) Remove pi user entry" echo " > /etc/shadow"; sudo cat /mnt/etc/shadow | grep -vE "^pi:" | tee ./tmp/shadow > /dev/null; # (2) Adding 'sats' user and new pi entry # - echo " (.) Adding 'sats' user and updated pi entry"; + echo " (.) Adding 'sats' user and updated 'pi'"; echo " > /etc/shadow"; cat ./utility/shadow_append | tee -a ./tmp/shadow > /dev/null; cat ./tmp/shadow | sudo tee /mnt/etc/shadow | sudo tee /mnt/etc/shadow- > /dev/null; @@ -270,21 +268,33 @@ step9(){ #========================================================# step10(){ - echo "\n>>> [10] Set up SATS daemon"; + echo "\n>>> [10] Set up SATS operating folder"; - # (1) Create daemon folder # - echo " (.) Create daemon folder"; - sudo mkdir -p /mnt/home/sats/satsd; + # (1) Create operating folder # + echo " (.) Create operating folder"; + sudo mkdir -p /mnt/home/sats/satsd/source; + sudo mkdir -p /mnt/home/sats/satsd/log; + sudo mkdir -p /mnt/home/sats/satsd/conf; + sudo touch /mnt/home/sats/satsd/first_install; - # (2) Init git repository with ssh url # - echo " (.) Clone git repo with server's ssh url"; - sudo git clone --depth=1 ssh://smmp-server/home/gw/satsd /mnt/home/sats/satsd; + # (2) Set up SATS botting script # + echo " (.) Set up SATS booting script"; + cat ./utility/booting_script | sudo tee /mnt/home/sats/satsd/boot; - # (3) Set up git pull with good key # - echo " (.) Set up \`git pull\` with registered ssh key"; - cd /mnt/home/sats/git pull origin master; + # (3) Set up service unit # + echo " (.) Set up service unit (sats.service)"; + cat ./utility/service_unit | sudo tee /mnt/lib/systemd/system/sats.service; + # (4) Enable startup service unit # + echo " (.) Emulate \`systemctl enable sats.service\`"; + sudo ln -fs /lib/systemd/system/sats.service /mnt/etc/systemd/system/sats.service; + + # (5) Adjust permissions # + echo " (.) Adjust permissions"; + sudo chown -R 666:666 /mnt/home/sats/satsd; + sudo chmod -R 770 /mnt/home/sats/satsd; + echo "<<< done"; diff --git a/clone/utility/booting_script b/clone/utility/booting_script new file mode 100644 index 0000000..41b20d5 --- /dev/null +++ b/clone/utility/booting_script @@ -0,0 +1,15 @@ +#!/bin/sh + +# [1] first install (install source code) +if [ -e /home/sats/satsd/first_install ]; then + + # install source code + git clone ssh://smmp-server/satsd /mnt/home/sats/satsd/source \ + && rm /home/sats/satsd/first_install \ + || exit; + +fi + + +# [2] Propagate script +sh /home/sats/satsd/source/boot $*; diff --git a/clone/utility/service_unit b/clone/utility/service_unit new file mode 100644 index 0000000..7e9344f --- /dev/null +++ b/clone/utility/service_unit @@ -0,0 +1,11 @@ +[Unit] +Description=SATS (Secure Authentication and Tracking SYSTEM) Daemon +After=multi-user.target + +[Service] +Type=idle +ExecStart=-/bin/sh /home/sats/satsd/boot service 2>> /home/sats/satsd/log/boot.log >> /home/sats/satsd/log/boot.log +User=sats + +[Install] +WantedBy=multi-user.target