4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openvim
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
24 #ONLY TESTED for Ubuntu 16.04
25 #it configures openvim to run as a service
28 echo -e "usage: sudo $0 [OPTIONS]"
29 echo -e "Configures openvim to run as a service at /opt"
31 echo -e " -u USER_OWNER user owner of the service, 'root' by default"
32 echo -e " -f PATH path where openvim source is located. If missing it is downloaded from git"
33 echo -e " -d --delete: if -f is provided, delete this path after copying to /opt"
34 echo -e " -h: show this help"
35 echo -e " --uninstall: remove created service and files"
39 echo "systemctl disable openvim.service " && systemctl disable openvim.service
2>/dev
/null ||
echo " Already done"
40 echo "service openvim stop " && service openvim stop
2>/dev
/null ||
echo " Already done"
41 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
43 rm -rf $file ||
! echo "Can not delete '$file'. Needed root privileges?" >&2 ||
exit 1
48 BAD_PATH_ERROR
="Path '$FILE' does not contain a valid openvim distribution"
49 GIT_URL
=https
://osm.etsi.org
/gerrit
/osm
/openvim.git
54 while getopts ":u:f:hdq-:" o
; do
57 export USER_OWNER
="$OPTARG"
72 [ "${OPTARG}" == "help" ] && usage
&& exit 0
73 [ "${OPTARG}" == "uninstall" ] && uninstall
&& exit 0
74 [ "${OPTARG}" == "delete" ] && DELETE
=y
&& continue
75 echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
79 echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2
83 echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2
92 BAD_PATH_ERROR
="Path '$FILE' does not contain a valid openvim distribution"
94 #check root privileges
95 [ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit 1
97 #Discover Linux distribution
99 if [[ -f /etc
/redhat-release
]]
101 _DISTRO
=$
(cat /etc
/redhat-release
2>/dev
/null | cut
-d" " -f1)
103 #if not assuming ubuntu type
104 _DISTRO
=$
(lsb_release
-is 2>/dev
/null
)
106 if [[ "$_DISTRO" == "Ubuntu" ]]
108 _RELEASE
=$
(lsb_release
-rs)
109 if [[ ${_RELEASE%%.*} != 16 ]]
111 echo "Only tested in Ubuntu Server 16.04" >&2 && exit 1
114 echo "Only tested in Ubuntu Server 16.04" >&2 && exit 1
120 FILE
=__temp__
${RANDOM}
121 git clone
$GIT_URL $FILE ||
! echo "Cannot get openvim source code from $GIT_URL" >&2 ||
exit 1
123 #git checkout <tag version>
125 [[ -d "$FILE" ]] ||
! echo $BAD_PATH_ERROR >&2 ||
exit 1
131 cp -r "$FILE" /opt
/openvim ||
! echo $BAD_PATH_ERROR >&2 ||
exit 1
132 mkdir
-p /opt
/openvim
/logs
134 ln -s -v /opt
/openvim
/openvimd.cfg
/etc
/default
/openvimd.cfg ||
echo "warning cannot create link '/etc/default/openvimd.cfg'"
135 ln -s -v /opt
/openvim
/logs
/var
/log
/openvim ||
echo "warning cannot create link '/var/log/openvim'"
136 ln -s -v /opt
/openvim
/openvim
/usr
/bin
/openvim
137 ln -s -v /opt
/openvim
/scripts
/service-openvim.sh
/usr
/sbin
/service-openvim
138 ln -s -v /opt
/openvim
/scripts
/openvim-report.sh
/usr
/bin
/openvim-report
139 ln -s -v /opt
/openvim
/scripts
/initopenvim.sh
/usr
/bin
/initopenvim
140 ln -s -v /opt
/openvim
/openflow
/usr
/bin
/openflow
142 chown
-R $SUDO_USER /opt
/openvim
144 mkdir
-p /etc
/systemd
/system
/
145 cat > /etc
/systemd
/system
/openvim.service
<< EOF
147 Description=openvim server
151 ExecStart=/opt/openvim/openvimd.py -c /opt/openvim/openvimd.cfg --log-file=/opt/openvim/logs/openvim.log
155 WantedBy=multi-user.target
158 [[ -n $DELETE ]] && rm -rf $FILE
160 service openvim start
161 systemctl
enable openvim.service