X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=scripts%2Finstall-openvim-service.sh;h=b862cc133c6a9e9f618d6ba6f8ed8e3bd09c0f55;hb=9cc283fdb8f9abcb9ea8e9ce9d98dad352c06f82;hp=f673502bd830f82b82c1036028261f143787707a;hpb=f13617a350092613d22a39997fb00afda7da209c;p=osm%2Fopenvim.git diff --git a/scripts/install-openvim-service.sh b/scripts/install-openvim-service.sh index f673502..b862cc1 100755 --- a/scripts/install-openvim-service.sh +++ b/scripts/install-openvim-service.sh @@ -26,18 +26,19 @@ function usage(){ echo -e "usage: sudo $0 [OPTIONS]" - echo -e "Configures openvim to run as a service" + echo -e "Configures openvim to run as a service at /opt" echo -e " OPTIONS" echo -e " -u USER_OWNER user owner of the service, 'root' by default" echo -e " -f PATH path where openvim source is located. If missing it is downloaded from git" - #echo -e " -q: install in an unattended mode" + echo -e " -d --delete: if -f is provided, delete this path after copying to /opt" echo -e " -h: show this help" echo -e " --uninstall: remove created service and files" } function uninstall(){ - service openvim stop - for file in /opt/openvim /etc/default/openvimd.cfg /var/log/openvim /etc/systemd/system/openvim.service + echo "systemctl disable openvim.service " && systemctl disable openvim.service 2>/dev/null || echo " Already done" + echo "service openvim stop " && service openvim stop 2>/dev/null || echo " Already done" + for file in /opt/openvim /etc/default/openvimd.cfg /var/log/openvim /etc/systemd/system/openvim.service /usr/bin/openvim /usr/bin/initopenvim /usr/sbin/service-openvim /usr/bin/openvim-report /usr/bin/openflow do rm -rf $file || ! echo "Can not delete '$file'. Needed root privileges?" >&2 || exit 1 done @@ -45,12 +46,12 @@ function uninstall(){ } BAD_PATH_ERROR="Path '$FILE' does not contain a valid openvim distribution" -GIT_URL=https://osm.etsi.org/gerrit/osm/RO.git +GIT_URL=https://osm.etsi.org/gerrit/osm/openvim.git USER_OWNER="root" QUIET_MODE="" FILE="" DELETE="" -while getopts ":u:f:hq-:" o; do +while getopts ":u:f:hdq-:" o; do case "${o}" in u) export USER_OWNER="$OPTARG" @@ -64,10 +65,14 @@ while getopts ":u:f:hq-:" o; do h) usage && exit 0 ;; + d) + DELETE=y + ;; -) [ "${OPTARG}" == "help" ] && usage && exit 0 [ "${OPTARG}" == "uninstall" ] && uninstall && exit 0 - echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 + [ "${OPTARG}" == "delete" ] && DELETE=y && continue + echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 exit 1 ;; \?) @@ -84,6 +89,7 @@ while getopts ":u:f:hq-:" o; do ;; esac done +BAD_PATH_ERROR="Path '$FILE' does not contain a valid openvim distribution" #check root privileges [ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit 1 @@ -111,33 +117,38 @@ fi if [[ -z $FILE ]] then - git clone $GIT_URL __temp__ || ! echo "Cannot get openvim source code from $GIT_URL" >&2 || exit 1 - #git checkout - FILE=./__temp__ + FILE=__temp__${RANDOM} + git clone $GIT_URL $FILE || ! echo "Cannot get openvim source code from $GIT_URL" >&2 || exit 1 DELETE=y + #git checkout +else + [[ -d "$FILE" ]] || ! echo $BAD_PATH_ERROR >&2 || exit 1 fi #make idenpotent -rm -rf /opt/openvim -rm -f /etc/default/openvimd.cfg -rm -f /var/log/openvim -cp -r $FILE /opt/openvim || ! echo $BAD_PATH_ERROR >&2 || exit 1 +uninstall +#copy files +cp -r "$FILE" /opt/openvim || ! echo $BAD_PATH_ERROR >&2 || exit 1 mkdir -p /opt/openvim/logs -#cp ${FILE}/openvim /usr/sbin/ || ! echo $BAD_PATH_ERROR >&2 || exit 1 -ln -s /opt/openvim/openvimd.cfg /etc/default/openvimd.cfg || echo "warning cannot create link '/etc/default/openvimd.cfg'" -ln -s /opt/openvim/logs /var/log/openvim || echo "warning cannot create link '/var/log/openvim'" - -chown $USER_OWNER /opt/openvim/openvimd.cfg -chown -R $USER_OWNER /opt/openvim - -mkdir -p etc/systemd/system/ +#makes links +ln -s -v /opt/openvim/openvimd.cfg /etc/default/openvimd.cfg || echo "warning cannot create link '/etc/default/openvimd.cfg'" +ln -s -v /opt/openvim/logs /var/log/openvim || echo "warning cannot create link '/var/log/openvim'" +ln -s -v /opt/openvim/openvim /usr/bin/openvim +ln -s -v /opt/openvim/scripts/service-openvim /usr/sbin/service-openvim +ln -s -v /opt/openvim/scripts/openvim-report /usr/bin/openvim-report +ln -s -v /opt/openvim/scripts/initopenvim.sh /usr/bin/initopenvim +ln -s -v /opt/openvim/openflow /usr/bin/openflow + +chown -R $SUDO_USER /opt/openvim + +mkdir -p /etc/systemd/system/ cat > /etc/systemd/system/openvim.service << EOF [Unit] Description=openvim server [Service] User=${USER_OWNER} -ExecStart=/opt/openvim/openvimd.py -c /opt/openvim/openvimd.cfg --log-file=/opt/openvim/logs/openvim.log +ExecStart=/opt/openvim/openvimd -c /opt/openvim/osm_openvim/openvimd.cfg --log-file=/opt/openvim/logs/openvim.log Restart=always [Install] @@ -147,6 +158,7 @@ EOF [[ -n $DELETE ]] && rm -rf $FILE service openvim start +systemctl enable openvim.service echo Done exit