From 805c1c2669d94207917e02a637a31ed55165fe05 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Mon, 6 Jul 2020 14:57:59 +0200 Subject: [PATCH] Import the orientdb role. Add a systemd unit file. --- README.md | 25 +-- defaults/main.yml | 81 ++++++++- handlers/main.yml | 4 +- meta/main.yml | 56 +++--- tasks/main.yml | 162 +++++++++++++++++- templates/automatic-backup.json.j2 | 11 ++ templates/backup-cleaner.sh.j2 | 8 + .../default-distributed-db-config.json.j2 | 18 ++ templates/hazelcast.xml.j2 | 45 +++++ templates/orientdb-letsencrypt-acme.sh.j2 | 42 +++++ templates/orientdb-nrpe.cfg.j2 | 3 + templates/orientdb-server-config.xml.j2 | 118 +++++++++++++ templates/orientdb-server-log.properties.j2 | 46 +++++ templates/orientdb.default.j2 | 8 + templates/orientdb.init.j2 | 83 +++++++++ templates/orientdb.service.j2 | 21 +++ 16 files changed, 675 insertions(+), 56 deletions(-) create mode 100644 templates/automatic-backup.json.j2 create mode 100644 templates/backup-cleaner.sh.j2 create mode 100644 templates/default-distributed-db-config.json.j2 create mode 100644 templates/hazelcast.xml.j2 create mode 100644 templates/orientdb-letsencrypt-acme.sh.j2 create mode 100644 templates/orientdb-nrpe.cfg.j2 create mode 100644 templates/orientdb-server-config.xml.j2 create mode 100644 templates/orientdb-server-log.properties.j2 create mode 100644 templates/orientdb.default.j2 create mode 100755 templates/orientdb.init.j2 create mode 100644 templates/orientdb.service.j2 diff --git a/README.md b/README.md index 3637db8..c828725 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,20 @@ Role Name ========= -A brief description of the role goes here. - -Requirements ------------- - -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. +A role that installs the community version of OrientDB Role Variables -------------- -A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. +The most important variables are listed below: + +``` yaml +``` Dependencies ------------ -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. - -Example Playbook ----------------- - -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - - - hosts: servers - roles: - - { role: username.rolename, x: 42 } +* openjdk License ------- @@ -35,4 +24,4 @@ EUPL-1.2 Author Information ------------------ -An optional section for the role authors to include contact information, or a website (HTML is not allowed). +Andrea Dell'Amico, diff --git a/defaults/main.yml b/defaults/main.yml index 95d3c70..2689ace 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,81 @@ --- -# defaults file for ansible-role-template \ No newline at end of file +orientdb_install: False +orientdb_enabled: True +orientdb_version: 3.0.31 +orientdb_archive_commpression: tar.gz +orientdb_dir: 'orientdb' +orientdb_tar_filename: '{{ orientdb_dir }}-{{ orientdb_version }}' +orientdb_tar_file: '{{ orientdb_tar_filename }}.{{ orientdb_archive_commpression }}' +orientdb_binary_distribution_url: 'https://s3.us-east-2.amazonaws.com/orientdb3/releases/{{ orientdb_version }}/{{ orientdb_tar_file }}' +orientdb_user: orientdb +orientdb_log_dir: /var/log/orientdb +orientdb_log_level: INFO +orientdb_home_prefix: /home +orientdb_base_dir: '{{ orientdb_home_prefix }}/{{ orientdb_user }}' +orientdb_install_dir: '{{ orientdb_base_dir }}/{{ orientdb_dir }}' +orientdb_data_dir: '{{ orientdb_home_prefix }}/{{ orientdb_user }}/databases' +orientdb_pid_dir: '{{ orientdb_home_prefix }}/{{ orientdb_user }}/pid' +orientdb_configuration_files: + - orientdb-server-log.properties + - orientdb-server-config.xml + - default-distributed-db-config.json + - hazelcast.xml + - automatic-backup.json + +orientdb_ssl_enabled: False +orientdb_letsencrypt_ssl_enabled: False +orientdb_ssl_client_auth_enabled: False + +orientdb_hooks_classes: + - { name: 'org.gcube.informationsystem.orientdb.hooks.HeaderHook', position: 'REGULAR' } + - { name: 'org.gcube.informationsystem.orientdb.hooks.ConsistsOfHook', position: 'REGULAR' } + - { name: 'org.gcube.informationsystem.orientdb.hooks.IsRelatedToHook', position: 'REGULAR' } + +#orientdb_hooks_jars: +# - 'http://maven.research-infrastructures.eu/nexus/service/local/artifact/maven/redirect?r=gcube-snapshots&g=org.gcube.information-system&a=resource-registry-orientdb-hooks&v=1.3.0-SNAPSHOT&e=jar&c=jar-with-dependencies' +#orientdb_hooks_to_be_removed: +# - hook*.jar + +orientdb_binary_protocol_lower_port: 2424 +orientdb_binary_protocol_higher_port: 2430 +orientdb_ssl_protocol_lower_port: 2434 +orientdb_ssl_protocol_higher_port: 2440 +orientdb_http_protocol_lower_port: 2480 +orientdb_http_protocol_higher_port: 2490 + +orientdb_java_heap: '-Xms1024m -Xmx2048m' +orientdb_default_settings: '' + +orientdb_distributed: False +orientdb_distributed_autodeploy: 'true' +orientdb_distributed_writequorum: 'majority' +#orientdb_distributed_writequorum: 'all' +orientdb_distributed_readquorum: 1 +orientdb_distributed_readyourwrites: 'true' +orientdb_distributed_executionmode: 'undefined' +orientdb_new_node_strategy: 'dynamic' + +orientbd_graph_server_enabled: False + +orientdb_hazelcast_group_name: orientdb +orientdb_hazelcast_group_password: orientdb +orientbd_hazelcast_encryption: False +orientdb_hazelcast_port_min: 2434 +orientdb_hazelcast_port_max: 2454 +orientdb_hazelcast_multicast_enabled: False +orientdb_hazelcast_multicast_group: 235.1.1.1 +orientdb_hazelcast_unicast_members: + - { member: 'localhost', port: '{{ orientdb_hazelcast_port_min }}' } + + +# For Reference see http://orientdb.com/docs/3.0.x/plugins/Automatic-Backup.html +orientdb_automatic_backup: True +orientdb_automatic_backup_mode: 'EXPORT' +orientdb_automatic_backup_export_options: '' +orientdb_automatic_backup_delay: 24h +orientdb_automatic_backup_first_time: '23:00:00' +orientdb_automatic_backup_directory: '{{ orientdb_home_prefix }}/{{ orientdb_user }}/backups' +orientdb_automatic_backup_target_file_name: '${DBNAME}-${DATE:yyyyMMddHHmmss}.zip' +orientdb_automatic_backup_compression_level: 9 +orientdb_automatic_backup_buffer_size: 1048576 +orientdb_automatic_backup_retention_days: '7' diff --git a/handlers/main.yml b/handlers/main.yml index 27474e0..52964c3 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,4 @@ --- -# handlers file for ansible-role-template \ No newline at end of file +- name: Restart orientdb + service: name=orientdb state=restarted sleep=30 + when: orientdb_enabled diff --git a/meta/main.yml b/meta/main.yml index 81bda14..7d6af4d 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,46 +1,32 @@ galaxy_info: - author: your name - description: your description - company: your company (optional) + author: Andrea Dell'Amico + description: Systems Architect + company: ISTI-CNR - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value - issue_tracker_url: https://support.d4science.org/projects/automatic-provisioning/issues + issue_tracker_url: https://redmine-s2i2s.isti.cnr.it/projects/provisioning - license: EUPL-1.2 + license: EUPL 1.2+ min_ansible_version: 2.8 - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - - # Optionally specify the branch Galaxy will use when accessing the GitHub - # repo for this role. During role install, if no tags are available, - # Galaxy will use this branch. During import Galaxy will access files on - # this branch. If Travis integration is configured, only notifications for this - # branch will be accepted. Otherwise, in all cases, the repo's default branch - # (usually master) will be used. - #github_branch: - - # - # Provide a list of supported platforms, and for each platform a list of versions. - # If you don't wish to enumerate all versions for a particular platform, use 'all'. # To view available platforms and versions (or releases), visit: # https://galaxy.ansible.com/api/v1/platforms/ # platforms: - - name: Ubuntu - versions: - - bionic - - galaxy_tags: [] - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. + - name: Ubuntu + versions: + - Trusty + - bionic + - name: EL + versions: + - 7 + + galaxy_tags: + - orientdb + +dependencies: + - src: git+https://gitea-s2i2s.isti.cnr.it/ISTI-ansible-roles/ansible-role-openjdk.git + version: master + name: openjdk + state: latest -dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 53c6cae..8d9e951 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,162 @@ --- -# tasks file for ansible-role-template \ No newline at end of file +- block: + - name: Create the orientdb user + user: name={{ orientdb_user }} home={{ orientdb_base_dir }} createhome=yes shell=/bin/bash + + - name: Get the orientdb distribution + get_url: url={{ orientdb_binary_distribution_url }} dest={{ orientdb_base_dir }}/{{ orientdb_tar_file }} validate_certs=no + + - name: Unpack the orientdb distribution + unarchive: src={{ orientdb_base_dir }}/{{ orientdb_tar_file }} dest={{ orientdb_base_dir }} copy=no + args: + creates: '{{ orientdb_home_prefix }}/{{ orientdb_user }}/{{ orientdb_dir }}-{{ orientdb_version }}' + + - name: Link to the latest version + become: True + become_user: '{{ orientdb_user }}' + file: src={{ orientdb_tar_filename }} dest={{ orientdb_install_dir }} state=link + + - name: Create a orientdb log directory out of the distribution directory + file: dest={{ orientdb_log_dir }} state=directory owner={{ orientdb_user }} group={{ orientdb_user }} mode=0755 + + - name: Link the log directory inside the orientdb user home + become: True + become_user: '{{ orientdb_user }}' + file: dest={{ orientdb_home_prefix }}/{{ orientdb_user }}/logs src={{ orientdb_log_dir }} state=link + + - name: Create the needed directory inside the orientdb user home + become: True + become_user: '{{ orientdb_user }}' + file: dest={{ item }} state=directory mode=0750 + with_items: + - '{{ orientdb_data_dir }}' + - '{{ orientdb_pid_dir }}' + - '{{ orientdb_automatic_backup_directory }}' + + - name: Remove the old hook jars + shell: rm -f {{ orientdb_install_dir }}/lib/{{ item }} + with_items: '{{ orientdb_hooks_to_be_removed | default([]) }}' + tags: [ 'orientdb', 'orientdb_hooks' ] + + - name: Fetch and install the hook jars + get_url: url='{{ item }}' dest={{ orientdb_install_dir }}/lib + with_items: '{{ orientdb_hooks_jars | default([]) }}' + notify: Restart orientdb + tags: [ 'orientdb', 'orientdb_hooks' ] + + - name: Install the orientdb default settings + template: src=orientdb.default.j2 dest=/etc/default/orientdb owner=root group=root mode=0444 + notify: Restart orientdb + + - name: Fix the pid file path inside the start and shutdown scripts + lineinfile: dest={{ orientdb_install_dir }}/bin/{{ item }} regexp="^ORIENTDB_PID=.*$" line="ORIENTDB_PID={{ orientdb_pid_dir }}/orientdb.pid" insertafter="^PRG=.*$" firstmatch=yes + with_items: + - server.sh + - shutdown.sh + tags: [ 'orientdb', 'orientdb_pid' ] + + - name: Install the orientdb configuration files + template: src={{ item }}.j2 dest={{ orientdb_install_dir }}/config/{{ item }} owner={{ orientdb_user }} group={{ orientdb_user }} mode=0640 + with_items: '{{ orientdb_configuration_files }}' + notify: Restart orientdb + tags: [ 'orientdb', 'orientdb_config' ] + + - name: Install the nagios nrpe configuration + template: src=orientdb-nrpe.cfg.j2 dest={{ nrpe_include_dir }}/orientdb-nrpe.cfg owner=root group=root mode=0444 + notify: Reload NRPE server + when: + - nrpe_include_dir is defined + - nagios_enabled is defined and nagios_enabled + tags: [ 'orientdb', 'orientdb_nagios' ] + + - name: Install the orientdb SYSV startup script + template: src=orientdb.init.j2 dest=/etc/init.d/orientdb owner=root group=root mode=0755 + tags: [ 'orientdb', 'orientdb_init' ] + when: ansible_service_mgr != 'systemd' + + - name: Install the orientdb systemd unit + template: src=orientdb.service.j2 dest=/usr/lib/systemd/system/orientdb.service owner=root group=root mode=0644 + tags: [ 'orientdb', 'orientdb_init' ] + when: ansible_service_mgr == 'systemd' + register: reload_systemd + + - name: Reload the systemd service + systemd: + daemon_reload: yes + when: reload_systemd is changed + + - name: Ensure that the service is enabled and running + service: name=orientdb state=started enabled=yes + when: orientdb_enabled + + - name: Ensure that the service is stopped and disabled + service: name=orientdb state=stopped enabled=no + when: not orientdb_enabled + + tags: orientdb + when: orientdb_install + +- block: + - name: Install a script that removes the old orientdb backups + template: src=backup-cleaner.sh.j2 dest=/usr/local/bin/orientdb-backup-cleaner owner=root group=root mode=555 + + - name: Add a cron job that removes the old backups + cron: + cron_file: 'orientdb-backup-cleaner' + disabled: no + job: "/usr/local/bin/orientdb-backup-cleaner >/dev/null 2>&1" + special_time: daily + user: '{{ orientdb_user }}' + name: "Remove old orientdb backups" + state: present + + tags: [ 'orientdb', 'orientdb_backup' ] + when: orientdb_install + + +- block: + - name: Create the acme hooks directory if it does not yet exist + file: dest={{ letsencrypt_acme_services_scripts_dir }} state=directory owner=root group=root + + - name: Install a letsencrypt hook to update the orientdb certificate + template: src=orientdb-letsencrypt-acme.sh.j2 dest={{ letsencrypt_acme_services_scripts_dir }}/orientdb owner=root group=root mode=4555 + + tags: [ 'orientdb', 'letsencrypt', 'orientdb_letsencrypt' ] + when: + - orientdb_install + - orientdb_letsencrypt_ssl_enabled + +- block: + - name: Ensure that the service is disabled and stopped + service: name=orientdb state=stopped enabled=no + + - name: Remove the orientdb SysV startup file + file: dest=/etc/init.d/orientdb state=absent + when: ansible_service_mgr != 'systemd' + + - name: Remove the orientdb systemd unit + file: dest=/usr/lib/systemd/system/orientdb.service state=absent + when: ansible_service_mgr == 'systemd' + + - name: Remove the link to the orientdb distribution + file: dest={{ orientdb_home_prefix }}/{{ orientdb_user }}/{{ orientdb_dir }} state=absent + + - name: Remove the default options file + file: dest=/etc/default/orientdb state=absent + + - name: Remove the backup cleaner script + file: dest=/usr/local/bin/orientdb-backup-cleaner state=absent + + - name: Remove the backup cleaner cron job + cron: + cron_file: 'orientdb-backup-cleaner' + disabled: no + job: "/usr/local/bin/orientdb-backup-cleaner >/dev/null 2>&1" + special_time: daily + user: '{{ orientdb_user }}' + name: "Remove old orientdb backups" + state: absent + + tags: orientdb + when: not orientdb_install + diff --git a/templates/automatic-backup.json.j2 b/templates/automatic-backup.json.j2 new file mode 100644 index 0000000..398b642 --- /dev/null +++ b/templates/automatic-backup.json.j2 @@ -0,0 +1,11 @@ +{ + "enabled": {{ orientdb_automatic_backup | ternary('true','false') }}, + "mode": "{{ orientdb_automatic_backup_mode }}", + "exportOptions": "{{ orientdb_automatic_backup_export_options }}", + "delay": "{{ orientdb_automatic_backup_delay }}", + "firstTime": "{{ orientdb_automatic_backup_first_time }}", + "targetDirectory": "{{ orientdb_automatic_backup_directory }}", + "targetFileName": "{{ orientdb_automatic_backup_target_file_name }}", + "compressionLevel": {{orientdb_automatic_backup_compression_level }}, + "bufferSize": {{ orientdb_automatic_backup_buffer_size }} +} \ No newline at end of file diff --git a/templates/backup-cleaner.sh.j2 b/templates/backup-cleaner.sh.j2 new file mode 100644 index 0000000..4b14cae --- /dev/null +++ b/templates/backup-cleaner.sh.j2 @@ -0,0 +1,8 @@ +#!/bin/bash + +BACKUP_RETENTION_DAYS="{{ orientdb_automatic_backup_retention_days }}" +BACKUP_DIRECTORY="{{ orientdb_automatic_backup_directory }}" + +find ${BACKUP_DIRECTORY} -atime +${BACKUP_RETENTION_DAYS} -type f -exec rm -f {} \; + +exit 0 diff --git a/templates/default-distributed-db-config.json.j2 b/templates/default-distributed-db-config.json.j2 new file mode 100644 index 0000000..44ebb7b --- /dev/null +++ b/templates/default-distributed-db-config.json.j2 @@ -0,0 +1,18 @@ +{ + "autoDeploy": {{ orientdb_distributed_autodeploy }}, + "readQuorum": {{ orientdb_distributed_readquorum }}, + "writeQuorum": "{{ orientdb_distributed_writequorum }}", + "executionMode": "{{ orientdb_distributed_executionmode }}", + "readYourWrites": {{ orientdb_distributed_readyourwrites }}, + "newNodeStrategy": "{{ orientdb_new_node_strategy }}", + "servers": { + "*": "master" + }, + "clusters": { + "internal": { + }, + "*": { + "servers": [""] + } + } +} diff --git a/templates/hazelcast.xml.j2 b/templates/hazelcast.xml.j2 new file mode 100644 index 0000000..6ba4cfb --- /dev/null +++ b/templates/hazelcast.xml.j2 @@ -0,0 +1,45 @@ + + + + + + {{ orientdb_hazelcast_group_name }} + {{ orientdb_hazelcast_group_password }} + + + {{ orientdb_hazelcast_port_min }} + + + {{ orientdb_hazelcast_multicast_group }} + {{ orientdb_hazelcast_port_min }} + + {% if not orientdb_hazelcast_multicast_enabled %} + + {% for node in orientdb_hazelcast_unicast_members %} + {{ node.member }}:{{ node.port | default(orientdb_hazelcast_port_min) }} + {% endfor %} + + {% endif %} + + {% if orientbd_hazelcast_encryption %} + + Blowfish + {{ orientdb_hazelcast_salt }} + {{ orientdb_hazelcast_pwd }} + 19 + + {% endif %} + + + 16 + + diff --git a/templates/orientdb-letsencrypt-acme.sh.j2 b/templates/orientdb-letsencrypt-acme.sh.j2 new file mode 100644 index 0000000..4a954c1 --- /dev/null +++ b/templates/orientdb-letsencrypt-acme.sh.j2 @@ -0,0 +1,42 @@ +#!/bin/bash + +ORIENTDB_ENABLED="{{ orientdb_enabled }}" +RETVAL=0 + +# Add the CA certificate if it's not already present +keytool -list -keystore {{ java_keyring_file }} -storepass {{ java_keyring_pwd }} -noprompt | grep {{ java_keyring_letsencrypt_trusted_ca }} +RETVAL=$? + +if [ $RETVAL -ne 0 ] ; then + keytool -trustcacerts -keystore "{{ java_keyring_file }}" -storepass {{ java_keyring_pwd }} -noprompt -importcert -alias "{{ java_keyring_letsencrypt_trusted_ca }}" -dname "CN={{ ansible_fqdn }}" -file "{{ letsencrypt_acme_certs_dir }}/fullchain" +fi +# Remove the old certificate +keytool -storepass {{ java_keyring_pwd }} -keystore "{{ java_keyring_file }}" -delete -alias "{{ ansible_fqdn }}" + +# Check if the old certificate is still present. If so, we have a problem. Otherwise, import the new one +keytool -list -keystore {{ java_keyring_file }} -storepass {{ java_keyring_pwd }} -noprompt | grep {{ ansible_fqdn }} +RETVAL=$? +if [ $RETVAL -ne 0 ] ; then + openssl pkcs12 -export -in {{ letsencrypt_acme_certs_dir }}/cert -inkey {{ letsencrypt_acme_certs_dir }}/privkey -CAfile {{ letsencrypt_acme_certs_dir }}/fullchain -name "{{ ansible_fqdn }}" -out /var/tmp/{{ ansible_fqdn }}.p12 -password pass:{{ java_keyring_pwd }} + keytool -importkeystore -srcstorepass {{ java_keyring_pwd }} -deststorepass {{ java_keyring_pwd }} -destkeystore {{ java_keyring_file }} -srckeystore /var/tmp/{{ ansible_fqdn }}.p12 -srcstoretype PKCS12 + rm -f /var/tmp/{{ ansible_fqdn }}.p12 +else + logger "orientdb letsencrypt hook: the old certificate is still present inside the keystore, aborting." + exit 1 +fi + +chmod 440 "{{ java_keyring_file }}" +chgrp {{ orientdb_user }} "{{ java_keyring_file }}" + +if [ "$ORIENTDB_ENABLED" == "True" ] ; then + logger "orientdb letsencrypt hook: shut down orientdb." + /etc/init.d/orientdb stop + sleep 30 + /etc/init.d/orientdb start + logger "orientdb letsencrypt hook: start orientdb." +else + logger "orientdb letsencrypt hook: the service is disabled, we do not restart it." +fi +logger "orientdb letsencrypt hook: the keystore has been updated with the renewed certificate." + +exit $RETVAL diff --git a/templates/orientdb-nrpe.cfg.j2 b/templates/orientdb-nrpe.cfg.j2 new file mode 100644 index 0000000..9b5c7e6 --- /dev/null +++ b/templates/orientdb-nrpe.cfg.j2 @@ -0,0 +1,3 @@ + +# Restart orientdb (via handler) +command[global_restart_orientdb]=/usr/bin/sudo /etc/init.d/orientdb start diff --git a/templates/orientdb-server-config.xml.j2 b/templates/orientdb-server-config.xml.j2 new file mode 100644 index 0000000..279ae38 --- /dev/null +++ b/templates/orientdb-server-config.xml.j2 @@ -0,0 +1,118 @@ + + + + {% if orientbd_graph_server_enabled %} + + + + + + + {% endif %} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +{% if orientdb_ssl_client_auth_enabled %} + +{% else %} + +{% endif %} + + + + + + + + +{% if orientdb_ssl_client_auth_enabled %} + +{% else %} + +{% endif %} + + + + + + + + + + + + + +{% if orientdb_ssl_enabled %} + +{% endif %} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {% for class in orientdb_hooks_classes %} + + {% endfor %} + + true + diff --git a/templates/orientdb-server-log.properties.j2 b/templates/orientdb-server-log.properties.j2 new file mode 100644 index 0000000..6539fd0 --- /dev/null +++ b/templates/orientdb-server-log.properties.j2 @@ -0,0 +1,46 @@ +# +# /* +# * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com) +# * +# * 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. +# * +# * For more information: http://www.orientechnologies.com +# */ +# + +# Specify the handlers to create in the root logger +# (all loggers are children of the root logger) +# The following creates two handlers +handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler + +# Set the default logging level for the root logger +.level = {{ orientdb_log_level }} +com.orientechnologies.level = {{ orientdb_log_level }} +com.orientechnologies.orient.server.distributed.level = {{ orientdb_log_level }} + +# Set the default logging level for new ConsoleHandler instances +java.util.logging.ConsoleHandler.level = {{ orientdb_log_level }} +# Set the default formatter for new ConsoleHandler instances +java.util.logging.ConsoleHandler.formatter = com.orientechnologies.common.log.OAnsiLogFormatter + +# Set the default logging level for new FileHandler instances +java.util.logging.FileHandler.level = {{ orientdb_log_level }} +# Naming style for the output file +java.util.logging.FileHandler.pattern={{ orientdb_log_dir }}/orient-server.log +# Set the default formatter for new FileHandler instances +java.util.logging.FileHandler.formatter = com.orientechnologies.common.log.OLogFormatter +# Limiting size of output file in bytes: +java.util.logging.FileHandler.limit=10000000 +# Number of output files to cycle through, by appending an +# integer to the base file name: +java.util.logging.FileHandler.count=10 diff --git a/templates/orientdb.default.j2 b/templates/orientdb.default.j2 new file mode 100644 index 0000000..f77cbc6 --- /dev/null +++ b/templates/orientdb.default.j2 @@ -0,0 +1,8 @@ +export ORIENTDB_DIR="{{ orientdb_home_prefix }}/{{ orientdb_user }}/{{ orientdb_dir }}" +export ORIENTDB_USER="{{ orientdb_user }}" +export ORIENTDB_OPTS_MEMORY="{{ orientdb_java_heap }}" +export ORIENTDB_SETTINGS="{{ orientdb_default_settings }}" +ORIENTDB_SERVER_OPTS= +{% if orientdb_distributed %} +ORIENTDB_SERVER_OPTS="-Ddistributed=true" +{% endif %} \ No newline at end of file diff --git a/templates/orientdb.init.j2 b/templates/orientdb.init.j2 new file mode 100755 index 0000000..d5839bd --- /dev/null +++ b/templates/orientdb.init.j2 @@ -0,0 +1,83 @@ +#!/bin/bash +# OrientDB service script +# +# Copyright (c) Orient Technologies LTD (http://www.orientechnologies.com) + +# chkconfig: 2345 20 80 +# description: OrientDb init script +# processname: orientdb.sh + +# You have to SET the OrientDB installation directory here +if [ -f /etc/default/orientdb ] ; then + . /etc/default/orientdb +else + ORIENTDB_DIR="{{ orientdb_home_prefix }}/{{ orientdb_user }}/{{ orientdb_dir }}" + ORIENTDB_USER="{{ orientdb_user }}" +fi + +usage() { + echo "Usage: `basename $0`: " + exit 1 +} + +start() { + status + if [ $PID -gt 0 ] + then + echo "OrientDB server daemon was already started. PID: $PID" + return $PID + fi + echo "Starting OrientDB server daemon..." + cd "$ORIENTDB_DIR/bin" + su $ORIENTDB_USER -c "cd \"$ORIENTDB_DIR/bin\"; /usr/bin/nohup ./server.sh $ORIENTDB_SERVER_OPTS >> {{ orientdb_log_dir }}/orientdb.log 2>&1 &" +} + +stop() { + status + if [ $PID -eq 0 ] + then + echo "OrientDB server daemon is already not running" + return 0 + fi + echo "Stopping OrientDB server daemon..." + cd "$ORIENTDB_DIR/bin" + su $ORIENTDB_USER -c "cd \"$ORIENTDB_DIR/bin\"; /usr/bin/nohup ./shutdown.sh >> {{ orientdb_log_dir }}/orientdb.log 2>&1" +} + +status() { + PID=` ps auxw | grep 'orientdb.www.path' | grep java | grep -v grep | awk '{print $2}'` + if [ "x$PID" = "x" ] + then + PID=0 + fi + + # if PID is greater than 0 then OrientDB is running, else it is not + return $PID +} + +if [ "x$1" = "xstart" ] +then + start + exit 0 +fi + +if [ "x$1" = "xstop" ] +then + stop + exit 0 +fi + +if [ "x$1" = "xstatus" ] +then + status + if [ $PID -gt 0 ] + then + echo "OrientDB server daemon is running with PID: $PID" + exit 0 + else + echo "OrientDB server daemon is NOT running" + exit 3 + fi +fi + +usage diff --git a/templates/orientdb.service.j2 b/templates/orientdb.service.j2 new file mode 100644 index 0000000..1626581 --- /dev/null +++ b/templates/orientdb.service.j2 @@ -0,0 +1,21 @@ +[Unit] +Description=OrientDB Server +After=network.target +After=syslog.target + +[Install] +WantedBy=multi-user.target + +[Service] +Type=simple +User={{ orientdb_user }} +Group={{ orientdb_user }} +Restart=always +RestartSec=10 +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=orientdb +ExecStart={{ orientdb_home_prefix }}/{{ orientdb_user }}/{{ orientdb_dir }}/bin/server.sh +ExecStop={{ orientdb_home_prefix }}/{{ orientdb_user }}/{{ orientdb_dir }}/bin/shutdown.sh +ExecStatus={{ orientdb_home_prefix }}/{{ orientdb_user }}/{{ orientdb_dir }}/bin/orientdb.sh status +ExecReload=/bin/kill -HUP $MAINPID