This file is indexed.

/usr/bin/one is in opennebula 4.12.3+dfsg-3.1build1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/bash

# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs        #
#                                                                            #
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
# not use this file except in compliance with the License. You may obtain    #
# a copy of the License at                                                   #
#                                                                            #
# http://www.apache.org/licenses/LICENSE-2.0                                 #
#                                                                            #
# Unless required by applicable law or agreed to in writing, software        #
# distributed under the License is distributed on an "AS IS" BASIS,          #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
# See the License for the specific language governing permissions and        #
# limitations under the License.                                             #
#--------------------------------------------------------------------------- #

if [ -z "$ONE_LOCATION" ]; then
    ONE_PID=/var/run/one/oned.pid
    ONE_SCHEDPID=/var/run/one/sched.pid
    ONE_CONF=/etc/one/oned.conf
    ONE_DB=/var/lib/one/one.db
    ONE_LOG=/var/log/one/oned.log
    ONE_SCHED_LOG=/var/log/one/sched.log
    ONE_XMLRPC_LOG=/var/log/one/one_xmlrpc.log

    ONED=/usr/bin/oned
    ONE_SCHEDULER=/usr/bin/mm_sched

    LOCK_FILE=/var/lock/one/one
else
    ONE_PID=$ONE_LOCATION/var/oned.pid
    ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid
    ONE_CONF=$ONE_LOCATION/etc/oned.conf
    ONE_DB=$ONE_LOCATION/var/one.db
    ONE_LOG=$ONE_LOCATION/var/oned.log
    ONE_SCHED_LOG=$ONE_LOCATION/var/sched.log
    ONE_XMLRPC_LOG=$ONE_LOCATION/var/one_xmlrpc.log

    ONED=$ONE_LOCATION/bin/oned
    ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched

    LOCK_FILE=$ONE_LOCATION/var/.lock
fi

KILL_9_SECONDS=5
BACKUP="true"

#------------------------------------------------------------------------------
# Function that checks for running daemons
#------------------------------------------------------------------------------
setup()
{
    ONE_PID_DIR=`dirname $ONE_PID`

    mkdir -p $ONE_PID_DIR

    if [ ! -w $ONE_PID_DIR ]; then
        echo "$ONE_PID_DIR is not writable, cannot start oned or scheduler."
        exit 1
    fi

    if [ -f $LOCK_FILE ]; then
        if [ -f  $ONE_PID ]; then
            ONEPID=`cat $ONE_PID`
            ps $ONEPID > /dev/null 2>&1
            if [ $? -eq 0 ]; then
                echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first."
                exit 1
            fi
        fi
        if [ -f  $ONE_SCHEDPID ]; then
            ONESCHEDPID=`cat $ONE_SCHEDPID`
            ps $ONESCHEDPID > /dev/null 2>&1
            if [ $? -eq 0 ]; then
                echo "The scheduler is still running (PID:$ONEPID). Please try 'one stop' first."
                exit 1
            fi
        fi
        echo "Stale .lock detected. Erasing it."
        rm $LOCK_FILE
    fi
}

#------------------------------------------------------------------------------
# Function that stops the daemons
#------------------------------------------------------------------------------
stop()
{
    stop_oned

    stop_sched
}

stop_oned()
{
    if [ -f $ONE_PID ]; then
        PID=$(cat $ONE_PID)
        kill $PID > /dev/null 2>&1

        counter=0
        while ps $PID > /dev/null 2>&1; do
            let counter=counter+1
            if [ $counter -gt $KILL_9_SECONDS ]; then
                kill -9 $PID > /dev/null 2>&1
                break
            fi
            sleep 1
        done

        rm -f $ONE_PID > /dev/null 2>&1
    fi
}

stop_sched()
{
    if [ -f $ONE_SCHEDPID ]; then
        kill `cat $ONE_SCHEDPID` > /dev/null 2>&1
        rm -f $ONE_SCHEDPID > /dev/null 2>&1
    fi
}

#------------------------------------------------------------------------------
# Function that starts the daemons
#------------------------------------------------------------------------------
start()
{
    if [ ! -x "$ONED" ]; then
        echo "Can not find $ONED."
        exit 1
    fi

    if [ ! -x "$ONE_SCHEDULER" ]; then
        echo "Can not find $ONE_SCHEDULER."
        exit 1
    fi

    if [ ! -f "$ONE_DB" ]; then
        if [ ! -f "$HOME/.one/one_auth" ]; then
            if [ -z "$ONE_AUTH" ]; then
                echo "You should have ONE_AUTH set the first time you start"
                echo "OpenNebula as it is used to set the credentials for"
                echo "the administrator user."
                exit 1
            fi
        fi
    fi

    # Start the one daemon
    start_oned

    # Start the scheduler
    start_sched

    # Wait for the daemons to warm up
    sleep 3

    STARTED="true"

    ps `cat $ONE_PID` > /dev/null 2>&1

    if [ $? -ne 0 ]; then
        echo "oned failed to start"
        STARTED="false"
    fi

    ps `cat $ONE_SCHEDPID` > /dev/null 2>&1

    if [ $? -ne 0 ]; then
        echo "scheduler failed to start"
        STARTED="false"
    fi

    if [ "$STARTED" == "false" ]; then
        stop
        exit -1
    fi
}

start_oned()
{
    if [ "$BACKUP" = "true" ];then
        [ -f "$ONE_LOG" ] && mv $ONE_LOG{,.$(date '+%Y%m%d%H%M%S')}
        [ -f "$ONE_XMLRPC_LOG" ] && mv $ONE_XMLRPC_LOG{,.$(date '+%Y%m%d%H%M%S')}
    fi
    $ONED -f 2>&1 &

    LASTRC=$?
    LASTPID=$!

    if [ $LASTRC -ne 0 ]; then
        echo "Error executing $ONED"
        exit 1
    else
        echo $LASTPID > $ONE_PID
    fi
}

start_sched()
{
    if [ "$BACKUP" = "true" ];then
        [ -f "$ONE_SCHED_LOG" ] && mv $ONE_SCHED_LOG{,.$(date '+%Y%m%d%H%M%S')}
    fi
    $ONE_SCHEDULER&

    LASTRC=$?
    LASTPID=$!

    if [ $LASTRC -ne 0 ]; then
        echo "Error executing $ONE_SCHEDULER"
        exit 1
    else
        echo $LASTPID > $ONE_SCHEDPID
    fi
}

#------------------------------------------------------------------------------
#------------------------------------------------------------------------------

if [ "$1" = "-f" ]; then
    BACKUP="false"
    shift
fi

case "$1" in
    start)
        setup
        start
        ;;
    stop)
        stop
        echo "oned and scheduler stopped"
        ;;
    restart)
        stop
        setup
        start
        echo "oned and scheduler restarted"
        ;;
    start-sched)
        start_sched
        ;;
    stop-sched)
        stop_sched
        ;;
    restart-sched)
        stop_sched
        sleep 1
        start_sched
        ;;
    *)
        echo "Usage: one [-f] {start|stop|restart|start-sched|stop-sched|restart-sched}" >&2
        echo "Options:" >&2
        echo "  -f  Do not backup log files." >&2
        exit 3
        ;;
esac