diff --git a/install.sh b/install.sh index 0c82766..b5abddb 100755 --- a/install.sh +++ b/install.sh @@ -1,19 +1,39 @@ #!/bin/sh +systemd=$(pidof systemd) + +if [ -z "$systemd" ]; then + echo "Systemd not detected" + echo "Assuming upstart" + startCmd="start paperplane" + stopCmd="stop paperplane" +else + echo "Systemd detected" + startCmd="systemctl start PaperPlane" + stopCmd="systemctl stop PaperPlane" +fi + if [ -d "/var/local/paperplane" ]; then echo "Updating existing install" - stop paperplane + eval "$stopCmd" cp -R . /var/local/paperplane chown -R paperplane:paperplane /var/local/paperplane - start paperplane + eval "$startCmd" fi if [ ! -d "/var/local/paperplane" ]; then # Add user adduser --system --group --gecos 'User for PaperPlane webapp' --disabled-password --home /home/paperplane paperplane - # Copy upstart config - cp upstart.conf /etc/init/paperplane.conf + if [ -z "$systemd" ]; then + # Copy upstart config + cp upstart.conf /etc/init/paperplane.conf + else + # Copy systemd config + cp systemd.service /usr/lib/systemd/system/PaperPlane.service + # Enable systemd service + systemctl enable PaperPlane + fi # Copy application folder and create log file cp -R . /var/local/paperplane @@ -24,5 +44,5 @@ if [ ! -d "/var/local/paperplane" ]; then cd /var/local/paperplane; npm link chown -R paperplane:paperplane /var/local/paperplane - start paperplane + eval "$startCmd" fi diff --git a/systemd.service b/systemd.service new file mode 100644 index 0000000..65838b2 --- /dev/null +++ b/systemd.service @@ -0,0 +1,14 @@ +[Unit] +Description=PaperPlane Link Sharing Server +After=network.target local-fs.target nss-lookup.target + +[Service] +Type=simple +ExecStart=/usr/bin/node /var/local/paperplane/server.js +#StandardOutput=/var/log/paperplane.log +#Not needed as systemd has it's own logging service +#To view logs use 'systemd status PaperPlane' +#To enable that log file, uncomment the line + +[Install] +WantedBy=multi-user.target