summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2018-05-14 23:11:50 +0200
committerLinus Färnstrand <linus@mullvad.net>2018-05-14 23:11:50 +0200
commit1f3061fc0efdd9f137aac44a732920f2e08216f5 (patch)
treed1db98dbf1ccc4ba907d1bcc87faba72f18cd665
parentfca08e280d9c636c7444e413bd8911336a390044 (diff)
parente7221ad616a02f86a24687249aa405e40de469a5 (diff)
downloadmullvadvpn-1f3061fc0efdd9f137aac44a732920f2e08216f5.tar.xz
mullvadvpn-1f3061fc0efdd9f137aac44a732920f2e08216f5.zip
Merge branch 'macos-system-service'
-rw-r--r--CHANGELOG.md2
-rw-r--r--app/main.js59
-rwxr-xr-xdist-assets/pkg-scripts/postinstall49
-rw-r--r--electron-builder.yml17
-rw-r--r--package.json2
-rw-r--r--yarn.lock13
6 files changed, 57 insertions, 85 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9f7e5435be..bcf9c1425e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -45,6 +45,8 @@ Line wrap the file at 100 chars. Th
resolution of the Mullvad API server hostname fails.
- Manage firewall rules on Windows depending on connection state.
- Improve account token hint to be the same length as an expected token.
+- The macOS installer is changed from dmg to pkg format.
+- The backend daemon is installed as a launchd daemon and started on macOS on install.
### Fixed
- Fix a bug in account input field that advanced the cursor to the end regardless its prior
diff --git a/app/main.js b/app/main.js
index ea85de8b36..863d8a6f67 100644
--- a/app/main.js
+++ b/app/main.js
@@ -5,8 +5,6 @@ import mkdirp from 'mkdirp';
import { log } from './lib/platform';
import electron, { app, BrowserWindow, ipcMain, Tray, Menu, nativeImage } from 'electron';
import TrayIconManager from './lib/tray-icon-manager';
-import ElectronSudo from 'electron-sudo';
-import shellescape from 'shell-escape';
import { version } from '../package.json';
import { parseIpcCredentials } from './lib/backend';
import { resolveBin } from './lib/proc';
@@ -41,12 +39,6 @@ const appDelegate = {
log.info('Running version', version);
- // Only macOS builds still launch the daemon manually.
- // On other platforms mullvad-daemon already runs as a system service.
- if (process.platform === 'darwin') {
- appDelegate._startBackend();
- }
-
app.on('window-all-closed', () => appDelegate.onAllWindowsClosed());
app.on('ready', () => appDelegate.onReady());
},
@@ -188,33 +180,6 @@ const appDelegate = {
onAllWindowsClosed: () => {
app.quit();
},
-
- _startBackend: () => {
- const rpcAddressFile = appDelegate._getRpcAddressFilePath();
- const backendIsRunning = fs.existsSync(rpcAddressFile);
- if (backendIsRunning) {
- log.info('Not starting the backend as it appears to already be running');
- return;
- }
-
- const pathToBackend = resolveBin('mullvad-daemon');
- log.info('Starting the mullvad backend at', pathToBackend);
-
- const options = {
- name: 'Mullvad',
- };
- const sudo = new ElectronSudo(options);
- const backendCommand = shellescape([
- pathToBackend, '-v',
- '--log', path.join(appDelegate._logFileLocation, 'backend.log'),
- '--tunnel-log', path.join(appDelegate._logFileLocation, 'openvpn.log')
- ]);
- sudo.spawn(backendCommand, [])
- .then( p => {
- appDelegate._setupBackendProcessListeners(p);
- return p;
- });
- },
_getRpcAddressFilePath: () => {
const rpcAddressFileName = '.mullvad_rpc_address';
@@ -225,30 +190,6 @@ const appDelegate = {
return path.join(getSystemTemporaryDirectory(), rpcAddressFileName);
}
},
- _setupBackendProcessListeners: (p) => {
- // electron-sudo writes all output to some buffers in memory.
- // For long-running processes such as this one that would
- // cause a memory leak.
- p.stdout.removeAllListeners('data');
- p.stderr.removeAllListeners('data');
-
- p.stdout.on('data', (data) => {
- console.log('BACKEND stdout:', data.toString());
- });
- p.stderr.on('data', (data) => {
- console.warn('BACKEND stderr:', data.toString());
- });
-
- p.on('error', (err) => {
- log.error('Failed to start or kill the backend', err);
- });
-
- p.on('exit', (code) => {
- const timeoutMs = 500;
- log.info('The backend exited with code', code + '. Attempting to restart it in', timeoutMs, 'milliseconds...');
- setTimeout( () => appDelegate._startBackend(), timeoutMs);
- });
- },
_pollForConnectionInfoFile: () => {
if (appDelegate.connectionFilePollInterval) {
diff --git a/dist-assets/pkg-scripts/postinstall b/dist-assets/pkg-scripts/postinstall
new file mode 100755
index 0000000000..2180d91ee4
--- /dev/null
+++ b/dist-assets/pkg-scripts/postinstall
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+set -eu
+
+LOG_DIR=/var/log/mullvad-daemon
+
+mkdir -p $LOG_DIR
+exec 2>&1 > $LOG_DIR/install.log
+
+INSTALL_DIR=$2
+DAEMON_PLIST_PATH="/Library/LaunchDaemons/net.mullvad.daemon.plist"
+
+DAEMON_PLIST=$(cat <<-EOM
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+ <dict>
+ <key>Label</key>
+ <string>net.mullvad.daemon</string>
+
+ <key>ProgramArguments</key>
+ <array>
+ <string>$INSTALL_DIR/Mullvad VPN.app/Contents/Resources/mullvad-daemon</string>
+ <string>-v</string>
+ <string>--log</string>
+ <string>$LOG_DIR/daemon.log</string>
+ <string>--tunnel-log</string>
+ <string>$LOG_DIR/openvpn.log</string>
+ </array>
+
+ <key>UserName</key>
+ <string>root</string>
+
+ <key>RunAtLoad</key>
+ <true/>
+
+ <key>KeepAlive</key>
+ <true/>
+
+ <key>StandardErrorPath</key>
+ <string>$LOG_DIR/stderr.log</string>
+ </dict>
+</plist>
+EOM
+)
+
+launchctl unload -w $DAEMON_PLIST_PATH
+echo "$DAEMON_PLIST" > $DAEMON_PLIST_PATH
+launchctl load -w $DAEMON_PLIST_PATH
diff --git a/electron-builder.yml b/electron-builder.yml
index 7b1cd6ef7e..e16375dd3a 100644
--- a/electron-builder.yml
+++ b/electron-builder.yml
@@ -27,19 +27,8 @@ files:
- build/
- node_modules/
-dmg:
- contents:
- - type: link
- path: /Applications
- x: 410
- y: 150
- - type: file
- x: 130
- y: 150
-
mac:
- target:
- - dmg
+ target: pkg
artifactName: MullvadVPN-${version}.${ext}
category: public.app-category.tools
extendInfo:
@@ -56,6 +45,10 @@ mac:
- from: ./client-binaries/mac/include/openvpn
to: ./openvpn-binaries/openvpn
+pkg:
+ allowAnywhere: false
+ allowCurrentUserHome: false
+
win:
target:
- nsis
diff --git a/package.json b/package.json
index b7d77d582b..bb794f5fe9 100644
--- a/package.json
+++ b/package.json
@@ -14,7 +14,6 @@
"babel-runtime": "^6.22.0",
"d3-geo-projection": "^2.3.2",
"electron-log": "^2.2.8",
- "electron-sudo": "https://github.com/mullvad/electron-sudo.git",
"history": "^4.6.1",
"jsonrpc-lite": "^1.2.3",
"mkdirp": "^0.5.1",
@@ -31,7 +30,6 @@
"reactxp": "^1.1.0-rc.2",
"redux": "^3.0.0",
"redux-thunk": "^2.2.0",
- "shell-escape": "^0.2.0",
"uuid": "^3.0.1",
"validated": "^1.1.0"
},
diff --git a/yarn.lock b/yarn.lock
index 223260621a..f107aa71d5 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1396,7 +1396,7 @@ bluebird-lst@^1.0.5:
dependencies:
bluebird "^3.5.1"
-bluebird@^3.4.6, bluebird@^3.5.0, bluebird@^3.5.1:
+bluebird@^3.5.0, bluebird@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9"
@@ -2786,13 +2786,6 @@ electron-publish@19.55.2:
fs-extra-p "^4.5.0"
mime "^2.2.0"
-"electron-sudo@https://github.com/mullvad/electron-sudo.git":
- version "4.0.12"
- resolved "https://github.com/mullvad/electron-sudo.git#f71134f86541b15359f4813715d721818fb2b1f4"
- dependencies:
- babel-runtime "^6.18.0"
- bluebird "^3.4.6"
-
electron-window@^0.8.0:
version "0.8.1"
resolved "https://registry.yarnpkg.com/electron-window/-/electron-window-0.8.1.tgz#16ca187eb4870b0679274fc8299c5960e6ab2c5e"
@@ -7000,10 +6993,6 @@ shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
-shell-escape@^0.2.0:
- version "0.2.0"
- resolved "https://registry.yarnpkg.com/shell-escape/-/shell-escape-0.2.0.tgz#68fd025eb0490b4f567a027f0bf22480b5f84133"
-
shell-quote@1.6.1, shell-quote@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.6.1.tgz#f4781949cce402697127430ea3b3c5476f481767"