For myapp, create a service file myapp.service at /etc/systemd/system:
[Unit]
Description=Myapp
After=network.target
[Service]
WorkingDirectory=/home/pwong/myapp
ExecStart=/usr/local/bin/meteor --production
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=Myapp
User=pwong
Group=pwong
Environment=NODE_ENV=production
Environment=PWD=/home/pwong/myapp
Environment=PORT=3000
Environment=HTTP_FORWARDED_COUNT=1
Environment=ROOT_URL=http://myapp.com
Environment=MONGO_URL=mongodb://user:pwd@mongodb0,mongodb1,mongodb2:27017/myapp?replcaSet=rs0
Environment=MONGO_OPLOG_URL=mongodb://user:pwd@mongodb0,mongodb1,mongodb2:27017/local?replcaSet=rs0&authSource=admin
[Install]
WantedBy=multi-user.target
-----------------------------------------------------------------
Note:
1. The above configuration is used for replcation set rs0 and remote mongodb server
2. Without the Install section, the service won't startup during the boot time. This section force the system to create a symbolic link for startup.
3. The local database won't accept user creation, so the user is created at admin. Therefore authSource has to be defined in this case.
Perform the following to enable the service and check the status of the service:
$ sudo systemctl daemon-reload
$ sudo systemctl enable myapp
$ sudo systemctl start myapp
$ sudo systemctl status myapp