ganeti-noded 18.3 KB
Newer Older
Iustin Pop's avatar
Iustin Pop committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/python
#

# Copyright (C) 2006, 2007 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


"""Ganeti node daemon"""

24
25
26
# functions in this module need to have a given name structure, so:
# pylint: disable-msg=C0103

Iustin Pop's avatar
Iustin Pop committed
27
28
29
import os
import sys
import traceback
Guido Trotter's avatar
Guido Trotter committed
30
import SocketServer
31
import errno
Iustin Pop's avatar
Iustin Pop committed
32
import logging
33
import signal
Iustin Pop's avatar
Iustin Pop committed
34
35
36
37
38
39
40

from optparse import OptionParser

from ganeti import backend
from ganeti import constants
from ganeti import objects
from ganeti import errors
41
from ganeti import jstore
42
from ganeti import daemon
43
from ganeti import http
44
from ganeti import utils
Iustin Pop's avatar
Iustin Pop committed
45
46


47
48
49
queue_lock = None


50
51
52
53
def _RequireJobQueueLock(fn):
  """Decorator for job queue manipulating functions.

  """
54
55
  QUEUE_LOCK_TIMEOUT = 10

56
57
  def wrapper(*args, **kwargs):
    # Locking in exclusive, blocking mode because there could be several
58
    # children running at the same time. Waiting up to 10 seconds.
59
    queue_lock.Exclusive(blocking=True, timeout=QUEUE_LOCK_TIMEOUT)
60
61
62
63
    try:
      return fn(*args, **kwargs)
    finally:
      queue_lock.Unlock()
64

65
66
67
  return wrapper


68
class NodeHttpServer(http.HttpServer):
69
70
71
72
73
  """The server implementation.

  This class holds all methods exposed over the RPC interface.

  """
74
75
76
77
78
  def __init__(self, *args, **kwargs):
    http.HttpServer.__init__(self, *args, **kwargs)
    self.noded_pid = os.getpid()

  def HandleRequest(self, req):
79
    """Handle a request.
Iustin Pop's avatar
Iustin Pop committed
80

81
    """
82
    if req.request_method.upper() != "PUT":
83
84
      raise http.HTTPBadRequest()

85
    path = req.request_path
Iustin Pop's avatar
Iustin Pop committed
86
87
88
    if path.startswith("/"):
      path = path[1:]

89
90
    method = getattr(self, "perspective_%s" % path, None)
    if method is None:
91
      raise http.HTTPNotFound()
Iustin Pop's avatar
Iustin Pop committed
92

Iustin Pop's avatar
Iustin Pop committed
93
    try:
94
      try:
95
        return method(req.request_post_data)
96
97
98
      except:
        logging.exception("Error in RPC call")
        raise
99
    except errors.QuitGanetiException, err:
100
      # Tell parent to quit
101
      os.kill(self.noded_pid, signal.SIGTERM)
Iustin Pop's avatar
Iustin Pop committed
102
103
104

  # the new block devices  --------------------------

105
106
107
108
109
  @staticmethod
  def perspective_blockdev_create(params):
    """Create a block device.

    """
110
    bdev_s, size, owner, on_primary, info = params
111
    bdev = objects.Disk.FromDict(bdev_s)
Iustin Pop's avatar
Iustin Pop committed
112
113
    if bdev is None:
      raise ValueError("can't unserialize data!")
114
    return backend.CreateBlockDevice(bdev, size, owner, on_primary, info)
Iustin Pop's avatar
Iustin Pop committed
115

116
117
118
119
120
  @staticmethod
  def perspective_blockdev_remove(params):
    """Remove a block device.

    """
Iustin Pop's avatar
Iustin Pop committed
121
    bdev_s = params[0]
122
    bdev = objects.Disk.FromDict(bdev_s)
Iustin Pop's avatar
Iustin Pop committed
123
124
    return backend.RemoveBlockDevice(bdev)

Iustin Pop's avatar
Iustin Pop committed
125
126
127
128
129
130
131
132
  @staticmethod
  def perspective_blockdev_rename(params):
    """Remove a block device.

    """
    devlist = [(objects.Disk.FromDict(ds), uid) for ds, uid in params]
    return backend.RenameBlockDevices(devlist)

133
134
135
136
137
  @staticmethod
  def perspective_blockdev_assemble(params):
    """Assemble a block device.

    """
138
    bdev_s, owner, on_primary = params
139
    bdev = objects.Disk.FromDict(bdev_s)
Iustin Pop's avatar
Iustin Pop committed
140
141
    if bdev is None:
      raise ValueError("can't unserialize data!")
142
    return backend.AssembleBlockDevice(bdev, owner, on_primary)
Iustin Pop's avatar
Iustin Pop committed
143

144
145
146
147
148
  @staticmethod
  def perspective_blockdev_shutdown(params):
    """Shutdown a block device.

    """
Iustin Pop's avatar
Iustin Pop committed
149
    bdev_s = params[0]
150
    bdev = objects.Disk.FromDict(bdev_s)
Iustin Pop's avatar
Iustin Pop committed
151
152
153
154
    if bdev is None:
      raise ValueError("can't unserialize data!")
    return backend.ShutdownBlockDevice(bdev)

155
  @staticmethod
156
  def perspective_blockdev_addchildren(params):
157
158
159
160
161
162
    """Add a child to a mirror device.

    Note: this is only valid for mirror devices. It's the caller's duty
    to send a correct disk, otherwise we raise an error.

    """
Iustin Pop's avatar
Iustin Pop committed
163
    bdev_s, ndev_s = params
164
    bdev = objects.Disk.FromDict(bdev_s)
165
166
    ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s]
    if bdev is None or ndevs.count(None) > 0:
Iustin Pop's avatar
Iustin Pop committed
167
      raise ValueError("can't unserialize data!")
168
    return backend.MirrorAddChildren(bdev, ndevs)
Iustin Pop's avatar
Iustin Pop committed
169

170
  @staticmethod
171
  def perspective_blockdev_removechildren(params):
172
173
174
175
176
177
    """Remove a child from a mirror device.

    This is only valid for mirror devices, of course. It's the callers
    duty to send a correct disk, otherwise we raise an error.

    """
Iustin Pop's avatar
Iustin Pop committed
178
    bdev_s, ndev_s = params
179
    bdev = objects.Disk.FromDict(bdev_s)
180
181
    ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s]
    if bdev is None or ndevs.count(None) > 0:
Iustin Pop's avatar
Iustin Pop committed
182
      raise ValueError("can't unserialize data!")
183
    return backend.MirrorRemoveChildren(bdev, ndevs)
Iustin Pop's avatar
Iustin Pop committed
184

185
186
187
188
189
  @staticmethod
  def perspective_blockdev_getmirrorstatus(params):
    """Return the mirror status for a list of disks.

    """
190
    disks = [objects.Disk.FromDict(dsk_s)
Iustin Pop's avatar
Iustin Pop committed
191
192
193
            for dsk_s in params]
    return backend.GetMirrorStatus(disks)

194
195
196
197
198
199
200
  @staticmethod
  def perspective_blockdev_find(params):
    """Expose the FindBlockDevice functionality for a disk.

    This will try to find but not activate a disk.

    """
201
    disk = objects.Disk.FromDict(params[0])
Iustin Pop's avatar
Iustin Pop committed
202
203
    return backend.FindBlockDevice(disk)

204
205
206
207
208
209
210
211
212
  @staticmethod
  def perspective_blockdev_snapshot(params):
    """Create a snapshot device.

    Note that this is only valid for LVM disks, if we get passed
    something else we raise an exception. The snapshot device can be
    remove by calling the generic block device remove call.

    """
213
    cfbd = objects.Disk.FromDict(params[0])
Iustin Pop's avatar
Iustin Pop committed
214
215
    return backend.SnapshotBlockDevice(cfbd)

216
217
218
219
220
221
222
223
224
  @staticmethod
  def perspective_blockdev_grow(params):
    """Grow a stack of devices.

    """
    cfbd = objects.Disk.FromDict(params[0])
    amount = params[1]
    return backend.GrowBlockDevice(cfbd, amount)

225
226
227
228
229
230
231
232
  @staticmethod
  def perspective_blockdev_close(params):
    """Closes the given block devices.

    """
    disks = [objects.Disk.FromDict(cf) for cf in params]
    return backend.CloseBlockDevices(disks)

Iustin Pop's avatar
Iustin Pop committed
233
234
  # export/import  --------------------------

235
236
237
238
239
  @staticmethod
  def perspective_snapshot_export(params):
    """Export a given snapshot.

    """
240
    disk = objects.Disk.FromDict(params[0])
Iustin Pop's avatar
Iustin Pop committed
241
    dest_node = params[1]
242
    instance = objects.Instance.FromDict(params[2])
243
    cluster_name = params[3]
244
245
246
    dev_idx = params[4]
    return backend.ExportSnapshot(disk, dest_node, instance,
                                  cluster_name, dev_idx)
247
248
249
250

  @staticmethod
  def perspective_finalize_export(params):
    """Expose the finalize export functionality.
Iustin Pop's avatar
Iustin Pop committed
251

252
    """
253
254
    instance = objects.Instance.FromDict(params[0])
    snap_disks = [objects.Disk.FromDict(str_data)
Iustin Pop's avatar
Iustin Pop committed
255
256
257
                  for str_data in params[1]]
    return backend.FinalizeExport(instance, snap_disks)

258
259
260
261
262
263
264
265
266
267
  @staticmethod
  def perspective_export_info(params):
    """Query information about an existing export on this node.

    The given path may not contain an export, in which case we return
    None.

    """
    path = params[0]
    einfo = backend.ExportInfo(path)
Iustin Pop's avatar
Iustin Pop committed
268
269
270
271
    if einfo is None:
      return einfo
    return einfo.Dumps()

272
273
274
275
276
277
278
279
280
  @staticmethod
  def perspective_export_list(params):
    """List the available exports on this node.

    Note that as opposed to export_info, which may query data about an
    export in any path, this only queries the standard Ganeti path
    (constants.EXPORT_DIR).

    """
Iustin Pop's avatar
Iustin Pop committed
281
282
    return backend.ListExports()

283
284
285
286
287
  @staticmethod
  def perspective_export_remove(params):
    """Remove an export.

    """
Iustin Pop's avatar
Iustin Pop committed
288
289
290
291
292
    export = params[0]
    return backend.RemoveExport(export)

  # volume  --------------------------

293
294
295
296
297
  @staticmethod
  def perspective_volume_list(params):
    """Query the list of logical volumes in a given volume group.

    """
Iustin Pop's avatar
Iustin Pop committed
298
299
300
    vgname = params[0]
    return backend.GetVolumeList(vgname)

301
302
303
304
305
  @staticmethod
  def perspective_vg_list(params):
    """Query the list of volume groups.

    """
Iustin Pop's avatar
Iustin Pop committed
306
307
308
309
    return backend.ListVolumeGroups()

  # bridge  --------------------------

310
311
312
313
314
  @staticmethod
  def perspective_bridges_exist(params):
    """Check if all bridges given exist on this node.

    """
Iustin Pop's avatar
Iustin Pop committed
315
316
317
318
319
    bridges_list = params[0]
    return backend.BridgesExist(bridges_list)

  # instance  --------------------------

320
321
322
323
324
  @staticmethod
  def perspective_instance_os_add(params):
    """Install an OS on a given instance.

    """
325
    inst_s = params[0]
326
    inst = objects.Instance.FromDict(inst_s)
327
    return backend.AddOSToInstance(inst)
Iustin Pop's avatar
Iustin Pop committed
328

329
330
331
332
333
  @staticmethod
  def perspective_instance_run_rename(params):
    """Runs the OS rename script for an instance.

    """
334
    inst_s, old_name = params
335
    inst = objects.Instance.FromDict(inst_s)
336
    return backend.RunRenameInstance(inst, old_name)
337

338
339
340
341
342
  @staticmethod
  def perspective_instance_os_import(params):
    """Run the import function of an OS onto a given instance.

    """
343
    inst_s, src_node, src_images, cluster_name = params
344
    inst = objects.Instance.FromDict(inst_s)
345
346
    return backend.ImportOSIntoInstance(inst, src_node, src_images,
                                        cluster_name)
Iustin Pop's avatar
Iustin Pop committed
347

348
349
350
351
352
  @staticmethod
  def perspective_instance_shutdown(params):
    """Shutdown an instance.

    """
353
    instance = objects.Instance.FromDict(params[0])
Iustin Pop's avatar
Iustin Pop committed
354
355
    return backend.ShutdownInstance(instance)

356
357
358
359
360
  @staticmethod
  def perspective_instance_start(params):
    """Start an instance.

    """
361
    instance = objects.Instance.FromDict(params[0])
Iustin Pop's avatar
Iustin Pop committed
362
363
364
    extra_args = params[1]
    return backend.StartInstance(instance, extra_args)

365
366
367
368
369
370
  @staticmethod
  def perspective_instance_migrate(params):
    """Migrates an instance.

    """
    instance, target, live = params
371
    instance = objects.Instance.FromDict(instance)
372
373
    return backend.MigrateInstance(instance, target, live)

374
375
376
377
378
379
380
381
382
383
  @staticmethod
  def perspective_instance_reboot(params):
    """Reboot an instance.

    """
    instance = objects.Instance.FromDict(params[0])
    reboot_type = params[1]
    extra_args = params[2]
    return backend.RebootInstance(instance, reboot_type, extra_args)

384
385
386
387
388
  @staticmethod
  def perspective_instance_info(params):
    """Query instance information.

    """
Iustin Pop's avatar
Iustin Pop committed
389
    return backend.GetInstanceInfo(params[0], params[1])
Iustin Pop's avatar
Iustin Pop committed
390

391
392
393
394
395
  @staticmethod
  def perspective_all_instances_info(params):
    """Query information about all instances.

    """
396
    return backend.GetAllInstancesInfo(params[0])
Iustin Pop's avatar
Iustin Pop committed
397

398
399
400
401
402
  @staticmethod
  def perspective_instance_list(params):
    """Query the list of running instances.

    """
403
    return backend.GetInstanceList(params[0])
Iustin Pop's avatar
Iustin Pop committed
404
405
406

  # node --------------------------

407
408
409
410
411
  @staticmethod
  def perspective_node_tcp_ping(params):
    """Do a TcpPing on the remote node.

    """
412
413
    return utils.TcpPing(params[1], params[2], timeout=params[3],
                         live_port_needed=params[4], source=params[0])
414

415
416
417
418
419
420
421
  @staticmethod
  def perspective_node_has_ip_address(params):
    """Checks if a node has the given ip address.

    """
    return utils.OwnIpAddress(params[0])

422
423
424
425
426
  @staticmethod
  def perspective_node_info(params):
    """Query node information.

    """
427
428
    vgname, hypervisor_type = params
    return backend.GetNodeInfo(vgname, hypervisor_type)
Iustin Pop's avatar
Iustin Pop committed
429

430
431
432
433
434
  @staticmethod
  def perspective_node_add(params):
    """Complete the registration of this node in the cluster.

    """
Iustin Pop's avatar
Iustin Pop committed
435
436
437
    return backend.AddNode(params[0], params[1], params[2],
                           params[3], params[4], params[5])

438
439
440
441
442
  @staticmethod
  def perspective_node_verify(params):
    """Run a verify sequence on this node.

    """
443
    return backend.VerifyNode(params[0], params[1])
Iustin Pop's avatar
Iustin Pop committed
444

445
446
447
448
449
  @staticmethod
  def perspective_node_start_master(params):
    """Promote this node to master status.

    """
450
    return backend.StartMaster(params[0])
Iustin Pop's avatar
Iustin Pop committed
451

452
453
454
455
456
  @staticmethod
  def perspective_node_stop_master(params):
    """Demote this node from master status.

    """
457
    return backend.StopMaster(params[0])
Iustin Pop's avatar
Iustin Pop committed
458

459
460
461
462
463
  @staticmethod
  def perspective_node_leave_cluster(params):
    """Cleanup after leaving a cluster.

    """
Iustin Pop's avatar
Iustin Pop committed
464
465
    return backend.LeaveCluster()

466
467
468
469
470
  @staticmethod
  def perspective_node_volumes(params):
    """Query the list of all logical volume groups.

    """
471
472
    return backend.NodeVolumes()

Iustin Pop's avatar
Iustin Pop committed
473
474
  # cluster --------------------------

475
476
477
478
479
  @staticmethod
  def perspective_version(params):
    """Query version information.

    """
Iustin Pop's avatar
Iustin Pop committed
480
481
    return constants.PROTOCOL_VERSION

482
483
484
485
486
487
488
489
  @staticmethod
  def perspective_upload_file(params):
    """Upload a file.

    Note that the backend implementation imposes strict rules on which
    files are accepted.

    """
Iustin Pop's avatar
Iustin Pop committed
490
491
    return backend.UploadFile(*params)

492
493
494
495
496
497
  @staticmethod
  def perspective_master_info(params):
    """Query master information.

    """
    return backend.GetMasterInfo()
Iustin Pop's avatar
Iustin Pop committed
498

499
500
501
502
503
504
505
  @staticmethod
  def perspective_write_ssconf_files(params):
    """Write ssconf files.

    """
    return backend.WriteSsconfFiles()

Iustin Pop's avatar
Iustin Pop committed
506
507
  # os -----------------------

508
509
510
511
512
  @staticmethod
  def perspective_os_diagnose(params):
    """Query detailed information about existing OSes.

    """
513
    return [os.ToDict() for os in backend.DiagnoseOS()]
Iustin Pop's avatar
Iustin Pop committed
514

515
516
517
518
519
  @staticmethod
  def perspective_os_get(params):
    """Query information about a given OS.

    """
Iustin Pop's avatar
Iustin Pop committed
520
521
    name = params[0]
    try:
522
      os_obj = backend.OSFromDisk(name)
Iustin Pop's avatar
Iustin Pop committed
523
    except errors.InvalidOS, err:
524
525
      os_obj = objects.OS.FromInvalidOS(err)
    return os_obj.ToDict()
Iustin Pop's avatar
Iustin Pop committed
526
527
528

  # hooks -----------------------

529
530
531
532
533
  @staticmethod
  def perspective_hooks_runner(params):
    """Run hook scripts.

    """
Iustin Pop's avatar
Iustin Pop committed
534
535
536
537
    hpath, phase, env = params
    hr = backend.HooksRunner()
    return hr.RunHooks(hpath, phase, env)

538
539
540
541
542
543
544
545
546
547
548
  # iallocator -----------------

  @staticmethod
  def perspective_iallocator_runner(params):
    """Run an iallocator script.

    """
    name, idata = params
    iar = backend.IAllocatorRunner()
    return iar.Run(name, idata)

549
550
551
552
553
554
555
556
557
558
  # test -----------------------

  @staticmethod
  def perspective_test_delay(params):
    """Run test delay.

    """
    duration = params[0]
    return utils.TestDelay(duration)

559
560
  # file storage ---------------

561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
  @staticmethod
  def perspective_file_storage_dir_create(params):
    """Create the file storage directory.

    """
    file_storage_dir = params[0]
    return backend.CreateFileStorageDir(file_storage_dir)

  @staticmethod
  def perspective_file_storage_dir_remove(params):
    """Remove the file storage directory.

    """
    file_storage_dir = params[0]
    return backend.RemoveFileStorageDir(file_storage_dir)

  @staticmethod
  def perspective_file_storage_dir_rename(params):
    """Rename the file storage directory.

    """
    old_file_storage_dir = params[0]
    new_file_storage_dir = params[1]
    return backend.RenameFileStorageDir(old_file_storage_dir,
                                        new_file_storage_dir)

587
588
  # jobs ------------------------

589
  @staticmethod
590
  @_RequireJobQueueLock
591
592
593
594
595
  def perspective_jobqueue_update(params):
    """Update job queue.

    """
    (file_name, content) = params
596
    return backend.JobQueueUpdate(file_name, content)
597
598

  @staticmethod
599
  @_RequireJobQueueLock
600
601
602
603
604
605
  def perspective_jobqueue_purge(params):
    """Purge job queue.

    """
    return backend.JobQueuePurge()

606
607
608
609
610
611
612
613
614
615
  @staticmethod
  @_RequireJobQueueLock
  def perspective_jobqueue_rename(params):
    """Rename a job queue file.

    """
    (old, new) = params

    return backend.JobQueueRename(old, new)

616
617
618
619
620
621
622
623
624
  @staticmethod
  def perspective_jobqueue_set_drain(params):
    """Set/unset the queue drain flag.

    """
    drain_flag = params[0]
    return backend.JobQueueSetDrainFlag(drain_flag)


625
626
627
628
629
630
631
632
633
634
  # hypervisor ---------------

  @staticmethod
  def perspective_hypervisor_validate_params(params):
    """Validate the hypervisor parameters.

    """
    (hvname, hvparams) = params
    return backend.ValidateHVParams(hvname, hvparams)

Iustin Pop's avatar
Iustin Pop committed
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657

def ParseOptions():
  """Parse the command line options.

  Returns:
    (options, args) as from OptionParser.parse_args()

  """
  parser = OptionParser(description="Ganeti node daemon",
                        usage="%prog [-f] [-d]",
                        version="%%prog (ganeti) %s" %
                        constants.RELEASE_VERSION)

  parser.add_option("-f", "--foreground", dest="fork",
                    help="Don't detach from the current terminal",
                    default=True, action="store_false")
  parser.add_option("-d", "--debug", dest="debug",
                    help="Enable some debug messages",
                    default=False, action="store_true")
  options, args = parser.parse_args()
  return options, args


658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
def EnsureRuntimeEnvironment():
  """Ensure our run-time environment is complete.

  Currently this creates directories which could be missing, either
  due to directories being on a tmpfs mount, or due to incomplete
  packaging.

  """
  dirs = [(val, 0755) for val in constants.SUB_RUN_DIRS]
  dirs.append((constants.LOG_OS_DIR, 0750))
  for dir_name, dir_mode in dirs:
    if not os.path.exists(dir_name):
      try:
        os.mkdir(dir_name, dir_mode)
      except EnvironmentError, err:
        if err.errno != errno.EEXIST:
          print ("Node setup wrong, cannot create directory '%s': %s" %
                 (dir_name, err))
          sys.exit(5)
    if not os.path.isdir(dir_name):
      print ("Node setup wrong, '%s' is not a directory" % dir_name)
      sys.exit(5)


Iustin Pop's avatar
Iustin Pop committed
682
def main():
683
684
685
  """Main function for the node daemon.

  """
686
687
  global queue_lock

Iustin Pop's avatar
Iustin Pop committed
688
  options, args = ParseOptions()
689
  utils.debug = options.debug
Iustin Pop's avatar
Iustin Pop committed
690
691
692
693
694
695
  for fname in (constants.SSL_CERT_FILE,):
    if not os.path.isfile(fname):
      print "config %s not there, will not run." % fname
      sys.exit(5)

  try:
Michael Hanselmann's avatar
Michael Hanselmann committed
696
    port = utils.GetNodeDaemonPort()
Iustin Pop's avatar
Iustin Pop committed
697
698
699
700
  except errors.ConfigurationError, err:
    print "Cluster configuration incomplete: '%s'" % str(err)
    sys.exit(5)

701
  EnsureRuntimeEnvironment()
702

Iustin Pop's avatar
Iustin Pop committed
703
704
  # become a daemon
  if options.fork:
705
    utils.Daemonize(logfile=constants.LOG_NODESERVER)
Iustin Pop's avatar
Iustin Pop committed
706

707
  utils.WritePidFile(constants.NODED_PID)
708
  try:
Iustin Pop's avatar
Iustin Pop committed
709
710
    utils.SetupLogging(logfile=constants.LOG_NODESERVER, debug=options.debug,
                       stderr_logging=not options.fork)
711
    logging.info("ganeti node daemon startup")
712

713
714
    # Prepare job queue
    queue_lock = jstore.InitAndVerifyQueue(must_lock=False)
Iustin Pop's avatar
Iustin Pop committed
715

716
    mainloop = daemon.Mainloop()
717
    server = NodeHttpServer(mainloop, "", port)
718
719
720
721
722
    server.Start()
    try:
      mainloop.Run()
    finally:
      server.Stop()
723
  finally:
724
    utils.RemovePidFile(constants.NODED_PID)
725

Iustin Pop's avatar
Iustin Pop committed
726

727
if __name__ == '__main__':
Iustin Pop's avatar
Iustin Pop committed
728
  main()