You are not logged in.
Hi all,
I am trying to use systemctl --user to control a bash script I am using to record a video source.
I have created a cam.service in ~/.config/systemd/user/
[Unit]
Description=Start Cam
[Service]
Type=forking
ExecStart=/bin/sh /home/sweetth/cam2.sh start
KillMode=process
Environment=DISPLAY=:1
[Install]
WantedBy=multi-user.target
The process start but failed after about 2 minutes - the script however carry on and the video source is still recording
see terminal output & systemctl --user status -l cam.service
$ systemctl --user start cam.service
Job for cam.service failed. See "systemctl status cam.service" and "journalctl -xe" for details.
$ systemctl --user status -l cam.service
● cam.service - Start Cam
Loaded: loaded (/home/sweetth/.config/systemd/user/cam.service; enabled; vendor preset: enabled)
Active: failed (Result: timeout) since Sun 2015-05-10 20:31:56 BST; 9min ago
Process: 4322 ExecStart=/bin/sh /home/sweetth/cam2.sh start (code=killed, signal=TERM)
Main PID: 3735 (code=exited, status=217/USER)
CGroup: /user.slice/user-1000.slice/user@1000.service/cam.service
May 10 20:30:46 linuxbox sh[4322]: [2.0K blob data]
May 10 20:30:58 linuxbox sh[4322]: [2.0K blob data]
May 10 20:31:10 linuxbox sh[4322]: [2.0K blob data]
May 10 20:31:22 linuxbox sh[4322]: [2.0K blob data]
May 10 20:31:34 linuxbox sh[4322]: [2.0K blob data]
May 10 20:31:46 linuxbox sh[4322]: [1.9K blob data]
May 10 20:31:56 linuxbox systemd[648]: cam.service start operation timed out. Terminating.
May 10 20:31:56 linuxbox systemd[648]: Failed to start Start Cam.
May 10 20:31:56 linuxbox systemd[648]: Unit cam.service entered failed state.
May 10 20:31:56 linuxbox systemd[648]: cam.service failed.
I wanted systemd to control the process so that I can start it and stop it with systemd but also that it will stop properly while login out or shutting down the computer.
See the script for information.
sleep 3 &&
cd /media/z/.cam/ &&
while true; do
ffmpeg -f alsa -i pulse -acodec ac3 -f video4linux2 -i /dev/video0 -vcodec libx264 -s 640x480 -preset medium -crf 26 -threads 0 -t 600 cam_`date +%F_%H.%M.%S`.avi
if [ $? -ne 0 ]; then # $? contains the exit status of last command
break # exit loop when ffmpeg failed
fi
done
zenity --warning --timeout 5 --title="Error" \
--text="The session has started with an error, most likely to be the webcam!\n
The session with now log out, please unplug the webcam, plug it back and wait ten seconds before logging back."
if [[ $? -eq 0 ]] ; then
zenity --info --text=zenity --info --timeout 5 --text="If the error continue restart the computer."
#gsettings set org.gnome.desktop.lockdown disable-log-out false
pkill desktop.sh & pkill ffmpeg &
# and finally . . . . we log back
gnome-session-quit --force
else
#gsettings set org.gnome.desktop.lockdown disable-log-out false
pkill desktop.sh & pkill ffmpeg &
# and finally . . . . we log back
gnome-session-quit --force
fi
done
exit
Thanks for your time and I am looking forward for your advice or direction.
Offline
That script looks pretty messy, so I didn't bother reading the whole thing.
But it looks like you're lying to systemd -- claiming the script forks while it doesn't.
Offline
Thank you for your prompt reply.
That indeed worked, however when I stop the service the script process remain active. I then have to kill it manually.
Any ideas or suggestion.
Last edited by sweetthdevil (2015-05-11 19:48:20)
Offline
Quick update.
I have now amended the service (see below) - the service start and stop all process. However I have three issues remaining.
[Unit]
Description=Start Cam
[Service]
ExecStart=/bin/sh /home/sweetth/cam2.sh start
ExecStop=/usr/bin/pkill -TERM ffmpeg
KillMode=process
Environment=DISPLAY=:1
[Install]
WantedBy=multi-user.target
1- It doesn't start automatically after login
$ systemctl --user status -l cam.service
● cam.service - Start Cam
Loaded: loaded (/home/sweetth/.config/systemd/user/cam.service; enabled; vendor preset: enabled)
Active: inactive (dead)
2 - The service stop all process when login off, but doesn't stop the process when the computer is rebooting or shut down.
3 - The script make sure that the recording of the video stream works, otherwise send a message to the user using zenity - that works now, but then it is suppose to automatically log the user off and that doesn't work.
Any ideas or suggestion.
Offline