v0.4.44 new command line option for log file configuration at openmanod server. New...
[osm/RO.git] / scripts / install-openmano-service.sh
1 #!/bin/bash
2
3 ##
4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openmano
6 # All Rights Reserved.
7 #
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
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
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
18 # under the License.
19 #
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
22 ##
23
24 #ONLY TESTED for Ubuntu 16.04
25 #it configures openmano to run as a service
26
27 function usage(){
28 echo -e "usage: sudo $0 [OPTIONS]"
29 echo -e "Configures openmano to run as a service"
30 echo -e " OPTIONS"
31 echo -e " -u USER user to run openmano, 'root' by default"
32 echo -e " -f PATH path where openmano source is located. If missing it download from git"
33 echo -e " -q: install in an unattended mode"
34 echo -e " -h: show this help"
35 }
36
37
38 USER="root"
39 QUIET_MODE=""
40 FILE=""
41 DELETE=""
42 while getopts ":u:f:hq-:" o; do
43 case "${o}" in
44 u)
45 export USER="$OPTARG"
46 ;;
47 f)
48 export FILE="$OPTARG"
49 ;;
50 q)
51 export QUIET_MODE=yes
52 ;;
53 h)
54 usage && exit 0
55 ;;
56 -)
57 [ "${OPTARG}" == "help" ] && usage && exit 0
58 echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
59 exit 1
60 ;;
61 \?)
62 echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2
63 exit 1
64 ;;
65 :)
66 echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2
67 exit 1
68 ;;
69 *)
70 usage >&2
71 exit -1
72 ;;
73 esac
74 done
75
76 #check root privileges and non a root user behind
77 [ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit 1
78
79 #Discover Linux distribution
80 #try redhat type
81 [ -f /etc/redhat-release ] && _DISTRO=$(cat /etc/redhat-release 2>/dev/null | cut -d" " -f1)
82 #if not assuming ubuntu type
83 [ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is 2>/dev/null)
84 if [ "$_DISTRO" == "Ubuntu" ]
85 then
86 _RELEASE=`lsb_release -rs`
87 if ! lsb_release -rs | grep -q -e "16.04"
88 then
89 echo "Only tested in Ubuntu Server 16.04" >&2 && exit 1
90 fi
91 else
92 echo "Only tested in Ubuntu Server 16.04" >&2 && exit 1
93 fi
94
95
96 if [[ -z $FILE ]]
97 then
98 git clone https://osm.etsi.org/gerrit/osm/RO.git openmano
99 FILE=./openmano
100 DELETE=y
101 fi
102 cp -r $FILE /opt/openmano
103 cp ${FILE}/openmano /usr/sbin/
104 mv /opt/openmano/openmanod.cfg /etc/default/openmanod.cfg
105 mkdir -p /var/log/openmano/
106 mkdir -p etc/systemd/system/
107
108
109 cat >> /etc/systemd/system/openmano.service << EOF
110 [Unit]
111 Description=openmano server
112
113 [Service]
114 User=${USER}
115 ExecStart=/opt/openmano/openmanod.py -c /etc/default/openmanod.cfg --log-file=/var/log/openmano/openmano.log
116 Restart=always
117
118 [Install]
119 WantedBy=multi-user.target
120 EOF
121
122 [[ -n $DELETE ]] && rm -rf $FILE
123
124 service openmano start
125
126 echo Done
127 exit