Cocoa Launch agent registering itself after installation - cocoa

I have created Cocoa app which is type of launch agent. To distribute this I have created package as well which installs the app and copies the launchagnet plist file in /Libraries/LaunchAgents.
Now the problem is after installation i want this app to be running in user context immediately without logoff/restart. If I register this with "launchctl" from installer, using post install script, it run in root context, as installer is running in root context.
Any suggestion how the agent registers itself to launchctl and runs in user context.

Try this in the postinstall script:
/usr/bin/sudo -u $USER /bin/launchctl load -S Aqua /Library/LaunchAgents/com.yourcompany.launchagent.plist
Note that if multiple users are logged in via Fast User Switching, this will only activate your launch agent for the user who installed it.
There is an unsupported way to make this work with multiple users logged in on Mac OS X 10.5/10.6, using launchctl bsexec; see this mailing list post for more information.

Related

How do i get rid of the sudo requirement?

I am using MacOS Catelina and i often have to run my terminal stuff with sudo otherwise they fail. like when i use Visual Studio and IONIC to add stuff to global or when it tries to create dir etc.
Is there a way to change the logged in user to run elevated commands in terminal without sudo ?
You either continue using sudo or switch current user to root (it's not a recommended way)
The user account named ”root” is a superuser with read and write
privileges to more areas of the system, including files in other macOS
user accounts. The root user is disabled by default. If you can log in
to your Mac with an administrator account, you can enable the root
user, then log in as the root user to complete your task.
The root user account is not intended for routine use. Its privileges
allow changes to files that are required by your Mac. To undo such
changes, you might need to reinstall your system software. You should
disable the root user after completing your task.
It's safer to use the sudo command in Terminal instead of enabling the
root user. To learn about sudo, open the Terminal app and enter man
sudo.
Taken from https://support.apple.com/en-us/HT204012

'Jenkins' user is not created on OS X install

When reading about Jenkins installation, many guides talk about that the installer created a user called 'Jenkins' on OS X. This user seems to be important for certain tasks.
However, installing Jenkins 2.32 using homebrew does not install this user here. Why is that - am I missing something?
Background: I want to run CI for iOS together with a Gitlab server.
Jenkins installed via Homebrew is kind of a mess - and I say this because it isn't terribly obvious in the log output where/who gets permissions.
Jenkins DOES NOT create a jenkins user on Mac OS (nor should it ever, imo).
By default, the user that was actively using brew install jenkins is the one who will get the default permissions. There should be a /.jenkins folder within that users home folder (ex: /Users/<your_user>/.jenkins)
The problem is that when brew finishes running, some files that should get symlinked to the active user don't - so you might create a job using rvm/ruby for example, and get errors that bundler can't write to the system ruby.
Try this in terminal/iTerm:
sudo chown whoami /Library/LaunchDaemons/homebrew.mxcl.jenkins.plist
also whoami should be surrounded by ticks `
I tend to just do these commands after a brew install jenkins
ln -sfv /usr/local/opt/jenkins/*.plist ~/Library/LaunchAgents
Symlink the Jenkins plist files to /Library/LaunchAgents
sudo cp -fv /usr/local/opt/jenkins/*.plist /Library/LaunchDaemons
Copy plist files to /Library/LaunchDaemons
sudo chownwhoami/Library/LaunchDaemons/homebrew.mxcl.jenkins.plist
Give sudo ownership of the plist file listed to the user outright
This part isn't necessary...
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist
Here's something to refer to:
http://flummox-engineering.blogspot.com/2016/01/installing-jenkins-os-x-homebrew.html

OS X 10.11 EL Capitan: Start launch agent for all logged in users from daemom

I am having with one daemon(A) which downloads one .pkg for daemon(B) from server and installs it also place daemon(B) in /Library/MyFolder/. it also place two global launch agent in same directory and corresponding plists in /Library/LaunchAgents. Application bundle of daemon(B) contains one wrapper app say launcher which loads launch agents for all logged in users and I am using below scripts to open launcher app on 10.10
for num in `ps ax | grep MacOS/loginwindow| cut -c 1-5`;
do
if [ $num -ne 1 ]
then
sudo launchctl bsexec $num /Library/MyFolder/daemon(b).app/Contents/MacOS/Launcher
fi
done.
Above script work fine on 10.10 but not working on 10.11 EL Capitan. Is it because of the rootless feature of 10.11 because if I disable rootless same scripts works fine. Also If i install .pkg for daemon(B) manually that tim also it work fine. Related question here
Try to search for '/usr/sbin/pboard' instead of 'MacOS/loginwindow'. Apple denied access to loginwindow process.
EDIT: This is no longer working. See comments for details.

Meteor requires sudo to run

Previously I was able to start Meteor 0.6.6.3 by simply running mrt.
Recently, Meteor 0.7.0.1 wont run properly unless I run it as root with sudo mrt. Environmental variables like MONGO_URL requires root to set it.
Any ideas what happened? I'm using Mountain Lion on Mac OSX.
You might have run it with sudo once before. When you run it with sudo just once and a file is written the files become root files root user file so it needs more permissions to run and wont run
ordinarily.
You might have run sudo mrt once it must have updated files for a package but they're now owned by root instead of your normal user.
I'm sure theres a terminal command to get it back but using Disk Utility and running 'Repair Disk Permissions' can also fix it (i think).

Installing a daemon for Mac OS X

I created a daemon for running into Mac OS X platform. I made an installer using PackageMaker and the Daemon is installed without problems. It seems that after the installation has finished, I need to reboot the system in order to have the daemon running. I am wondering if I can load and start the Daemon without forcing the reboot?... I have some ideas about it but not sure if is the right way, for example:
Using a shell script that invoke the command: $sudo launchctl load /Library/LaunchDaemons/myService.plist
Using ServiceManagement.framework to manage privilege escalation on the application that will be using the Daemon while is running so the App can if necessary install and load de service. I have to say that the work of the service is required only when a Cocoa App is active.
If any better idea please let me know it people. :D
You should add the daemon load command in the postinstall script of your package (Your Option 1). Anyway, the daemons do have launch-on-demand options so your daemon will only be loaded only if your app requests to load it.

Resources