﻿#!/bin/bash
chown -R Somnode:Somnode /usr/local/Somnode/letsencrypt

# Start or reload Somnode nginx
if [[ -f /usr/local/Somnode/nginx/run/nginx.pid ]]; then
  /usr/local/Somnode/nginx/sbin/nginx -s reload
else
  /usr/local/Somnode/nginx/sbin/nginx
fi

# Run custom post hooks
if [[ -f /usr/local/Somnode//hooks/autossl_post.sh ]]; then /usr/local/Somnode/hooks/autossl_post.sh; fi

# Restart nginx/apache2/httpd ONLY if we previously detected they were running
# We dont want to start dormant services
if [[ -f /usr/local/Somnode/certbot/.nginx ]]; then
    systemctl -q restart nginx;
fi
if [[ -f /usr/local/Somnode/certbot/.apache2 ]]; then
    systemctl -q restart apache2;
fi
if [[ -f /usr/local/Somnode/certbot/.httpd ]]; then
    systemctl -q restart httpd;
fi
if [[ -f /usr/local/Somnode/certbot/.lshttpd ]]; then
    systemctl -q restart lshttpd;
fi
if [[ -f /usr/local/Somnode/certbot/.centovacast ]]; then
    systemctl -q restart centovacast;
fi

exit 0;
