-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
776 lines (697 loc) · 36.6 KB
/
Makefile
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# ########################################################################
#
# Ricgraph - Research in context graph
#
# ########################################################################
#
# MIT License
#
# Copyright (c) 2024, 2025 Rik D.T. Janssen
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ########################################################################
#
# This file is the Makefile for Ricgraph.
# For make, see https://www.gnu.org/software/make.
#
# This file will make installing Ricgraph on Linux easier. It also helps
# e.g. with dumping and restoring graph databases, and with running
# Ricgraph batch scripts.
#
# Original version Rik D.T. Janssen, September 2024.
# Updated Rik D.T. Janssen, January 2025.
#
# ########################################################################
# ########################################################################
# These are the versions of the software to be installed.
# ########################################################################
ricgraph_version := 2.8
neo4j_community_version := 5.24.0
neo4j_desktop_version := 1.6.0
# The minimal Python version required for Ricgraph.
minimal_python_minor_version := 10
# ########################################################################
# The name of the Ricgraph batch harvest script to run and its log.
# It should be in directory [Ricgraph install directory]/harvest.
# ########################################################################
batch_script := batch_harvest_demo.py
batch_script_log := $(basename $(batch_script))_`date +%y%m%d-%H%M`.log
# ########################################################################
# Define a number of variables.
# ########################################################################
# Determine the Linux edition and version number, for debug purposes only.
linux_edition := $(shell cat /etc/os-release | grep '^NAME=' | sed 's/NAME="\(.*\)"/\1/')
ifeq ($(linux_edition),Fedora Linux)
# Fedora does not has double quotes around the version number.
linux_version := $(shell cat /etc/os-release | grep '^VERSION_ID=' | sed 's/VERSION_ID=\(.*\)/\1/')
else ifeq ($(linux_edition),Manjaro Linux)
# Manjaro does not has double quotes around the version number.
linux_version := $(shell cat /etc/os-release | grep '^BUILD_ID=' | sed 's/BUILD_ID=\(.*\)/\1/')
else
# Ubuntu and OpenSUSE and Debian have double quotes around the version number.
linux_version := $(shell cat /etc/os-release | grep '^VERSION_ID=' | sed 's/VERSION_ID="\(.*\)"/\1/')
endif
# Ricgraph variables.
ricgraph_download := https://github.com/UtrechtUniversity/ricgraph
ricgraph_path := $(ricgraph_download)/archive/refs/tags/v$(ricgraph_version).tar.gz
ricgraph_cuttingedge_path := $(ricgraph_download)/archive/refs/heads/main.zip
# This is the GitHub name of the Ricgraph release file that is downloaded
ricgraph_tag_name := $(shell basename $(ricgraph_path))
ricgraph_cuttingedge_name := $(shell basename $(ricgraph_cuttingedge_path))
ricgraph_server_install_dir := /opt/ricgraph_venv
ricgraph_singleuser_install_dir := $(HOME)/ricgraph_venv
ricgraph_explorer := ricgraph_explorer.py
# This is the GitHub name of the Ricgraph release file that is in the downloaded tar file.
ricgraph := ricgraph-$(ricgraph_version)
# You can use the following two variables as command line arguments to run
# any Ricgraph script. 'ricgraph_anyscript' should contain the path to the
# script relative to the directory where this Makefile is. The same for
# 'ricgraph_anyscript_log', unless it starts with a '/'.
# If that directory or file is not writable for the user
# executing the script, you will get an error. The values below are placeholders.
# Example use:
# 'make ricgraph_anyscript=[script name] ricgraph_anyscript_log=[log file] run_anyscript'
ricgraph_anyscript := maintenance/create_toc_documentation.py
ricgraph_anyscript_log_file := $(basename $(notdir $(ricgraph_anyscript)))_`date +%y%m%d-%H%M`.log
ricgraph_anyscript_log := $(dir $(ricgraph_anyscript))/$(ricgraph_anyscript_log_file)
# Neo4j variable.
# Ask https://perplexity.ai for download locations, prompt:
# "What is the direct download link for neo4j community edition rpm (or deb) version?"
neo4j_download := https://dist.neo4j.org
# Misc. variables.
readdoc_server := https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_as_server.md#create-a-python-virtual-environment-and-install-ricgraph-in-it
readdoc_singleuser := https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_install_configure.md#using-pythons-venv-module
tmp_dir := /tmp/cuttingedge_$(shell echo $$PPID)
graphdb_backup_dir := /root/graphdb_backup
graphdb_password_file := /tmp/0-ricgraph-password.txt
graphdb_password_length := 12
graphdb_password := [not_set]
systemctl_cmd := systemctl
# This controls whether the question "Are you sure" is shown to the user or not. If it is
# something else than "no", it will be shown. Useful when this Makefile is run from a script.
ask_are_you_sure := yes
# Determine which python command to use.
ifeq ($(shell which python3.11 > /dev/null 2>&1 && echo $$?),0)
# E.g. for OpenSUSE Leap, Fedora.
python_cmd := python3.11
actual_python_minor_version := $(shell $(python_cmd) -c 'import sys; print(sys.version_info.minor)')
else ifeq ($(shell which python3 > /dev/null 2>&1 && echo $$?),0)
# E.g. for Ubuntu.
python_cmd := python3
actual_python_minor_version := $(shell $(python_cmd) -c 'import sys; print(sys.version_info.minor)')
else
python_cmd := [not_set]
actual_python_minor_version := [not_set]
endif
# Determine which package install command to use, and subsequently which package names to use.
# We need a package manager that can install 'rpm' or 'deb' files (for Neo4j Community Edition).
ifeq ($(shell which rpm > /dev/null 2>&1 && echo $$?),0)
# E.g. for OpenSUSE Leap & Tumbleweed, Fedora.
# To update (not supported in this Makefile) you will need "rpm -iU".
package_install_cmd := rpm -i
neo4j_community_path := $(neo4j_download)/rpm/neo4j-$(neo4j_community_version)-1.noarch.rpm
neo4j_cyphershell_path := $(neo4j_download)/cypher-shell/cypher-shell-$(neo4j_community_version)-1.noarch.rpm
else ifeq ($(shell which apt > /dev/null 2>&1 && echo $$?),0)
# E.g. for Ubuntu and Debian.
package_install_cmd := apt-get install --yes
neo4j_community_path := $(neo4j_download)/deb/neo4j_$(neo4j_community_version)_all.deb
neo4j_cyphershell_path := $(neo4j_download)/cypher-shell/cypher-shell_$(neo4j_community_version)_all.deb
else
package_install_cmd := [not_set]
neo4j_community_path := [not_set]
neo4j_cyphershell_path := [not_set]
endif
neo4j_desktop_path := $(neo4j_download)/neo4j-desktop/linux-offline/neo4j-desktop-$(neo4j_desktop_version)-x86_64.AppImage
neo4j_desktop := $(shell basename $(neo4j_desktop_path))
neo4j_community := $(shell basename $(neo4j_community_path))
neo4j_cyphershell := $(shell basename $(neo4j_cyphershell_path))
# Determine which Apache paths to use.
ifeq ($(shell test -d /etc/apache2/vhosts.d && echo true),true)
# E.g. for OpenSUSE Leap & Tumbleweed.
apache_vhosts_dir := /etc/apache2/vhosts.d
apache_service_file := /usr/lib/systemd/system/apache2.service
else ifeq ($(shell test -d /etc/apache2/sites-available && echo true),true)
# E.g. for Ubuntu and Debian.
apache_vhosts_dir := /etc/apache2/sites-available
apache_service_file := /usr/lib/systemd/system/apache2.service
else ifeq ($(shell test -d /etc/httpd/conf.d && echo true),true)
# E.g. for Fedora.
apache_vhosts_dir := /etc/httpd/conf.d
apache_service_file := /usr/lib/systemd/system/httpd.service
else
apache_vhosts_dir := [not_set]
apache_service_file := [not_set]
endif
# Determine which Nginx paths to use.
# Virtual hosts are called "Server blocks" in Nginx but I still use vhost for readability.
ifeq ($(shell test -d /etc/nginx/vhosts.d && echo true),true)
# E.g. for OpenSUSE Leap & Tumbleweed.
nginx_vhosts_dir := /etc/nginx/vhosts.d
else ifeq ($(shell test -d /etc/nginx/sites-available && echo true),true)
# E.g. for Ubuntu and Debian.
nginx_vhosts_dir := /etc/nginx/sites-available
else ifeq ($(shell test -d /etc/nginx/conf.d && echo true),true)
# E.g. for Fedora.
nginx_vhosts_dir := /etc/nginx/conf.d
else
nginx_vhosts_dir := [not_set]
endif
# ########################################################################
# General targets.
# ########################################################################
help:
@echo ""
@echo "Ricgraph Makefile help."
@echo "You can use this Makefile to install (parts of) Ricgraph and dump/restore"
@echo "its graph database. There are also other options as listed below."
@echo ""
@echo "The output of this script will be the commands that have been executed"
@echo "and their results. If you do not get any output, then nothing has been done,"
@echo "because the action that you requested has already been executed."
@echo ""
@echo "Please be careful running this Makefile and make sure you know what"
@echo "you do (especially with the Apache or Nginx webserver). For some actions you"
@echo "will need to be user 'root', this Makefile will test for it."
@echo "If you use 'make --dry-run [Makefile target]' the commands that are to be"
@echo "executed will be shown, but they will not be executed."
@echo ""
@echo "Informational commands for this Makefile:"
@echo "- make: Displays this message."
@echo "- make help: Displays this message."
@echo ""
@echo "Commands to install Ricgraph as a single user, recommended for"
@echo "new Ricgraph users or users that cannot change to user 'root' (please read"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_install_configure.md):"
@echo "- make install_neo4j_desktop: Download and install Neo4j Desktop."
@echo "- make full_singleuser_install: Install Ricgraph for a single user."
@echo " This will be done in a Python virtual environment"
@echo " in $(ricgraph_singleuser_install_dir)."
@echo " Also, a 'make install_neo4j_desktop' will be done (if not done yet)."
@echo ""
@echo "Commands to install Ricgraph as a server (you need to be 'root') (please read"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_as_server.md):"
@echo "- make install_enable_neo4j_community: Download, install, enable, and run"
@echo " Neo4j Community Edition."
@echo "- make full_server_install: Install Ricgraph as a server."
@echo " This will be done in a Python virtual environment"
@echo " in $(ricgraph_server_install_dir)."
@echo " Also, a 'make install_enable_neo4j_community' will be done"
@echo " (if not done yet)."
@echo "- make install_enable_ricgraphexplorer_restapi: Install, enable, and run"
@echo " Ricgraph Explorer and its REST API as a service."
@echo " This will also do a 'make full_server_install' (if not done yet)."
@echo "- make prepare_webserver_apache: Prepare webserver Apache for use with Ricgraph."
@echo " This will also do a 'make full_server_install' (if not done yet)."
@echo "- make prepare_webserver_nginx: Prepare webserver Nginx for use with Ricgraph."
@echo " For SURF Research Cloud you will need the Nginx webserver."
@echo " This will also do a 'make full_server_install' (if not done yet)."
@echo ""
@echo "Commands to run something:"
@echo "- make run_batchscript: run Ricgraph batch script '$(batch_script)'."
@echo " You can change the name of this script by"
@echo " adding 'batch_script=my_batchscript.py' to your 'make' command."
@echo " If you use Neo4j Desktop, you need to start it first."
@echo "- make run_ricgraph_explorer: run Ricgraph Explorer in development mode."
@echo " If you use Neo4j Desktop, you need to start it first."
@echo "- make run_anyscript: you can use this to run any Ricgraph script."
@echo " You may want to use command line parameters 'ricgraph_anyscript'"
@echo " and possibly 'ricgraph_anyscript_log'."
@echo ""
@echo "Advanced commands for this Makefile:"
@echo "- make makefile_variables: list all variables used in this Makefile."
@echo "- install the 'cutting edge' version of Ricgraph, i.e. the most current version"
@echo " of Ricgraph on GitHub ($(ricgraph_download)):"
@echo " add 'ricgraph_version=cuttingedge' to your 'make' command, e.g. as in"
@echo " 'make ricgraph_version=cuttingedge install_ricgraph_server'"
@echo "- make install_ricgraph_singleuser: Install Ricgraph for a single user."
@echo " This will be done in a Python virtual environment"
@echo " in $(ricgraph_singleuser_install_dir)."
@echo "- make install_ricgraph_server: Install Ricgraph as a server."
@echo " This will be done in a Python virtual environment"
@echo " in $(ricgraph_server_install_dir)."
@echo "- make dump_graphdb_neo4j_community: dump Neo4j Community graph database"
@echo " in directory $(graphdb_backup_dir)."
@echo "- make restore_graphdb_neo4j_community: restore Neo4j Community graph database"
@echo " from directory $(graphdb_backup_dir)."
@echo "- make generate_graphdb_password: generate a password for the graph database."
@echo " Write it to file $(graphdb_password_file)."
@echo " Only do this if the file does not exist."
@echo "- make specify_graphdb_password: specify (type) a password for the graph"
@echo " database. Write it to file $(graphdb_password_file)."
@echo " Always create this file, even if it already exists."
@echo "- make clean: removes files you have downloaded."
@echo " If you have used command line parameters for previous make calls"
@echo " (e.g. ricgraph_version=cuttingedge), you will have to call this clean"
@echo " with the same command line parameters."
@echo ""
all:
@echo ""
@echo "You have typed 'make all'."
@echo "With the Ricgraph Makefile, this will not install anything."
@echo "To learn about valid Makefile options (targets), type 'make help'."
@echo ""
makefile_variables:
@echo ""
@echo "This is a list of the internal variables in this Makefile:"
@echo "- ricgraph_version: $(ricgraph_version)"
@echo "- neo4j_community_version: $(neo4j_community_version)"
@echo "- neo4j_desktop_version: $(neo4j_desktop_version)"
@echo "- package_install_cmd: $(package_install_cmd)"
@echo "- python_cmd: $(python_cmd)"
@echo "- actual_python_minor_version: $(actual_python_minor_version)"
@echo "- minimal_python_minor_version: $(minimal_python_minor_version)"
@echo "- linux_name: $(linux_edition)"
@echo "- linux_version: $(linux_version)"
@echo "- HOME: $(HOME)"
@echo "- ricgraph_server_install_dir: $(ricgraph_server_install_dir)"
@echo "- ricgraph_singleuser_install_dir: $(ricgraph_singleuser_install_dir)"
@echo "- apache_vhosts_dir: $(apache_vhosts_dir)"
@echo "- apache_service_file: $(apache_service_file)"
@echo "- nginx_vhosts_dir: $(nginx_vhosts_dir)"
@echo "- neo4j_community: $(neo4j_community)"
@echo "- neo4j_community_path: $(neo4j_community_path)"
@echo "- neo4j_cyphershell: $(neo4j_cyphershell)"
@echo "- neo4j_cyphershell_path: $(neo4j_cyphershell_path)"
@echo "- neo4j_desktop: $(neo4j_desktop)"
@echo "- neo4j_desktop_path: $(neo4j_desktop_path)"
@echo "- graphdb_backup_dir: $(graphdb_backup_dir)"
@echo "- graphdb_password_file: $(graphdb_password_file)"
@echo "- graphdb_password_length: $(graphdb_password_length)"
@echo "- batch_script: $(batch_script)"
@echo "- batch_script_log: $(batch_script_log)"
@echo "- ricgraph_explorer: $(ricgraph_explorer)"
@echo ""
check_python_minor_version:
ifeq ($(python_cmd),[not_set])
@echo ""
@echo "Error: Python has not been installed, please install Python >= 3.$(minimal_python_minor_version) using your package manager."
@echo ""
exit 1
endif
@if [ $(actual_python_minor_version) -lt $(minimal_python_minor_version) ]; then \
echo "Error: Wrong Python version 3.$(actual_python_minor_version) on your system,"; \
echo "please install Python >= 3.$(minimal_python_minor_version) using your package manager."; \
exit 1; \
fi
check_user_root:
@if [ $(shell id -u) != 0 ]; then echo "Error: You need to be root. Please execute 'sudo bash' and then rerun the 'make' command you started with."; exit 1; fi
check_user_notroot:
@if [ $(shell id -u) = 0 ]; then echo "Error: You need to be a regular user. Please make sure you are and then rerun the 'make' command you started with."; exit 1; fi
check_package_install_cmd:
ifeq ($(package_install_cmd),[not_set])
@echo ""
@echo "Error: Your package manager is unknown. Please make sure you have"
@echo "a package manager that can install 'rpm' or 'deb' files."
@echo "That is required to install Neo4j Community Edition."
@echo ""
exit 1
endif
check_webserver_apache:
ifeq ($(shell test ! -f $(apache_service_file) && echo true),true)
@echo ""
@echo "Error: Apache webserver is not installed."
@echo "Please install it using your package manager."
@echo ""
exit 1
endif
check_webserver_nginx:
ifeq ($(shell test ! -f /lib/systemd/system/nginx.service && echo true),true)
@echo ""
@echo "Error: Nginx webserver is not installed."
@echo "Please install it using your package manager."
@echo ""
exit 1
endif
# Only seems necessary for Ubuntu.
install_python_venv: check_package_install_cmd
ifeq ($(shell test ! -e /usr/share/doc/python3-venv && echo true),true)
@if [ $(shell id -u) != 0 ]; then \
echo ""; \
echo "You are missing Python package 'python3-venv'. To install, please"; \
echo "change to user 'root' (type 'sudo bash') and execute 'make install_python_venv'."; \
echo "After that, exit from user 'root' and become a regular user again."; \
echo "Then rerun the 'make' command you started with."; \
echo ""; \
exit 1; \
fi
$(package_install_cmd) python3-venv
endif
# ########################################################################
# Ricgraph targets.
# ########################################################################
create_user_group_ricgraph: check_user_root
@# Do not put '[' and ']' around the condition of the if's below,
@# then it will not work.
@if ! getent group 'ricgraph' > /dev/null 2>&1; then groupadd --system ricgraph; echo "Created group 'ricgraph'."; fi
@if ! getent passwd 'ricgraph' > /dev/null 2>&1; then useradd --system --comment "Ricgraph user" --no-create-home --gid ricgraph ricgraph; echo "Created user 'ricgraph'."; fi
install_enable_neo4j_community: check_user_root check_python_minor_version check_package_install_cmd generate_graphdb_password
ifeq ($(shell test ! -f /lib/systemd/system/neo4j.service && echo true),true)
@echo ""
@echo "Starting Install and enable Neo4j Community Edition. Read documentation at:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_as_server.md#install-and-start-neo4j-community-edition"
$(call are_you_sure)
@echo ""
@if [ ! -f $(HOME)/$(neo4j_community) ]; then cd $(HOME); echo "Downloading Neo4j Community Edition..."; wget $(neo4j_community_path); fi
@if [ ! -f $(HOME)/$(neo4j_cyphershell) ]; then cd $(HOME); echo "Downloading Neo4j Cypher Shell..."; wget $(neo4j_cyphershell_path); fi
$(package_install_cmd) $(HOME)/$(neo4j_cyphershell)
$(package_install_cmd) $(HOME)/$(neo4j_community)
@echo "If you get any errors on missing dependencies, please install them using '$(package_install_cmd)'."
$(call read_graphdb_password)
@# The following can only be done if you have not started Neo4j yet.
neo4j-admin dbms set-initial-password $(graphdb_password)
$(systemctl_cmd) enable neo4j.service
$(systemctl_cmd) start neo4j.service
@echo ""
@echo "Done."
@echo "Neo4j Community Edition version $(neo4j_community_version) has"
@echo "been installed, enabled and will be run at system start."
@echo "The password to access it can be found in $(graphdb_password_file)."
@echo ""
endif
install_neo4j_desktop: check_user_notroot check_python_minor_version generate_graphdb_password
ifeq ($(shell test ! -f $(HOME)/$(neo4j_desktop) && echo true),true)
@echo ""
@echo "Starting Download and install Neo4j Desktop. Read documentation at:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_install_configure.md#install-neo4j-desktop"
$(call are_you_sure)
@echo ""
@cd $(HOME); echo "Downloading Neo4j Desktop..."; wget $(neo4j_desktop_path)
chmod 755 $(HOME)/$(neo4j_desktop)
@echo ""
@echo "Done."
@echo "Neo4j Desktop version $(neo4j_desktop_version) has been downloaded."
@echo "Before you can use it, please read the post-install steps at"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_install_configure.md#post-install-steps-neo4j-desktop"
@echo "One of the steps is to fill in a password. Use the"
@echo "password in file $(graphdb_password_file)."
@echo "If you do this, you do not need to fill in this password in"
@echo "file 'ricgraph.ini' later on, this Makefile will take care of it."
@echo ""
endif
full_server_install: install_enable_neo4j_community install_ricgraph_server
@echo ""
install_ricgraph_server: check_user_root check_python_minor_version create_user_group_ricgraph
ifeq ($(shell test ! -d $(ricgraph_server_install_dir) && echo true),true)
@# This test is placed here instead of in function install_ricgraph
@# because it will keep the code of install_ricgraph more clear.
$(call install_ricgraph,$(ricgraph_server_install_dir),"server","neo4j_community_edition",$(ricgraph_version),$(readdoc_server))
endif
full_singleuser_install: install_neo4j_desktop install_ricgraph_singleuser
@echo ""
install_ricgraph_singleuser: check_user_notroot check_python_minor_version
ifeq ($(shell test ! -d $(ricgraph_singleuser_install_dir) && echo true),true)
@# This test is placed here instead of in function install_ricgraph
@# because it will keep the code of install_ricgraph more clear.
$(call install_ricgraph,$(ricgraph_singleuser_install_dir),"singleuser","neo4j_desktop",$(ricgraph_version),$(readdoc_singleuser))
endif
install_enable_ricgraphexplorer_restapi: check_user_root full_server_install
ifeq ($(shell test ! -f /etc/systemd/system/ricgraph_explorer_gunicorn.service && echo true),true)
@echo ""
@echo "Starting Install and enable Ricgraph Explorer and REST API."
@echo "Read documentation at:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_as_server.md#use-a-service-unit-file-to-run-ricgraph-explorer-and-the-ricgraph-rest-api"
$(call are_you_sure)
@echo ""
cp $(ricgraph_server_install_dir)/ricgraph_server_config/ricgraph_explorer_gunicorn.service /etc/systemd/system
$(systemctl_cmd) daemon-reload
$(systemctl_cmd) enable ricgraph_explorer_gunicorn.service
$(systemctl_cmd) start ricgraph_explorer_gunicorn.service
@echo ""
@echo "Done."
@echo "Ricgraph Explorer and the Ricgraph REST API have"
@echo "been enabled and will be run at system start."
@echo "These are only accessible at this (local) machine."
@echo "You can use Ricgraph Explorer by typing http://localhost:3030 in"
@echo "your web browser, or you can use the Ricgraph REST API by using"
@echo "the path http://localhost:3030/api followed by a REST API endpoint."
@echo ""
endif
prepare_webserver_apache: check_user_root check_webserver_apache full_server_install
ifeq ($(shell test ! -f $(apache_vhosts_dir)/ricgraph_explorer.conf && echo true),true)
ifeq ($(shell test ! -f $(apache_vhosts_dir)/ricgraph_explorer.conf-apache && echo true),true)
@echo ""
@echo "Starting Preparing webserver Apache for use with Ricgraph."
@echo "Read documentation at:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_as_server.md#use-apache-wsgi-and-asgi-to-make-ricgraph-explorer-and-the-ricgraph-rest-api-accessible-from-outside-your-virtual-machine"
$(call are_you_sure)
@echo ""
cp $(ricgraph_server_install_dir)/ricgraph_server_config/ricgraph_explorer.conf-apache $(apache_vhosts_dir)
chmod 600 $(apache_vhosts_dir)/ricgraph_explorer.conf-apache
a2enmod mod_proxy
a2enmod mod_proxy_http
@echo ""
@echo "Done."
@echo "Webserver Apache has been prepared. To make it work, continue reading at:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_as_server.md#post-install-steps-apache"
@echo ""
endif
endif
prepare_webserver_nginx: check_user_root check_webserver_nginx full_server_install
ifeq ($(shell test ! -f $(nginx_vhosts_dir)/ricgraph_explorer.conf && echo true),true)
ifeq ($(shell test ! -f $(nginx_vhosts_dir)/ricgraph_explorer.conf-nginx && echo true),true)
@echo ""
@echo "Starting Preparing webserver Nginx for use with Ricgraph."
@echo "Read documentation at:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_as_server.md#use-nginx-wsgi-and-asgi-to-make-ricgraph-explorer-and-the-ricgraph-rest-api-accessible-from-outside-your-virtual-machine"
$(call are_you_sure)
@echo ""
cp $(ricgraph_server_install_dir)/ricgraph_server_config/ricgraph_explorer.conf-nginx $(nginx_vhosts_dir)
chmod 600 $(nginx_vhosts_dir)/ricgraph_explorer.conf-nginx
@echo ""
@echo "Done."
@echo "Webserver Nginx has been prepared. To make it work, continue reading at:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_as_server.md#post-install-steps-nginx"
@echo ""
endif
endif
# Documentation for dump & restore: https://neo4j.com/docs/operations-manual/current/kubernetes/operations/dump-load
dump_graphdb_neo4j_community: check_user_root
ifneq ($(shell which neo4j-admin > /dev/null 2>&1 && echo $$?),0)
@echo ""
@echo "Error: You need the 'neo4j-admin' command to dump a graph database."
@echo "You can install it by running 'make install_enable_neo4j_community'."
@echo ""
exit 1
endif
@echo ""
@echo "Starting Dump of graph database of Neo4j Community Edition in"
@echo "directory $(graphdb_backup_dir)."
@echo "Read documentation at:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_install_configure.md#create-a-neo4j-community-edition-database-dump-of-ricgraph"
$(call are_you_sure)
@echo ""
@if [ ! -d $(graphdb_backup_dir) ]; then mkdir $(graphdb_backup_dir); fi
@if [ -f $(graphdb_backup_dir)/system.dump ]; then echo "Error: Graph database dump file $(graphdb_backup_dir)/system.dump does exist, you might overwrite an existing dump. Please remove it first."; exit 1; fi
@if [ -f $(graphdb_backup_dir)/neo4j.dump ]; then echo "Error: Graph database dump file $(graphdb_backup_dir)/neo4j.dump does exist, you might overwrite an existing dump. Please remove it first."; exit 1; fi
$(systemctl_cmd) stop neo4j.service
chmod 640 /etc/neo4j/*
chmod 750 /etc/neo4j
neo4j-admin database dump --expand-commands system --to-path=$(graphdb_backup_dir)
neo4j-admin database dump --expand-commands neo4j --to-path=$(graphdb_backup_dir)
$(systemctl_cmd) start neo4j.service
@echo ""
@echo "Done."
@echo "The graph database of Neo4j Community Edition has been dumped"
@echo "in directory $(graphdb_backup_dir)."
@echo ""
restore_graphdb_neo4j_community: check_user_root
ifneq ($(shell which neo4j-admin > /dev/null 2>&1 && echo $$?),0)
@echo ""
@echo "Error: You need the 'neo4j-admin' command to restore a graph database."
@echo "You can install it by running 'make install_enable_neo4j_community'."
@echo ""
exit 1
endif
@echo ""
@echo "Starting Restore of graph database of Neo4j Community Edition"
@echo "from directory $(graphdb_backup_dir)."
@echo "Your old graph database will be removed."
@echo "Read documentation at:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_install_configure.md#restore-a-neo4j-community-edition-database-dump-of-ricgraph-in-neo4j-community-edition"
$(call are_you_sure)
@echo ""
@if [ ! -f $(graphdb_backup_dir)/system.dump ]; then echo "Error: Graph database dump file $(graphdb_backup_dir)/system.dump does not exist."; exit 1; fi
@if [ ! -f $(graphdb_backup_dir)/neo4j.dump ]; then echo "Error: Graph database dump file $(graphdb_backup_dir)/neo4j.dump does not exist."; exit 1; fi
$(systemctl_cmd) stop neo4j.service
chmod 640 /etc/neo4j/*
chmod 750 /etc/neo4j
@# Save old database
@if [ -d /var/lib/neo4j ]; then mv /var/lib/neo4j /var/lib/neo4j-`date +%y%m%d-%H%M`; fi
mkdir /var/lib/neo4j
neo4j-admin database load --expand-commands system --from-path=$(graphdb_backup_dir) --overwrite-destination=true
neo4j-admin database load --expand-commands neo4j --from-path=$(graphdb_backup_dir) --overwrite-destination=true
chown -R neo4j:neo4j /var/lib/neo4j
$(systemctl_cmd) start neo4j.service
@echo ""
@echo "Done."
@echo "The graph database of Neo4j Community Edition has been restored"
@echo "from directory $(graphdb_backup_dir)."
@echo ""
@echo "If you use the Ricgraph Explorer gunicorn service, please execute"
@echo "the command 'systemctl restart ricgraph_explorer_gunicorn' now."
@echo ""
@echo "If you get a warning that the system database may contain unwanted"
@echo "metadata from the DBMS it was taken from, please ignore it."
@echo ""
run_batchscript:
@echo ""
@echo "This target will run Ricgraph batch script harvest/$(batch_script)."
@echo "The output will be both on screen as well as in file"
@echo "harvest/$(batch_script_log)."
@echo "It may take a while before the output appears on screen,"
@echo "this is due to buffering of the output."
@echo ""
@echo "If you continue, this script might delete your current graph database."
$(call are_you_sure)
@echo ""
@if [ ! -f harvest/$(batch_script) ]; then echo "Error: batch script '$(batch_script)' does not exist."; exit 1; fi
@if [ $(shell id -u) = 0 ]; then \
sudo -u ricgraph bash -c 'cd harvest; ../bin/python $(batch_script) | tee $(batch_script_log)'; \
else \
cd harvest; ../bin/python $(batch_script) | tee $(batch_script_log); \
fi
run_ricgraph_explorer:
@echo ""
@echo "This target will run Ricgraph Explorer in development mode"
@echo "from ricgraph_explorer/$(ricgraph_explorer)."
@echo ""
@if [ ! -f ricgraph_explorer/$(ricgraph_explorer) ]; then echo "Error: script '$(ricgraph_explorer)' does not exist."; exit 1; fi
cd ricgraph_explorer; ../bin/python $(ricgraph_explorer)
run_anyscript:
@echo ""
@echo "This target will run Ricgraph script $(ricgraph_anyscript)."
@echo "The output will be both on screen as well as in file"
@echo "$(ricgraph_anyscript_log)."
@echo "If you don't have write permission to this file, you will get an error."
@echo "It may take a while before the output appears on screen,"
@echo "this is due to buffering of the output."
$(call are_you_sure)
@echo ""
@if [ ! -f ricgraph_explorer/$(ricgraph_explorer) ]; then echo "Error: script '$(ricgraph_explorer)' does not exist."; exit 1; fi
@# Check if the path to 'ricgraph_anyscript_log' starts with '/'. If so, it is considered a full path.
@if [ $(shell echo $(ricgraph_anyscript_log) | cut -c1) = '/' ]; then \
cd $(dir $(ricgraph_anyscript)); ../bin/python $(notdir $(ricgraph_anyscript)) | tee $(ricgraph_anyscript_log); \
else \
cd $(dir $(ricgraph_anyscript)); ../bin/python $(notdir $(ricgraph_anyscript)) | tee ../$(ricgraph_anyscript_log); \
fi
generate_graphdb_password:
@if [ ! -f $(graphdb_password_file) ]; then \
< /dev/urandom tr -dc 'A-Za-z0-9' | head -c $(graphdb_password_length) > $(graphdb_password_file); \
echo "Created graphdb_password_file $(graphdb_password_file)."; \
fi
specify_graphdb_password:
@echo -n "Specify the graph database password you want to use: "
@read answer && echo -n "$$answer" > $(graphdb_password_file)
@echo "Created graphdb_password_file $(graphdb_password_file)."
# Note that if you have used command line parameters for previous make calls
# (e.g. ricgraph_version=cuttingedge), you will have to call this clean
# with the same command line parameters.
clean:
rm -f $(HOME)/$(neo4j_cyphershell) $(HOME)/$(neo4j_community)
rm -f $(dir $(ricgraph_server_install_dir))/$(ricgraph_tag_name)
rm -f $(dir $(ricgraph_singleuser_install_dir))/$(ricgraph_tag_name)
# ########################################################################
# Ricgraph functions.
# ########################################################################
define read_graphdb_password
@if [ ! -f $(graphdb_password_file) ]; then \
echo "Error: graphdb_password_file $(graphdb_password_file) not found."; \
echo "You need to install Neo4j first. This will generate this file."; \
exit 1; \
fi
$(eval graphdb_password := $(shell cat $(graphdb_password_file)))
endef
define are_you_sure
@if [ $(ask_are_you_sure) != "no" ]; then \
if echo -n "Are you sure you want to proceed? [y/n] " && read ans && ! [ $${ans:-N} = y ]; then \
echo "Make stopped."; \
exit 1; \
fi \
fi
endef
# $(1) is install location (full path), $(2) is either "server" or "singleuser",
# $(3) is either "neo4j_desktop" or "neo4j_community_edition", $(4) is version, $(5) is documentation link.
define install_ricgraph
@echo ""
@echo "Starting install of Ricgraph version '$(4)' in"
@echo "directory '$(1)'."
@echo "as '$(2)'. The database to be used is '$(3)'."
@echo "Read documentation at $(5)."
$(call are_you_sure)
@echo ""
@if [ -d $(1) ]; then echo -e "Error: Ricgraph install dir $(1) already exists,\nplease remove it first."; exit 1; fi
@if [ $(2) != "server" ] && [ $(2) != "singleuser" ]; then echo "Error: wrong value for parameter #2: '$(2)'."; exit 1; fi
@if [ $(3) != "neo4j_desktop" ] && [ $(3) != "neo4j_community_edition" ]; then echo "Error: wrong value for parameter #3: '$(3)'."; exit 1; fi
@# Only seems necessary for Ubuntu.
@if [ "$(linux_edition)" = "Ubuntu" ]; then \
make install_python_venv; \
fi
@if [ ! -d $(dir $(1)) ]; then mkdir -p $(dir $(1)); fi
@# Note $(4) is version. If it is 'cuttingedge', download it first.
@if [ "$(4)" = "cuttingedge" ]; then \
mkdir $(tmp_dir); \
cd $(tmp_dir); \
echo "Downloading Ricgraph cutting edge version..."; \
wget $(ricgraph_cuttingedge_path); \
unzip -q $(ricgraph_cuttingedge_name); \
mv ricgraph-main $(ricgraph); \
echo "This is the cutting edge version of Ricgraph of `date +%y%m%d-%H%M`." > $(ricgraph)/0_ricgraph_cuttingedge_`date +%y%m%d-%H%M`; \
tar czf $(ricgraph_tag_name) $(ricgraph); \
mv -f $(ricgraph_tag_name) $(dir $(1)); \
rm -r $(tmp_dir); \
fi
@if [ ! -f $(dir $(1))/$(ricgraph_tag_name) ]; then cd $(dir $(1)); echo "Downloading Ricgraph..."; wget $(ricgraph_path); fi
$(python_cmd) -m venv $(1)
cd $(1); tar xf $(dir $(1))/$(ricgraph_tag_name)
mv $(1)/$(ricgraph)/* $(1)
rm -r $(1)/$(ricgraph)
$(1)/bin/pip install setuptools pip wheel
$(1)/bin/pip install -r $(1)/requirements.txt
cp $(1)/ricgraph.ini-sample $(1)/ricgraph.ini
$(call read_graphdb_password)
sed -i 's/^graphdb_password =/graphdb_password = $(graphdb_password)/' $(1)/ricgraph.ini
@# Neo4j Desktop is the default in ricgraph.ini, for Community we need to modify.
@# Note $(3) is either "neo4j_desktop" or "neo4j_community_edition".
@if [ "$(3)" = "neo4j_community_edition" ]; then \
sed -i 's/^graphdb_scheme = bolt/###graphdb_scheme = bolt/' $(1)/ricgraph.ini; \
sed -i 's/^graphdb_port = 7687/###graphdb_port = 7687/' $(1)/ricgraph.ini; \
sed -i 's/^#graphdb_scheme = neo4j/graphdb_scheme = neo4j/' $(1)/ricgraph.ini; \
sed -i 's/^#graphdb_port = 7687/graphdb_port = 7687/' $(1)/ricgraph.ini; \
fi
@if [ "$(2)" = "server" ]; then \
chown -R ricgraph:ricgraph $(dir $(1)); \
chmod -R go-w $(dir $(1)); \
fi
@echo ""
@echo "Done."
@echo "Ricgraph version '$(4)' has been installed in"
@echo "a Python virtual environment in '$(1)'."
@echo "You may want to modify '$(1)/ricgraph.ini' to suit"
@echo "your needs, please read:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_install_configure.md#ricgraph-initialization-file"
@echo ""
@echo "Please read this to learn how to start Ricgraph scripts from the command line:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_as_server.md#in-case-you-have-installed-ricgraph-as-a-server"
@echo ""
@echo "Alternatively, you may want to install a Python Integrated"
@echo "development environment (IDE), such as PyCharm. Read documenentation at:"
@echo "https://github.com/UtrechtUniversity/ricgraph/blob/main/docs/ricgraph_install_configure.md#using-a-python-integrated-development-environment-ide"
@echo ""
endef