- Write a simple shell, like:
1 |
|
Save it as a .sh
file, like /Users/bejond/startmongodb.sh
. Then make the shell runnable.
sudo chmod a+x /Users/bejond/startmongodb.sh
- Create a
.plisth
file in/Library/LaunchAgents/
, likecom.startup.mongodb.plist
, in order to run the script or command.
Edit the file, like:
1 |
|
Seeing ProgramArguments
, this means we can pass a command and arguments. You can also change ProgramArguments
to Program
, but without <array>
element.
-
Add the
com.startup.mongodb.plist
tolaunchd
:
$ sudo launchctl load /Library/LaunchAgents/com.startup.mongodb.plist
-
Remove the
com.startup.mongodb.plist
fromlaunchd
:
$ sudo launchctl unload /Library/LaunchAgents/com.startup.mongdb.plist
-
Then
/Users/bejond/startmongodb.sh
would be executed just now. And it would also run on next startup.
[1] Running script upon login mac - answered by trisweb
[2] Adding Startup Scripts to Launch Daemon on Mac OS X Sierra 10.12.6, by seeing the .plist file
[3] Run command on startup / login (Mac OS X) - answered by Scott