From f1b47589e6e73be7f8287c71d46d246e48dda2e2 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Thu, 2 Jun 2016 12:52:14 +0300 Subject: [PATCH] updated init script --- setup/install.sh | 12 +++++++++--- setup/mailtrain.service | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 setup/mailtrain.service diff --git a/setup/install.sh b/setup/install.sh index b40b98cb..6635bebb 100755 --- a/setup/install.sh +++ b/setup/install.sh @@ -31,9 +31,6 @@ mkdir -p /opt/mailtrain cd /opt/mailtrain git clone git://github.com/andris9/mailtrain.git . -# Set up upstart service script -cp setup/mailtrain.conf /etc/init - # Add new user for the daemon to run as useradd mailtrain || true @@ -71,6 +68,15 @@ cat < /etc/logrotate.d/mailtrain } EOM +if [ -d "/usr/lib/systemd" ]; then + # Set up systemd service script + cp setup/mailtrain.service /etc/systemd/system/ + systemctl enable mailtrain.service +else + # Set up upstart service script + cp setup/mailtrain.conf /etc/init/ +fi + # Start the service service mailtrain start diff --git a/setup/mailtrain.service b/setup/mailtrain.service new file mode 100644 index 00000000..d233e74c --- /dev/null +++ b/setup/mailtrain.service @@ -0,0 +1,13 @@ +Description=Mailtrain server +Requires=After=mysql.service + +[Service] +Environment="NODE_ENV=production" +WorkingDirectory=/opt/mailtrain +ExecStart=/usr/bin/node index.js >> /var/log/mailtrain.log 2>&1 +Type=simple +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target