I have a python script which I'd like to run every time my machine boots. It requires sudo however. What's a simple solution to make my python script with sudo on startup?
For non-privileged startup scripts simply add your single line command to /etc/rc.local for commands that require sudo add it to /etc/rc.common.
You can use launchd.
launchd -- System wide and per-user daemon/agent manager
Add your property list file to the /Library/LaunchDaemons directory.
Have a look at Technical Note TN2083 Daemons and Agents
Related
I'm trying to create a script to start different things. Whenever I add the below to the script and run it, I get a message: "mongod: unrecognized service". I can use it in the terminal, but not through the script.
sudo service mongod start
I got it to start just using sudo service mongod start. The .sh file was created in Windows. Once I deleted it and created a .sh file in Linux, it ran.
Try
sudo service mongodb start
mongod/mongodb depends on Linux version
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
I'm trying to run a program written in C++ by using CLion v1.2 as super user. Anyone here knows how to run it as superuser? I'm using CMake.
I solved this by remote debugging on local machine. I run gdbserver with root privileges and connected to it from CLion.
To start gdbserver sudo gdbserver :port myapp, configure remote GDB debug with port
This was already implemented on CLion, starting 2020.3:
https://www.jetbrains.com/help/clion/debug-as-root.html
If you are asking to run the debugger as sudo/administrator, I had the same issue. On Linux you can open CLion as sudo and gdb will not have root permission issues running an executable:
sudo ./clion.sh
I would guess that you could right click in Windows and "Run as administrator" to get the same result.
There is a feature request into JetBrains to run the debugger as root that could use more up voting.
A workaround is:
From https://www.jetbrains.com/help/clion/attaching-to-local-process.html#prereq-ubuntu
If you are using CLion on Ubuntu (or probably, on some other Linux distribution), upon the first attempt to attach to the local process you can get the ptrace: Operation not permitted. error message. To disable it and enable attach to the local process feature, do the following:
To disable this restriction temporarily, enter the command:
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
To disable this restriction permanently, open the file /etc/sysctl.d/10-ptrace.conf for editing and change the line kernel.yama.ptrace_scope = 1 to kernel.yama.ptrace_scope = 0. To apply the changes, enter:
sudo service procps restart or restart your system, at your choice.
You can create a bash script to help you. For example, run.sh:
#!/usr/bin/env bash
echo $LOGIN_PASSWD | sudo -S yourExecutable --with=some-arguments
Don't forget to chmod a+x run.sh, and export the password of current account as an environment variable in Run/Debug Configurations.
BACKGROUND:
I have an application that is freshly deployed every day -- a VM is created, and then root for that system creates a "systemuser", which then installs the application.
It's running:
CentOS 6
RVM
Ruby 1.8.7 on Rails
passenger
The way it's set up, I have to have Ruby on Rails install itself, and install passenger. To this end the user running the service has sudo powers, but the intention is to only allow the commands needed during installation. For security and maintainability reasons we cannot put the sudo password in the script.
my /etc/sudoers includes:
systemuser ALL = NOPASSWD: /usr/bin/env, /bin/bash, /usr/local/rvm/rubies/ruby-1.8.7-p358/bin/gem, /bin/cp, /bin/ln, /bin/mv, /bin/rm, /etc/init.d/httpd *
THE PROBLEM:
Until recently a variant of this worked great. However recently something changed somewhere (?) and the rvmsudo command no longer executes without a password prompt.
$ rvmsudo passenger-install-apache2-module
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for systemuser:
THE QUESTION:
What is the minimal set of commands that should be in /etc/sudoers to install rvm, ruby, bundler/gem, and then passenger2 on apache?
Yes, I've read the "documentation" at https://rvm.io/integration/passenger/
Creative solutions welcomed! I realize one may say this looks like a pretty hacky system, and I'd agree with you. But at the moment it's hard for me to improve it without understanding what commands are being run by this passenger install script.
Removing "env" and "bash" from the front and adding "rvm" gets a little farther:
systemuser ALL = NOPASSWD: /usr/local/rvm/bin/rvmsudo, /usr/local/rvm/gems/ruby-1.8.7-p358/bin/passenger-install-apache2-module, /bin/cp, /bin/ln, /bin/mv, /bin/rm, /etc/init.d/httpd *
running this:
$ rvmsudo passenger-install-apache2-module
[sudo] password for systemuser:
Thanks for your attention!
/usr/bin/env is a router allowing to run any command, the same for /bin/bash, you would have to add which passenger-install-apache2-module instead of them.
The Alt+f2 in ubuntu shows up Run Application prompt. I can type any command there and open an application through it. How can i do the same programmatically, i mean that i have a command that should be passed to Alt+F2 programmatically. By program i mean a shell script
Have a look at xdotool.
You can use gmrun, which can be installed from the Ubuntu repos. Just sudo apt-get install gmrun. man gmrun for more info.
It's not exactly the same as the "run application dialog", but there's no clean way to bring that up from a script that I know of.