How can I activate a service after the desktop on raspberry pi (not immediately with boot)? - service

I want to launch an executable script python automatically. How can I activate a service after the desktop on raspberry pi?
I want to launch an executable script python automatically. How can I activate a service after the desktop on raspberry pi?
When I launched the service at the boot, it's failes (need some library python).
I'll try autostart, sudo nano /etc/rc.local and service.
Nothing works.
So, the answer i think is to launch the script automatically after boot.
Thanks a lot for your help

You can insert the script run in crontab, for it to run after a few seconds upon reboot. For example:
#reboot sleep 20 && /usr/bin/python my_script.py
Hope it helps!

Related

How to run foreground script after autologin to raspbian CLI

I have python script that runs in infinitve loop and gets input from keyboard. Works like a charm when I run it manually from CLI. I want to automate this process -> that it will start up automaticly after Rpi boot and login "pi" user.
I used raspi-config to setup autologin to CLI as "pi" user and then I want to run python script in foreground.
Right now Rpi boots -> login as pi user to CLI -> and waits for action. And here I want to have my script start
I tried to run it as a service or in crontab but it always runs in the background. I also tried running it through /etc/rc.local but it starts running before the login prompts which i don't want. I found some tutorials but all of them are for GUI and background processes. I thought that it will be quite easy but after several hours I decided to ask here.
My OS is
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.8 (stretch)
Release: 9.8
Codename: stretch
I run script -> python keyboardinput.py
I would invoke your script from /home/pi/.bashrc
Your script would run every time you login and a shell starts.

How to run Google Assistant library (on AIY kit), upon startup of Raspberry Pi?

We set up a voice kit using Raspberry Pi (using "the MagPi essentials AIY Projects" manual). We are able to enable Google Assistant using the command "src/assistant_library_demo.py" in the dev terminal, after Raspberry Pi starts up. We would like to embed the voice kit in a stuffed animal with a portable power supply (i.e., used to charge cell phone on the go). But when the portable power supply is charged, the Raspberry Pi resets. That requires us to go back into the Raspberry Pi, open the dev terminal, and run the Google Assistant file.
My question: Is it possible to run a startup script that automatically runs Google Assistant upon Raspberry Pi starting up? How to do this?
I ended up creating a crontab job after a 10 second wait. Starting right at boot didn't give it enough time for the internet to connect fully.
In terminal type:
crontab -e
Choose an option if it asks how you want to open/edit the file. Then at the bottom put:
#reboot sleep 10 && /home/pi/pathtofile > /home/pi/cronlog 2>&1
Save the file and reboot or pull the cable out and plug it back in. The cronlog helped me troubleshoot this whole process and get feedback on why it didn't work.
Take a look at this page. It tells you how to set up a service which will run automatically.
If the link has gone bad, here is a short explanation of it:
Create a file called my_assistant.service in the src directory, and put in the following code
[Unit]
Description=My awesome assistant app
[Service]
Environment=XDG_RUNTIME_DIR=/run/user/1000
ExecStart=/bin/bash -c 'python3 -u src/my_assistant.py'
WorkingDirectory=/home/pi/AIY-projects-python
Restart=always
User=pi
[Install]
WantedBy=multi-user.target
Where the file says src/my_assistant.py, replace my_assistant with your program's filename. Now go to the folder that file the .sevice file is in, and run the command sudo mv my_assistant.service /lib/systemd/system/. This code moves the file to the services folder. Now you can run the following commands to change the service:
Enable the service- sudo systemctl enable my_assistant.service
Disable it- sudo systemctl disable my_assistant.service
Start it (just runs it once, enabling makes it run on startup)- sudo service my_assistant start
Stop it- sudo service my_assistant stop
See the logs, when the program was started and if an error occurred- sudo service my_assistant status

Run the Mechanize::Firefox script in VNC server using Net::SSH::perl?

I have done the script with Mechanize::Firefox. I need to run the script in VNC server. I'm working on ubuntu. I have installed krdc software to run the scripts.
Before running the script I'm starting the vnc server by using the following command vncserver.
To connect the server via ssh I have using one password for example sshpassword. When open the krdc software there I'm using the vncpassword.
My problem is, I have trying to run the Mechanize::Firefox script using Net::SSH::perl script it is running but the firefox is not starting. So I cannot crawl the content.
How can I fix this issue.? I don't know from where need to start.

Rasperry Pi won't boot any more after installing upstart

I'm running Jessie 8.0 on a raspberry pi 2 B and it doesn't boot completely anymore after installing upstart
sudo apt-get install upstart
FYI: Apache, PHP, MySQL, KODI were installed upfront
What can I do? Could I try to uninstall upstart?
Thanks in advance
Just ran into this headache this morning on my Raspberry Pi 3. You can use Recovery / Single User Mode to fix this.
Plug in a keyboard and HDMI connection to the Pi.
Repeatedly press shift while booting to get to the recovery console.
Press 'e' to edit config, use tab and arrow keys to navigate to cmdline.txt
Add "init=/bin/bash" to the end as the last argument
Press "OK", and then hit the escape key to continue booting
After the boot sequence looks like it has stopped (mine looked like it had frozen mid-boot, don't worry), try pressing enter to get a CLI prompt
Type /etc/init.d/mountall.sh
Type mount -n -o remount,rw / (This mounts the root of SD Card)
At this point most commands should be functional, now you can use Escounda's answer and type: sudo apt-get purge --auto-remove upstart
After a reboot everything should be back to normal with no OS reinstall required! Don't forget to remove "init=/bin/bash" from your cmdline.txt when you're finished.
I'm probably late to the party, but I had the same issue yesterday (Pi won't boot, no way to use apt to remove upstart)
So I installed Ubuntu in a VM and chrooted into my SD Card (See https://raspberrypi.stackexchange.com/a/24011/13597 for more informations about this)
Then removed upstart just like in Escounda's second post
I managed to boot again by removing upstart:
sudo apt-get purge --auto-remove upstart
This command will also automatically reinstall systemd-sysv

Stop or restart beanstalkd manually on command line

Beanstalkd is running on my Ubuntu VPS. I don't know how to stop or shut down the beandstalkd server. I want to stop the server manually on the command line.
I've found monitoring tools and a configurations script, but no commands for the commandline.
Beanstalkd is normally run with the standard OS-level tools (so, on Ubuntu, upstart). There are a number of example configuration scripts for LaunchD, systemD and Upstart in the Beanstalkd repo.
For an Ubuntu system, you would copy the Upstart .conf file, making any required tweaks to the command line you need (to enable the binary log, for example) and drop it into the /etc/init/ directory. Then the usual start, restart, stop & status commands would be able to control the Beanstalkd daemon, and it could be auto-started on bootup.
If it's not already under upstart control, then you can simply kill the process, like anything else, by finding the process ID (pgrep -lf beanstalkd).