I have created a jar file in java, and I want to make the application automatically start during system boot up. I found I have to write a shell script for that. What should be that shell script look like? Is there anything else I have to do to make an application automatically start at boot up?
The preferred way to launch programs at OS X startup is to create a launchd daemon as explained here.
In mac os x you can also just run "open program.jar" (or any folder, '-a' for native applications) and it will open detached from the terminal with any default environment settings that it would use if you just double clicked it.
You can also add a program (or the script) to the user's login items through System Preferences > Accounts > 'username' > Login items. This is completely point and click and doesn't require a shell script
The shellscript would be something like this:
cd /directory/to/jar
java -jar Jar.jar
Or maybe you don't actually need to write Jar.jar, only Jar. I don't quite remember.
Related
I have a simple Django code which I want to keep running on a specific GCE instance. Sometimes the instance gets restarted due to some reasons, not in my control. I created a batch script which I tried to put in Startup folder in both users and common folder. It didn't work. I tried putting the script in using sysprep-specialize-script-url(using cloud storage), sysprep-specialize-script-cmd and sysprep-specialize-script-bat. It didn't work. Here's the content of the batch script -
cd C:\Users\kartik_domadiya\Desktop\happierMiscGoogleCloud
manage.py runserver 0.0.0.0:80
pause
I tried running C:\Program Files\Google\Compute Engine\metadata_scripts\run_startup_scripts.cmd manually and it worked (with any metadata key). So I can see that there's no problem with the script itself.
I even tried with putting the batch script in task scheduler which didn't work too.
So is there any way I can debug the problem and find out why isn't the batch script working? I am using Windows 2012 R2, if that matters.
PS: I know that's a development server and should not be used in production.
I moved the code to C:/code (basically out of any particular user's folder) and then provided all user its access (Right Click > Properties > Security), updated the batch file and put it into startup folder (Run > shell:startup).
It started working after that. I suppose the issue was due to access permission.
I have Jenkins running on Windows, and I have a build that works fine under CygWin bash from the CygWin terminal, so I now want to automate it. However, using this script:
#!C:\cygwin\bin\bash.exe
whoami
make
The system reports me as nt authority\system, not the ken that I get when using an interactive shell. Is there an easy way to persuade Jenkins or CygWin to run as me?
Most likely you are running jenkins with default installation. You have two options. First is mentioned in the comment. Change the "Service account" to be same as yours.
Second option is derived from best practices. Run the jenkins master on a system with backup etc. Configure slave node with your account credentials. Change the project configuration to build on the specific node.
(It is possible to run slave and master on same machine with different credentials - just in case you want to try out things)
The real problem I was having was not that the shell script was running as the wrong user, but that the shell script was not executing the default /etc/profile. So, the solution was simply:
#!C:\cygwin\bin\bash.exe -l
whoami
make
I was still nt authority\system, but now I had the correct environment set up and could run make successfully.
Note also that if I create a /home/system directory I can add .bash_profile, etc, to that directory to further customise the build environment.
I am trying to configure the "Run Settings" on Qt Creator 3.0.1.
I would like to set the value of many environment variables by sourcing a shell script 'myScript'.
However, Deployment's Custom Process Step apparently doesn't accept 'source' as a command.
If I execute the script instead of sourcing it, it sets the environment variables of the shell process in which it is executed, which is not the same where Qt Creator runs the executable.
Is it possible to use 'myScript' to configure the environment variables ? How should I call it?
Ofcorse, You can run qt via scrypt. This is very simply. My script is below. Ofcorse you need environment variables in concret file. In my case this file is environment-setup
#!/bin/bash
echo "ustawienie zmiennej /usr/local/angstrom/arm/environment-setup"
# set concret variables important is . /
. /usr/local/angstrom/arm/environment-setup
echo "Uruchomienie qtCreator"
# lunched qtcreator
$HOME/Qt/Tools/QtCreator/bin/qtcreator
You also can set this script as linked to main icon qt in your start menu. After this, all you need to run qt is only click in your shortcut in menu
I think currently there's no proper way to set QtCreator build environment variables using a script. For example in this guide by ICS three options are mentioned in the "Set Up the Environment" section:
1. You can always start Qt Creator in the same shell/console session where you previously ran the environment setup script (i.e. /opt/poky/2.2.1/environment-setup-armv5e-poky-linux-gnueabi). This option is the easiest, but means that you can’t simply launch Qt Creator from a desktop shortcut or similar method. It might also cause problems if you want to build for the desktop or another embedded platform within the same session.
2. You can add the environment variables to the kit’s settings. This option is a little more work to set up, but avoids the issues of the shell setup.
3. A third option is to add the environment variables to your project settings, but that means adding it to every project that uses the kit.
I'm using Jenkins to do continuous integration builds. I have quite a few jobs that have much of the same configuration code. I'm in the midst of pulling this all out into a common script file that I'd like to run pre and post build.
I've been unable to figure out how to set some environment variables within that script, so that both the Xcode build command, and the Jenkins build can see them.
Does anyone know if this is possible?
It is not possible to do exactly what you ask. A process cannot change the environment variables of another process. The pre and post and actual build steps run in different processes.
But you can create a script that sets the common environment variables and share that script between all your builds.
The would first call your shell to execute the commands in the script and then call xcodebuild:
# Note the dot in the beginning of the next line. It is not a typo.
. set_environment.sh
xcodebuild myawesomeapp.xcodeproj
The script could look like this:
export VARIABLE1=value1
export VARIABLE2=value2
How exactly your jobs will share the script depends on your environment and use case. You can
place the script in some well-known location on the Jenkins host or
place the script in the version controlled source tree if all your jobs share the same repository or
place the script in a repository of its own and make a Jenkins build which archives the script as a build artifact. All the other jobs would then use Copy Artifact plugin to get a copy of the script from the artifacts of script job.
From Apple's Technical Q&A QA1067 it appears that if you create the file /Users/YOU/.MacOSX/environment.plist and populate it with your desired environment variables that all processes (launched by the user with the environment.plist file in their home dir) will pick up these environment variables. You may need to restart your computer (or just log out and back in) before a newly launched process will pick up the variables.
This article also claims that Xcode will also pass these variables to a build phase script. I have not tested it yet but next time I restart my MacBook I will let you know if it worked.
From http://developer.apple.com/library/mac/#/legacy/mac/library/qa/qa1067/_index.html
Q: How do I set environment for all processes launched by a specific
user?
A: It is actually a fairly simple process to set environment variables
for processes launched by a specific user.
There is a special environment file which loginwindow searches for
each time a user logs in. The environment file is:
~/.MacOSX/environment.plist (be careful it's case sensitive). Where
'~' is the home directory of the user we are interested in. You will
have to create the .MacOSX directory yourself using terminal (by
typing mkdir .MacOSX). You will also have to create the environment
file yourself. The environment file is actually in XML/plist format
(make sure to add the .plist extension to the end of the filename or
this won't work).
I'm using the CakePHP Console to download files from we and processed in a database. I'm running the console from inside the "app" directory. But when I'm trying to run the console outside app and by just setting the "-app" parameter for my cron job, it doesn't work.
To be honest, I've had no success using -app parameter. It's like it's not working at all.
By the way, I'm using Windows & Pycron for my cron jobs.
Here's what happens when I'm trying to run the console from D:\
D:\>web\elink\cake\console\cake -app D:\web\elink\app
Welcome to CakePHP v1.2.2.8120 Console
---------------------------------------------------------------
Current Paths:
-app: app
-working: D: -app D:/web/elink/app
-root: D: -app D:/web/elink
-core: D:\web\elink
Changing Paths:
your working path should be the same as your application path
to change your path use the '-app' param.
Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp
Available Shells:
D:\web\elink\vendors\shells:
- none
CORE\console\libs:
acl
api
bake
console
i18n
schema
testsuite
To run a command, type 'cake shell_name [args]'
To get help on a specific command, type 'cake shell_name help'
My shells are located at D:\web\elink\app\vendors\shells.
I have managed to reproduce this issue using versions 1.2.2.8120 and 1.2.3.8166 on Windows. The -app parameter doesn't seem to work at all as expected.
The console will only list global shells in the /vendors/shells folder and not application-specific ones located in /app/vendors/shells or in plugins (/app/plugins/plugin_name/vendors/shells).
The -app parameter works as expected on OpenSUSE, listing all available application-specific shells (including those in plugins).
Unless we are doing something incorrectly, it is probably worth opening a ticket on Trac about this issue.
A workaround would be to add your Cake console directory to the Windows PATH environment variable.
Open 'System Properties' (Start key + Pause/Break key)
Open 'Advanced' tab
Click 'Environment Variables'
Select the PATH variable in the 'System variables' section
Press 'Edit'
Append ;E:\web\elink\cake\console\ to the 'Variable value'
Press 'Okay' on all dialogs
Close all open cmd prompts
You can then set up pycron to run E:\web\elink\cake without the -app parameter and all your application-specific shells should be available.
-For the people having the same problem but on linux systems, here there is an easy solution:
http://book.cakephp.org/complete/3/The-Manual#Running-Shells-as-cronjobs-846
-Another alternative solution for any system would be to create a simple script with two lines like this:
cd /path/to/app
/path/to/cake
-Both solutions worked for me in a Cent0S and in a MacOS based machines.