From 182c50ccbf5e835a4985dfeea7c4aa7a6a69ac0c Mon Sep 17 00:00:00 2001 From: bnewbold Date: Wed, 4 May 2016 16:23:54 -0400 Subject: mediagoblin: fixes, systemd scripts --- roles/mediagoblin/tasks/mediagoblin.yml | 27 ++++++++++++++++++- .../etc_nginx_sites-available_mediagoblin.j2 | 13 +++++---- ...c_systemd_system_mediagoblin-celeryd.service.j2 | 26 ++++++++++++++++++ ...tc_systemd_system_mediagoblin-paster.service.j2 | 31 ++++++++++++++++++++++ 4 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 roles/mediagoblin/templates/etc_systemd_system_mediagoblin-celeryd.service.j2 create mode 100644 roles/mediagoblin/templates/etc_systemd_system_mediagoblin-paster.service.j2 (limited to 'roles') diff --git a/roles/mediagoblin/tasks/mediagoblin.yml b/roles/mediagoblin/tasks/mediagoblin.yml index 29929c3..c99b65c 100644 --- a/roles/mediagoblin/tasks/mediagoblin.yml +++ b/roles/mediagoblin/tasks/mediagoblin.yml @@ -33,6 +33,16 @@ mode=0750 owner={{ mediagoblin_user }} +- name: Create mediagoblin PID directory + file: name=/run/mediagoblin + state=directory + owner={{ mediagoblin_user }} + +- name: Create mediagoblin logs directory + file: name=/var/log/mediagoblin + state=directory + owner={{ mediagoblin_user }} + - name: Checkout git git: repo={{ mediagoblin_git_uri }} dest={{ mediagoblin_basedir }}/src @@ -81,7 +91,22 @@ template: src=etc_nginx_sites-available_mediagoblin.j2 dest=/etc/nginx/sites-available/mediagoblin -# XXX: TODO: how to create a systemd unit? +- name: Copy generic mediagoblin celeryd systemd file + template: src=etc_systemd_system_mediagoblin-celeryd.service.j2 + dest=/etc/systemd/system/mediagoblin-celeryd.service + +- name: Copy generic mediagoblin paster systemd file + template: src=etc_systemd_system_mediagoblin-paster.service.j2 + dest=/etc/systemd/system/mediagoblin-paster.service + +- name: Have systemd detect new files + shell: systemctl daemon-reload + +- name: Start systemd paster service + shell: systemctl start mediagoblin-celeryd.service && systemctl start mediagoblin-paster.service + +- name: Enable systemd services + shell: systemctl enable mediagoblin-celeryd.service && systemctl enable mediagoblin-paster.service - name: Create nginx symlink for default file: state=link diff --git a/roles/mediagoblin/templates/etc_nginx_sites-available_mediagoblin.j2 b/roles/mediagoblin/templates/etc_nginx_sites-available_mediagoblin.j2 index 8705d0f..855c580 100644 --- a/roles/mediagoblin/templates/etc_nginx_sites-available_mediagoblin.j2 +++ b/roles/mediagoblin/templates/etc_nginx_sites-available_mediagoblin.j2 @@ -13,28 +13,27 @@ server { # interprets as an HTML file, etc.) add_header X-Content-Type-Options nosniff; - server_name mediagoblin.example.org www.mediagoblin.example.org; - access_log /var/log/nginx/mediagoblin.example.access.log; - error_log /var/log/nginx/mediagoblin.example.error.log; + access_log /var/log/nginx/mediagoblin.access.log; + error_log /var/log/nginx/mediagoblin.error.log; # MediaGoblin's stock static files: CSS, JS, etc. location /mgoblin_static/ { - alias /srv/mediagoblin.example.org/mediagoblin/mediagoblin/static/; + alias {{ mediagoblin_basedir }}/src/mediagoblin/static/; } # Instance specific media: location /mgoblin_media/ { - alias /srv/mediagoblin.example.org/mediagoblin/user_dev/media/public/; + alias {{ mediagoblin_basedir }}/src/user_dev/media/public/; } # Theme static files (usually symlinked in) location /theme_static/ { - alias /srv/mediagoblin.example.org/mediagoblin/user_dev/theme_static/; + alias {{ mediagoblin_basedir }}/src/user_dev/theme_static/; } # Plugin static files (usually symlinked in) location /plugin_static/ { - alias /srv/mediagoblin.example.org/mediagoblin/user_dev/plugin_static/; + alias {{ mediagoblin_basedir }}/src/user_dev/plugin_static/; } # # Mounting MediaGoblin itself via FastCGI. diff --git a/roles/mediagoblin/templates/etc_systemd_system_mediagoblin-celeryd.service.j2 b/roles/mediagoblin/templates/etc_systemd_system_mediagoblin-celeryd.service.j2 new file mode 100644 index 0000000..f44a012 --- /dev/null +++ b/roles/mediagoblin/templates/etc_systemd_system_mediagoblin-celeryd.service.j2 @@ -0,0 +1,26 @@ +# {{ ansible_managed }} +# Set the WorkingDirectory, Environment and ExecStart values to match your environment. +# If using Debian/*buntu, mkdir and chown are located in /bin/mkdir and /bin/chown, respectively. +# If using Fedora/CentOS/Red Hat, mkdir and chown are located in /usr/bin/mkdir and /usr/bin/chown, respectively. + +[Unit] +Description=Mediagoblin Celeryd + +[Service] +User=mediagoblin +Group=mediagoblin +Type=simple +WorkingDirectory={{ mediagoblin_basedir }}/src +# Create directory for PID (if needed) and set ownership +ExecStartPre=/bin/mkdir -p /run/mediagoblin +ExecStartPre=/bin/chown -hR mediagoblin:mediagoblin /run/mediagoblin +# Celery process will run as the `mediagoblin` user after start. +Environment=MEDIAGOBLIN_CONFIG={{ mediagoblin_basedir }}/src/mediagoblin_local.ini \ + CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery +ExecStart={{ mediagoblin_basedir }}/src/bin/celery worker \ + --logfile=/var/log/mediagoblin/celery.log \ + --loglevel=INFO +PIDFile=/run/mediagoblin/mediagoblin-celeryd.pid + +[Install] +WantedBy=multi-user.target diff --git a/roles/mediagoblin/templates/etc_systemd_system_mediagoblin-paster.service.j2 b/roles/mediagoblin/templates/etc_systemd_system_mediagoblin-paster.service.j2 new file mode 100644 index 0000000..63a589d --- /dev/null +++ b/roles/mediagoblin/templates/etc_systemd_system_mediagoblin-paster.service.j2 @@ -0,0 +1,31 @@ +# Set the WorkingDirectory, Environment and ExecStart values to match your environment. +# If using Debian/*buntu, mkdir and chown are located in /bin/mkdir and /bin/chown, respectively. +# If using Fedora/CentOS/Red Hat, mkdir and chown are located in /usr/bin/mkdir and /usr/bin/chown, respectively. +[Unit] +Description=Mediagoblin + +[Service] +Type=forking +User=mediagoblin +Group=mediagoblin +Environment=CELERY_ALWAYS_EAGER=false +WorkingDirectory={{ mediagoblin_basedir }}/src +# Start mg-paster process as root, then switch to mediagoblin user/group +PermissionsStartOnly=true +ExecStartPre=-/bin/mkdir -p /run/mediagoblin +ExecStartPre=/bin/chown -hR mediagoblin:mediagoblin /run/mediagoblin + +ExecStart={{ mediagoblin_basedir }}/src/bin/paster serve \ + {{ mediagoblin_basedir }}/src/paste_local.ini \ + --pid-file=/var/run/mediagoblin/mediagoblin.pid \ + --log-file=/var/log/mediagoblin/mediagoblin.log \ + --daemon \ + --server-name=http http_host=127.0.0.1 http_port=26543 + #--server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543 +ExecStop={{ mediagoblin_basedir }}/src/bin/paster serve \ + --pid-file=/var/run/mediagoblin/mediagoblin.pid \ + {{ mediagoblin_basedir }}/src/paste_local.ini stop +PIDFile=/var/run/mediagoblin/mediagoblin.pid + +[Install] +WantedBy=multi-user.target -- cgit v1.2.3